operator/statement/
dml.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use common_query::Output;
16use common_telemetry::tracing;
17use query::parser::QueryStatement;
18use session::context::QueryContextRef;
19use sql::statements::insert::Insert;
20use sql::statements::statement::Statement;
21
22use crate::error::Result;
23use crate::statement::StatementExecutor;
24
25impl StatementExecutor {
26    #[tracing::instrument(skip_all)]
27    pub async fn insert(&self, insert: Box<Insert>, query_ctx: QueryContextRef) -> Result<Output> {
28        if insert.can_extract_values() {
29            // Fast path: plain insert ("insert with literal values") is executed directly
30            self.inserter
31                .handle_statement_insert(insert.as_ref(), &query_ctx)
32                .await
33        } else {
34            // Slow path: insert with subquery. Execute using query engine.
35            let statement = QueryStatement::Sql(Statement::Insert(insert));
36            self.plan_exec(statement, query_ctx).await
37        }
38    }
39}