Skip to content

Commit 8708350

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 42a4cb9 commit 8708350

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
@@ -290,7 +290,8 @@ public AbstractInsertExecutor initPlan(ConnectContext ctx, StmtExecutor stmtExec
290290
parsedPlan = Optional.ofNullable(buildResult.planner.getParsedPlan());
291291
Plan analyzedPlan = buildResult.planner.getAnalyzedPlan();
292292
lineagePlan = Optional.ofNullable(analyzedPlan);
293-
if (!ctx.getStatementContext().getIvmRewriteContext().isPresent()) {
293+
// Fast INSERT INTO VALUES does not retain an analyzed plan and cannot contain table stream scans.
294+
if (analyzedPlan != null && !ctx.getStatementContext().getIvmRewriteContext().isPresent()) {
294295
for (LogicalOlapTableStreamScan streamScan : analyzedPlan
295296
.<LogicalOlapTableStreamScan>collectToList(LogicalOlapTableStreamScan.class::isInstance)) {
296297
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
@@ -252,6 +252,28 @@ public void testUserInsertRejectsIvmInternalTableStream() throws Exception {
252252
"unexpected message: " + ex.getMessage());
253253
}
254254

255+
@Test
256+
public void testFastInsertIntoValuesAllowsMissingAnalyzedPlan() throws Exception {
257+
connectContext.getStatementContext().setIvmRewriteContext(Optional.empty());
258+
boolean originalFastAnalyze = connectContext.getSessionVariable().isEnableFastAnalyzeInsertIntoValues();
259+
connectContext.getSessionVariable().setEnableFastAnalyzeInsertIntoValues(true);
260+
try {
261+
String sql = "insert into test_stream.tbl_target values (1, 2)";
262+
LogicalPlan logicalPlan = parser.parseSingle(sql);
263+
Assertions.assertTrue(logicalPlan instanceof InsertIntoTableCommand);
264+
265+
connectContext.setStartTime();
266+
UUID uuid = UUID.randomUUID();
267+
connectContext.setQueryId(new TUniqueId(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits()));
268+
269+
StmtExecutor executor = new StmtExecutor(connectContext, sql);
270+
InsertIntoTableCommand command = (InsertIntoTableCommand) logicalPlan;
271+
Assertions.assertNotNull(command.initPlan(connectContext, executor, false));
272+
} finally {
273+
connectContext.getSessionVariable().setEnableFastAnalyzeInsertIntoValues(originalFastAnalyze);
274+
}
275+
}
276+
255277
@Test
256278
public void testUnprotectedUpdateAdvancesPartitionOffsetAndConsumptionTime() throws Exception {
257279
// (B1) When no historicalPartitionTSO is present, unprotectedUpdateStreamUpdate should

0 commit comments

Comments
 (0)