From 651881d7c07d90acfdb48ff92ebc792bcccd1ba4 Mon Sep 17 00:00:00 2001 From: minghong Date: Fri, 18 Oct 2024 17:21:35 +0800 Subject: [PATCH] copy stats and groupId when rewrite physical plan --- .../nereids/processor/post/PlanPostProcessor.java | 4 +++- .../nereids/processor/post/RuntimeFilterPruner.java | 3 +++ .../trees/plans/visitor/DefaultPlanRewriter.java | 11 ++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/PlanPostProcessor.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/PlanPostProcessor.java index 5090acedf43f39..f73d552ee82384 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/PlanPostProcessor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/PlanPostProcessor.java @@ -19,6 +19,7 @@ import org.apache.doris.nereids.CascadesContext; import org.apache.doris.nereids.trees.plans.Plan; +import org.apache.doris.nereids.trees.plans.physical.AbstractPhysicalPlan; import org.apache.doris.nereids.trees.plans.visitor.DefaultPlanRewriter; /** @@ -27,6 +28,7 @@ public class PlanPostProcessor extends DefaultPlanRewriter { public Plan processRoot(Plan plan, CascadesContext ctx) { - return plan.accept(this, ctx); + AbstractPhysicalPlan newPlan = (AbstractPhysicalPlan) super.visit(plan, ctx); + return newPlan == plan ? plan : newPlan.copyStatsAndGroupIdFrom((AbstractPhysicalPlan) plan); } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/RuntimeFilterPruner.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/RuntimeFilterPruner.java index 92b2960fb25c33..3fbaf927ed1702 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/RuntimeFilterPruner.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/RuntimeFilterPruner.java @@ -284,6 +284,9 @@ private boolean isEffectiveRuntimeFilter(EqualTo equalTo, PhysicalHashJoin join) } Slot leftSlot = leftSlots.iterator().next(); Slot rightSlot = rightSlots.iterator().next(); + if (leftStats == null || rightStats == null) { + return false; + } ColumnStatistic probeColumnStat = leftStats.findColumnStatistics(leftSlot); ColumnStatistic buildColumnStat = rightStats.findColumnStatistics(rightSlot); //TODO remove these code when we ensure left child if from probe side diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/DefaultPlanRewriter.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/DefaultPlanRewriter.java index ff89572197df0b..c3d29372a1e878 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/DefaultPlanRewriter.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/DefaultPlanRewriter.java @@ -18,6 +18,7 @@ package org.apache.doris.nereids.trees.plans.visitor; import org.apache.doris.nereids.trees.plans.Plan; +import org.apache.doris.nereids.trees.plans.physical.AbstractPhysicalPlan; import org.apache.doris.nereids.trees.plans.physical.PhysicalOlapScan; import org.apache.doris.nereids.trees.plans.physical.PhysicalStorageLayerAggregate; @@ -56,6 +57,14 @@ public static

P visitChildren(DefaultPlanRewriter rewrite } newChildren.add(newChild); } - return hasNewChildren ? (P) plan.withChildren(newChildren.build()) : plan; + if (hasNewChildren) { + plan = (P) plan.withChildren(newChildren.build()); + if (plan instanceof AbstractPhysicalPlan) { + AbstractPhysicalPlan physicalPlan = (AbstractPhysicalPlan) plan; + plan = (P) ((AbstractPhysicalPlan) physicalPlan.withChildren(newChildren.build())) + .copyStatsAndGroupIdFrom(physicalPlan); + } + } + return plan; } }