Skip to content

Commit e0df398

Browse files
authored
[fix](nereids) fix insert overwrite statement plan twice (apache#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`
1 parent acd49e4 commit e0df398

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertIntoTableCommand.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,26 @@ public class InsertIntoTableCommand extends Command implements NeedAuditEncrypti
107107
// default is empty. only for OlapInsertExecutor#finalizeSink will construct one for check allow auto partition
108108
private final Optional<InsertCommandContext> insertCtx;
109109
private final Optional<LogicalPlan> cte;
110+
private final boolean needNormalizePlan;
111+
112+
public InsertIntoTableCommand(LogicalPlan logicalQuery, Optional<String> labelName,
113+
Optional<InsertCommandContext> insertCtx, Optional<LogicalPlan> cte) {
114+
this(logicalQuery, labelName, insertCtx, cte, true);
115+
}
110116

111117
/**
112118
* constructor
113119
*/
114120
public InsertIntoTableCommand(LogicalPlan logicalQuery, Optional<String> labelName,
115-
Optional<InsertCommandContext> insertCtx, Optional<LogicalPlan> cte) {
121+
Optional<InsertCommandContext> insertCtx, Optional<LogicalPlan> cte,
122+
boolean needNormalizePlan) {
116123
super(PlanType.INSERT_INTO_TABLE_COMMAND);
117124
this.originLogicalQuery = Objects.requireNonNull(logicalQuery, "logicalQuery should not be null");
118125
this.labelName = Objects.requireNonNull(labelName, "labelName should not be null");
119126
this.logicalQuery = Optional.empty();
120127
this.insertCtx = insertCtx;
121128
this.cte = cte;
129+
this.needNormalizePlan = needNormalizePlan;
122130
}
123131

124132
/**
@@ -132,6 +140,7 @@ public InsertIntoTableCommand(InsertIntoTableCommand command, PlanType planType)
132140
this.insertCtx = command.insertCtx;
133141
this.cte = command.cte;
134142
this.jobId = command.jobId;
143+
this. needNormalizePlan = true;
135144
}
136145

137146
public LogicalPlan getLogicalQuery() {
@@ -277,8 +286,12 @@ private BuildInsertExecutorResult initPlanOnce(ConnectContext ctx,
277286
);
278287
if (!(this instanceof InsertIntoDictionaryCommand)) {
279288
// process inline table (default values, empty values)
280-
this.logicalQuery = Optional.of((LogicalPlan) InsertUtils.normalizePlan(originLogicalQuery,
281-
targetTableIf, analyzeContext, insertCtx));
289+
if (needNormalizePlan) {
290+
this.logicalQuery = Optional.of((LogicalPlan) InsertUtils.normalizePlan(originLogicalQuery,
291+
targetTableIf, analyzeContext, insertCtx));
292+
} else {
293+
this.logicalQuery = Optional.of(originLogicalQuery);
294+
}
282295
}
283296
if (cte.isPresent()) {
284297
this.logicalQuery = Optional.of((LogicalPlan) cte.get().withChildren(logicalQuery.get()));

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertOverwriteTableCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ private boolean allowInsertOverwrite(TableIf targetTable) {
290290
private void runInsertCommand(LogicalPlan logicalQuery, InsertCommandContext insertCtx,
291291
ConnectContext ctx, StmtExecutor executor) throws Exception {
292292
InsertIntoTableCommand insertCommand = new InsertIntoTableCommand(logicalQuery, labelName,
293-
Optional.of(insertCtx), Optional.empty());
293+
Optional.of(insertCtx), Optional.empty(), false);
294294
insertCommand.run(ctx, executor);
295295
if (ctx.getState().getStateType() == MysqlStateType.ERR) {
296296
String errMsg = Strings.emptyToNull(ctx.getState().getErrorMessage());

0 commit comments

Comments
 (0)