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

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


The following commit(s) were added to refs/heads/master by this push:
     new e0df398a2c6 [fix](nereids) fix insert overwrite statement plan twice 
(#53398)
e0df398a2c6 is described below

commit e0df398a2c61ba44ec72f876fa2f6b11f866386c
Author: 924060929 <[email protected]>
AuthorDate: Thu Jul 17 19:08:38 2025 +0800

    [fix](nereids) fix insert overwrite statement plan twice (#53398)
    
    the `InsertOverwriteTableCommand` will normalize plan twice, maybe cause
    some strange problems
    
    first:
    ```java
    this.logicalQuery = Optional.of((LogicalPlan) InsertUtils.normalizePlan(
        originLogicalQuery, targetTableIf, analyzeContext, Optional.empty()));
    ```
    
    second:
    ```java
    InsertIntoTableCommand insertCommand = new 
InsertIntoTableCommand(logicalQuery, labelName,
        Optional.of(insertCtx), Optional.empty(), false);
    insertCommand.run(ctx, executor);
    ```
    
    we should skip normalize plan in the `InsertIntoTableCommand`
---
 .../plans/commands/insert/InsertIntoTableCommand.java | 19 ++++++++++++++++---
 .../commands/insert/InsertOverwriteTableCommand.java  |  2 +-
 2 files changed, 17 insertions(+), 4 deletions(-)

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 c501fe5b679..51499035af2 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
@@ -107,18 +107,26 @@ public class InsertIntoTableCommand extends Command 
implements NeedAuditEncrypti
     // default is empty. only for OlapInsertExecutor#finalizeSink will 
construct one for check allow auto partition
     private final Optional<InsertCommandContext> insertCtx;
     private final Optional<LogicalPlan> cte;
+    private final boolean needNormalizePlan;
+
+    public InsertIntoTableCommand(LogicalPlan logicalQuery, Optional<String> 
labelName,
+            Optional<InsertCommandContext> insertCtx, Optional<LogicalPlan> 
cte) {
+        this(logicalQuery, labelName, insertCtx, cte, true);
+    }
 
     /**
      * constructor
      */
     public InsertIntoTableCommand(LogicalPlan logicalQuery, Optional<String> 
labelName,
-                                  Optional<InsertCommandContext> insertCtx, 
Optional<LogicalPlan> cte) {
+                                  Optional<InsertCommandContext> insertCtx, 
Optional<LogicalPlan> cte,
+                                  boolean needNormalizePlan) {
         super(PlanType.INSERT_INTO_TABLE_COMMAND);
         this.originLogicalQuery = Objects.requireNonNull(logicalQuery, 
"logicalQuery should not be null");
         this.labelName = Objects.requireNonNull(labelName, "labelName should 
not be null");
         this.logicalQuery = Optional.empty();
         this.insertCtx = insertCtx;
         this.cte = cte;
+        this.needNormalizePlan = needNormalizePlan;
     }
 
     /**
@@ -132,6 +140,7 @@ public class InsertIntoTableCommand extends Command 
implements NeedAuditEncrypti
         this.insertCtx = command.insertCtx;
         this.cte = command.cte;
         this.jobId = command.jobId;
+        this. needNormalizePlan = true;
     }
 
     public LogicalPlan getLogicalQuery() {
@@ -277,8 +286,12 @@ public class InsertIntoTableCommand extends Command 
implements NeedAuditEncrypti
             );
             if (!(this instanceof InsertIntoDictionaryCommand)) {
                 // process inline table (default values, empty values)
-                this.logicalQuery = Optional.of((LogicalPlan) 
InsertUtils.normalizePlan(originLogicalQuery,
-                        targetTableIf, analyzeContext, insertCtx));
+                if (needNormalizePlan) {
+                    this.logicalQuery = Optional.of((LogicalPlan) 
InsertUtils.normalizePlan(originLogicalQuery,
+                            targetTableIf, analyzeContext, insertCtx));
+                } else {
+                    this.logicalQuery = Optional.of(originLogicalQuery);
+                }
             }
             if (cte.isPresent()) {
                 this.logicalQuery = Optional.of((LogicalPlan) 
cte.get().withChildren(logicalQuery.get()));
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertOverwriteTableCommand.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertOverwriteTableCommand.java
index 7e7d8ec834a..e60b7a2b574 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertOverwriteTableCommand.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertOverwriteTableCommand.java
@@ -290,7 +290,7 @@ public class InsertOverwriteTableCommand extends Command 
implements NeedAuditEnc
     private void runInsertCommand(LogicalPlan logicalQuery, 
InsertCommandContext insertCtx,
             ConnectContext ctx, StmtExecutor executor) throws Exception {
         InsertIntoTableCommand insertCommand = new 
InsertIntoTableCommand(logicalQuery, labelName,
-                Optional.of(insertCtx), Optional.empty());
+                Optional.of(insertCtx), Optional.empty(), false);
         insertCommand.run(ctx, executor);
         if (ctx.getState().getStateType() == MysqlStateType.ERR) {
             String errMsg = 
Strings.emptyToNull(ctx.getState().getErrorMessage());


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to