Skip to content

Commit 428d474

Browse files
yujun7770AyanamiRei
authored andcommitted
[fix](stream) Fix stream scan partition prune state propagation (apache#65657)
### What problem does this PR solve? Related Issue: close apache#65654 `LogicalOlapTableStreamScan.withSelectedPartitionIds(List<Long>, boolean)` diverged from `LogicalOlapScan` and changed the meaning of the second parameter. In `LogicalOlapScan`, the second parameter represents `hasPartitionPredicate`, while the rebuilt scan is always marked as partition-pruned. The stream scan override treated that second parameter as `isPartitionPruned`, which let partition pruning rebuild a stream scan that still looked unpruned and could be matched again by the same rewrite rule. This PR keeps the stream-scan override consistent with `LogicalOlapScan`: the second parameter remains `hasPartitionPredicate`, and the rebuilt `LogicalOlapTableStreamScan` is marked as already partition-pruned.
1 parent ab324bb commit 428d474

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapTableStreamScan.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,11 @@ public LogicalOlapTableStreamScan withSelectedPartitionIds(List<Long> selectedPa
276276
*/
277277
@Override
278278
public LogicalOlapTableStreamScan withSelectedPartitionIds(List<Long> selectedPartitionIds,
279-
boolean isPartitionPruned) {
279+
boolean hasPartitionPredicate) {
280280
return AbstractPlan.copyWithSameId(this, () ->
281281
new LogicalOlapTableStreamScan(relationId, (Table) table, qualifier,
282282
groupExpression, Optional.of(getLogicalProperties()),
283-
selectedPartitionIds, isPartitionPruned, hasPartitionPredicate, selectedTabletIds,
283+
selectedPartitionIds, true, hasPartitionPredicate, selectedTabletIds,
284284
selectedIndexId, indexSelected, preAggStatus, manuallySpecifiedPartitions,
285285
hints, cacheSlotWithSlotName, cachedOutput, tableSample, directMvScan,
286286
colToSubPathsMap, manuallySpecifiedTabletIds, operativeSlots, virtualColumns,

‎fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/ExplainTableStreamPlanTest.java‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,24 @@ public void testAppendOnlyAliasedStreamResetCanBePlanned() throws Exception {
500500
assertStreamScanCanBePlanned(ctx, "explain select s.* from test_stream.s_dup@reset() as s");
501501
}
502502

503+
@Test
504+
public void testStreamScanWithSelectedPartitionIdsMarksPartitionPruned() {
505+
Plan analyzedPlan = PlanChecker.from(connectContext)
506+
.analyze("select * from test_stream.s2 where k1 < 100")
507+
.getCascadesContext()
508+
.getRewritePlan();
509+
510+
LogicalOlapTableStreamScan streamScan = findFirstLogicalStreamScan(analyzedPlan);
511+
Assertions.assertNotNull(streamScan);
512+
Assertions.assertFalse(streamScan.isPartitionPruned());
513+
514+
LogicalOlapTableStreamScan prunedScan =
515+
streamScan.withSelectedPartitionIds(streamScan.getSelectedPartitionIds(), false);
516+
517+
Assertions.assertTrue(prunedScan.isPartitionPruned());
518+
Assertions.assertFalse(prunedScan.hasPartitionPredicate());
519+
}
520+
503521
@Test
504522
public void testRecordPlanForMvPreRewriteNormalizesStreamScanInsideCte() throws Exception {
505523
ConnectContext ctx = createDefaultCtx();
@@ -577,6 +595,19 @@ private LogicalProject<?> findFirstLogicalProject(Plan plan) {
577595
return null;
578596
}
579597

598+
private LogicalOlapTableStreamScan findFirstLogicalStreamScan(Plan plan) {
599+
if (plan instanceof LogicalOlapTableStreamScan) {
600+
return (LogicalOlapTableStreamScan) plan;
601+
}
602+
for (Plan child : plan.children()) {
603+
LogicalOlapTableStreamScan found = findFirstLogicalStreamScan(child);
604+
if (found != null) {
605+
return found;
606+
}
607+
}
608+
return null;
609+
}
610+
580611
private boolean containsLogicalStreamScan(Plan plan) {
581612
if (plan instanceof LogicalOlapTableStreamScan) {
582613
return true;

0 commit comments

Comments
 (0)