[enhancement](Nereids) remove deriveStats jobs for some groupExpression (#24835)

Don't call DeriveStatJob for follow group expressions:

- the group expression that is generated by the joinCommute rule
- the group expression that is generated by the implementation rule without creating a new group
This commit is contained in:
谢健
2023-09-25 17:14:16 +08:00
committed by GitHub
parent 3b4d8b4ac8
commit 60af62b41e

View File

@ -30,6 +30,7 @@ import org.apache.doris.nereids.metrics.event.TransformEvent;
import org.apache.doris.nereids.minidump.NereidsTracer;
import org.apache.doris.nereids.pattern.GroupExpressionMatching;
import org.apache.doris.nereids.rules.Rule;
import org.apache.doris.nereids.rules.RuleType;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
@ -82,11 +83,27 @@ public class ApplyRuleJob extends Job {
newGroupExpression.setFromRule(rule);
if (newPlan instanceof LogicalPlan) {
pushJob(new OptimizeGroupExpressionJob(newGroupExpression, context));
if (!rule.getRuleType().equals(RuleType.LOGICAL_JOIN_COMMUTE)) {
pushJob(new DeriveStatsJob(newGroupExpression, context));
} else {
// The Join Commute rule preserves the operator's expression and children,
// thereby not altering the statistics. Hence, there is no need to derive statistics for it.
groupExpression.setStatDerived(true);
}
} else {
pushJob(new CostAndEnforcerJob(newGroupExpression, context));
if (newGroupExpression.children().stream().anyMatch(g -> g.getLogicalExpressions().isEmpty())) {
// If a rule creates a new group when generating a physical plan,
// then we need to derive statistics for it, e.g., logicalTopToPhysicalTopN rule:
// logicalTopN ==> GlobalPhysicalTopN
// -> localPhysicalTopN
// These implementation rules integrate rules for plan shape transformation.
pushJob(new DeriveStatsJob(newGroupExpression, context));
} else {
groupExpression.setStatDerived(true);
}
}
// we should derive stats for new logical/physical plan if the plan missing the stats
pushJob(new DeriveStatsJob(newGroupExpression, context));
NereidsTracer.logApplyRuleEvent(rule.toString(), plan, newGroupExpression.getPlan());
APPLY_RULE_TRACER.log(TransformEvent.of(groupExpression, plan, newPlans, rule.getRuleType()),
rule::isRewrite);