Skip to content

Commit 2b871de

Browse files
seawindeyujun777
authored andcommitted
[fix](fe) Fix fast insert into values after IVM stream guard (apache#24)
### What problem does this PR solve? Issue Number: N/A Related PR: apache#21 Problem Summary: Fast INSERT INTO VALUES planning does not retain an analyzed plan. The IVM internal stream guard added by the related PR dereferenced that nullable plan and caused ordinary VALUES inserts to fail with a null pointer. Skip stream traversal when the analyzed plan is absent; this is safe because the fast VALUES path only reads inline constants and cannot contain a table stream scan. Add focused unit coverage for the fast planning path while retaining the existing internal stream rejection coverage. ### Release note Fixed an issue where INSERT INTO VALUES could fail with a null pointer after IVM internal stream validation. ### Check List (For Author) - Test: Unit Test - ./run-fe-ut.sh --run org.apache.doris.nereids.trees.plans.commands.insert.InsertIntoTableCommandTableStreamTest - mvn clean install -DskipTests -Dmaven.build.cache.enabled=false - Behavior changed: No - Does this need documentation: No
1 parent 4bb2da9 commit 2b871de

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ public AbstractInsertExecutor initPlan(ConnectContext ctx, StmtExecutor stmtExec
286286
parsedPlan = Optional.ofNullable(buildResult.planner.getParsedPlan());
287287
Plan analyzedPlan = buildResult.planner.getAnalyzedPlan();
288288
lineagePlan = Optional.ofNullable(analyzedPlan);
289-
if (!ctx.getStatementContext().getIvmRewriteContext().isPresent()) {
289+
// Fast INSERT INTO VALUES does not retain an analyzed plan and cannot contain table stream scans.
290+
if (analyzedPlan != null && !ctx.getStatementContext().getIvmRewriteContext().isPresent()) {
290291
for (LogicalOlapTableStreamScan streamScan : analyzedPlan
291292
.<LogicalOlapTableStreamScan>collectToList(LogicalOlapTableStreamScan.class::isInstance)) {
292293
OlapTableStreamWrapper wrapper = streamScan.getTable();

‎fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/insert/InsertIntoTableCommandTableStreamTest.java‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,28 @@ public void testUserInsertRejectsIvmInternalTableStream() throws Exception {
166166
"unexpected message: " + ex.getMessage());
167167
}
168168

169+
@Test
170+
public void testFastInsertIntoValuesAllowsMissingAnalyzedPlan() throws Exception {
171+
connectContext.getStatementContext().setIvmRewriteContext(Optional.empty());
172+
boolean originalFastAnalyze = connectContext.getSessionVariable().isEnableFastAnalyzeInsertIntoValues();
173+
connectContext.getSessionVariable().setEnableFastAnalyzeInsertIntoValues(true);
174+
try {
175+
String sql = "insert into test_stream.tbl_target values (1, 2)";
176+
LogicalPlan logicalPlan = parser.parseSingle(sql);
177+
Assertions.assertTrue(logicalPlan instanceof InsertIntoTableCommand);
178+
179+
connectContext.setStartTime();
180+
UUID uuid = UUID.randomUUID();
181+
connectContext.setQueryId(new TUniqueId(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits()));
182+
183+
StmtExecutor executor = new StmtExecutor(connectContext, sql);
184+
InsertIntoTableCommand command = (InsertIntoTableCommand) logicalPlan;
185+
Assertions.assertNotNull(command.initPlan(connectContext, executor, false));
186+
} finally {
187+
connectContext.getSessionVariable().setEnableFastAnalyzeInsertIntoValues(originalFastAnalyze);
188+
}
189+
}
190+
169191
@Test
170192
public void testUnprotectedUpdateAdvancesPartitionOffsetAndConsumptionTime() throws Exception {
171193
// (B1) When no historicalPartitionTSO is present, unprotectedUpdateStreamUpdate should

0 commit comments

Comments
 (0)