[opt](Nereids) forbid some bad pattern aggregate in AggregateStrategy (#18877)

since we cannot do stats derive and cost estimate on agg very good.
this PR remove some aggregate pattern that usually not good.
1. one stage agg after exchange. this pattern is good only when process very few rows.
2. three stage distinct agg with gather middle merge.
This commit is contained in:
morrySnow
2023-04-26 20:01:35 +08:00
committed by GitHub
parent 4a6e65c172
commit e83d0d9b6a
7 changed files with 66 additions and 64 deletions

View File

@ -24,6 +24,7 @@ import org.apache.doris.nereids.jobs.JobContext;
import org.apache.doris.nereids.memo.GroupExpression;
import org.apache.doris.nereids.properties.DistributionSpecHash.ShuffleType;
import org.apache.doris.nereids.trees.expressions.ExprId;
import org.apache.doris.nereids.trees.plans.AggMode;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.physical.PhysicalDistribute;
import org.apache.doris.nereids.trees.plans.physical.PhysicalHashAggregate;
@ -77,6 +78,10 @@ public class ChildrenPropertiesRegulator extends PlanVisitor<Double, Void> {
@Override
public Double visitPhysicalHashAggregate(PhysicalHashAggregate<? extends Plan> agg, Void context) {
if (agg.getAggMode() == AggMode.INPUT_TO_RESULT
&& children.get(0).getPlan() instanceof PhysicalDistribute) {
return -1.0;
}
return 0.0;
}

View File

@ -980,7 +980,8 @@ public class AggregateStrategies implements ImplementationRuleFactory {
if (logicalAgg.getGroupByExpressions().isEmpty()) {
return ImmutableList.<PhysicalHashAggregate<? extends Plan>>builder()
.add(anyLocalGatherGlobalGatherDistinctAgg)
// TODO: this plan pattern is not good usually, we remove it temporary.
// .add(anyLocalGatherGlobalGatherDistinctAgg)
.add(anyLocalHashGlobalGatherDistinctAgg)
.build();
} else {