This is an automated email from the ASF dual-hosted git repository.

huajianlan pushed a commit to branch opt_insert_into_values
in repository https://gitbox.apache.org/repos/asf/doris.git

commit e1565fbb698afccbdc7a98e57446542b15e585fd
Author: 924060929 <lanhuaj...@selectdb.com>
AuthorDate: Fri Dec 6 14:30:09 2024 +0800

    fix
---
 .../doris/nereids/parser/LogicalPlanBuilder.java   | 20 +++++++----
 .../commands/insert/InsertIntoTableCommand.java    | 39 +++++++++++++++++++---
 .../trees/plans/logical/LogicalInlineTable.java    |  9 ++++-
 3 files changed, 56 insertions(+), 12 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
index 15aeca952a2..30594e44d09 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
@@ -1838,10 +1838,12 @@ public class LogicalPlanBuilder extends 
DorisParserBaseVisitor<Object> {
 
     @Override
     public LogicalPlan visitInlineTable(InlineTableContext ctx) {
-        List<List<NamedExpression>> values = ctx.rowConstructor().stream()
-                .map(this::visitRowConstructor)
-                .collect(ImmutableList.toImmutableList());
-        return new LogicalInlineTable(values);
+        List<RowConstructorContext> rowConstructorContexts = 
ctx.rowConstructor();
+        ImmutableList.Builder<List<NamedExpression>> rows = 
ImmutableList.builderWithExpectedSize(rowConstructorContexts.size());
+        for (RowConstructorContext rowConstructorContext : 
rowConstructorContexts) {
+            rows.add(visitRowConstructor(rowConstructorContext));
+        }
+        return new LogicalInlineTable(rows.build());
     }
 
     /**
@@ -2972,9 +2974,13 @@ public class LogicalPlanBuilder extends 
DorisParserBaseVisitor<Object> {
 
     @Override
     public List<NamedExpression> visitRowConstructor(RowConstructorContext 
ctx) {
-        return ctx.rowConstructorItem().stream()
-                .map(this::visitRowConstructorItem)
-                .collect(ImmutableList.toImmutableList());
+        List<RowConstructorItemContext> rowConstructorItemContexts = 
ctx.rowConstructorItem();
+        ImmutableList.Builder<NamedExpression> columns
+                = 
ImmutableList.builderWithExpectedSize(rowConstructorItemContexts.size());
+        for (RowConstructorItemContext rowConstructorItemContext : 
rowConstructorItemContexts) {
+            columns.add(visitRowConstructorItem(rowConstructorItemContext));
+        }
+        return columns.build();
     }
 
     @Override
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertIntoTableCommand.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertIntoTableCommand.java
index 43e569d437d..525c380e3f1 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertIntoTableCommand.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertIntoTableCommand.java
@@ -344,6 +344,10 @@ public class InsertIntoTableCommand extends Command 
implements ForwardWithSync,
     private BuildInsertExecutorResult planInsertExecutor(
             ConnectContext ctx, StmtExecutor stmtExecutor,
             LogicalPlanAdapter logicalPlanAdapter, TableIf targetTableIf) 
throws Throwable {
+        LogicalPlan logicalPlan = logicalPlanAdapter.getLogicalPlan();
+
+        boolean isInsertIntoValues
+                = logicalPlan instanceof UnboundTableSink && 
logicalPlan.child(0) instanceof LogicalInlineTable;
         // the key logical when use new coordinator:
         // 1. use NereidsPlanner to generate PhysicalPlan
         // 2. use PhysicalPlan to select InsertExecutorFactory, some 
InsertExecutors want to control
@@ -355,7 +359,8 @@ public class InsertIntoTableCommand extends Command 
implements ForwardWithSync,
         // 4. ExecutorFactory use the DistributePlan to generate the 
NereidsSqlCoordinator and InsertExecutor
 
         AtomicReference<ExecutorFactory> executorFactoryRef = new 
AtomicReference<>();
-        InsertByInlineTablePlanner planner = new 
InsertByInlineTablePlanner(ctx.getStatementContext()) {
+        InsertByInlineTablePlanner planner = new InsertByInlineTablePlanner(
+                ctx.getStatementContext(), isInsertIntoValues) {
             @Override
             protected void doDistribute(boolean 
canUseNereidsDistributePlanner) {
                 // when enter this method, the step 1 already executed
@@ -470,14 +475,22 @@ public class InsertIntoTableCommand extends Command 
implements ForwardWithSync,
     private static class InsertByInlineTablePlanner extends NereidsPlanner {
         private static final Rule toPhysicalOlapTableSink = new 
LogicalOlapTableSinkToPhysicalOlapTableSink()
                 .build();
-        private AtomicReference<Group> rootGroupRef = new AtomicReference<>();
+        private final AtomicReference<Group> rootGroupRef = new 
AtomicReference<>();
+
+        private final boolean isInsertIntoValues;
 
-        public InsertByInlineTablePlanner(StatementContext statementContext) {
+        public InsertByInlineTablePlanner(StatementContext statementContext, 
boolean isInsertIntoValues) {
             super(statementContext);
+            this.isInsertIntoValues = isInsertIntoValues;
         }
 
         @Override
         protected void analyze(boolean showPlanProcess) {
+            if (!isInsertIntoValues) {
+                super.analyze(showPlanProcess);
+                return;
+            }
+
             DefaultPlanRewriter<Void> analyzer = new 
DefaultPlanRewriter<Void>() {
                 @Override
                 public Plan visitUnboundTableSink(
@@ -516,6 +529,11 @@ public class InsertIntoTableCommand extends Command 
implements ForwardWithSync,
 
         @Override
         protected void rewrite(boolean showPlanProcess) {
+            if (!isInsertIntoValues) {
+                super.rewrite(showPlanProcess);
+                return;
+            }
+
             DefaultPlanRewriter<Void> rewriter = new 
DefaultPlanRewriter<Void>() {
                 @Override
                 public Plan visitLogicalProject(LogicalProject<? extends Plan> 
project, Void context) {
@@ -536,8 +554,12 @@ public class InsertIntoTableCommand extends Command 
implements ForwardWithSync,
 
         @Override
         protected void optimize() {
-            DefaultPlanRewriter<Void> optimizer = new 
DefaultPlanRewriter<Void>() {
+            if (!isInsertIntoValues) {
+                super.optimize();
+                return;
+            }
 
+            DefaultPlanRewriter<Void> optimizer = new 
DefaultPlanRewriter<Void>() {
                 @Override
                 public Plan visitLogicalUnion(LogicalUnion logicalUnion, Void 
context) {
                     logicalUnion = (LogicalUnion) 
super.visitLogicalUnion(logicalUnion, context);
@@ -586,17 +608,26 @@ public class InsertIntoTableCommand extends Command 
implements ForwardWithSync,
 
         @Override
         public Group getRoot() {
+            if (!isInsertIntoValues) {
+                return super.getRoot();
+            }
             return rootGroupRef.get();
         }
 
         @Override
         protected PhysicalPlan chooseNthPlan(
                 Group rootGroup, PhysicalProperties physicalProperties, int 
nthPlan) {
+            if (!isInsertIntoValues) {
+                return super.chooseNthPlan(rootGroup, physicalProperties, 
nthPlan);
+            }
             return super.physicalPlan;
         }
 
         @Override
         protected PhysicalPlan postProcess(PhysicalPlan physicalPlan) {
+            if (!isInsertIntoValues) {
+                return super.postProcess(physicalPlan);
+            }
             return physicalPlan;
         }
     }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalInlineTable.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalInlineTable.java
index b26032794fd..b9980c03ec1 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalInlineTable.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalInlineTable.java
@@ -79,7 +79,14 @@ public class LogicalInlineTable extends LogicalLeaf 
implements BlockFuncDepsProp
 
     @Override
     public List<? extends Expression> getExpressions() {
-        return 
constantExprsList.stream().flatMap(List::stream).collect(ImmutableList.toImmutableList());
+        ImmutableList.Builder<Expression> expressions = 
ImmutableList.builderWithExpectedSize(
+                constantExprsList.size() * constantExprsList.get(0).size());
+
+        for (List<NamedExpression> namedExpressions : constantExprsList) {
+            expressions.addAll(namedExpressions);
+        }
+
+        return expressions.build();
     }
 
     @Override


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to