[enhancement](Nereids) turn on stream pre aggregate for nereids (#13538)

Exactly the same behavior as the legacy optimizer.
This commit is contained in:
morrySnow
2022-10-21 17:23:53 +08:00
committed by GitHub
parent 3e92f742bf
commit ddc08ee690
2 changed files with 18 additions and 15 deletions

View File

@ -27,16 +27,18 @@ import org.apache.doris.nereids.trees.plans.physical.PhysicalAggregate;
public class LogicalAggToPhysicalHashAgg extends OneImplementationRuleFactory {
@Override
public Rule build() {
return logicalAggregate().then(agg -> new PhysicalAggregate<>(
// TODO: for use a function to judge whether use stream
agg.getGroupByExpressions(),
agg.getOutputExpressions(),
agg.getPartitionExpressions(),
agg.getAggPhase(),
false,
agg.isFinalPhase(),
agg.getLogicalProperties(),
agg.child())
).toRule(RuleType.LOGICAL_AGG_TO_PHYSICAL_HASH_AGG_RULE);
return logicalAggregate().thenApply(ctx -> {
boolean useStreamAgg = !ctx.connectContext.getSessionVariable().disableStreamPreaggregations
&& !ctx.root.getGroupByExpressions().isEmpty();
return new PhysicalAggregate<>(
ctx.root.getGroupByExpressions(),
ctx.root.getOutputExpressions(),
ctx.root.getPartitionExpressions(),
ctx.root.getAggPhase(),
useStreamAgg,
ctx.root.isFinalPhase(),
ctx.root.getLogicalProperties(),
ctx.root.child());
}).toRule(RuleType.LOGICAL_AGG_TO_PHYSICAL_HASH_AGG_RULE);
}
}

View File

@ -49,6 +49,7 @@ import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;
@SuppressWarnings({"unchecked", "unused"})
public class ImplementationTest {
private static final Map<String, Rule> rulesMap
= ImmutableMap.<String, Rule>builder()
@ -82,7 +83,7 @@ public class ImplementationTest {
PhysicalPlan physicalPlan = executeImplementationRule(project);
Assertions.assertEquals(PlanType.PHYSICAL_PROJECT, physicalPlan.getType());
PhysicalProject physicalProject = (PhysicalProject) physicalPlan;
PhysicalProject<GroupPlan> physicalProject = (PhysicalProject<GroupPlan>) physicalPlan;
Assertions.assertEquals(2, physicalProject.getExpressions().size());
Assertions.assertEquals(col1, physicalProject.getExpressions().get(0));
Assertions.assertEquals(col2, physicalProject.getExpressions().get(1));
@ -98,7 +99,7 @@ public class ImplementationTest {
PhysicalPlan physicalPlan = executeImplementationRule(topN);
Assertions.assertEquals(PlanType.PHYSICAL_TOP_N, physicalPlan.getType());
PhysicalTopN physicalTopN = (PhysicalTopN) physicalPlan;
PhysicalTopN<GroupPlan> physicalTopN = (PhysicalTopN<GroupPlan>) physicalPlan;
Assertions.assertEquals(limit, physicalTopN.getLimit());
Assertions.assertEquals(offset, physicalTopN.getOffset());
Assertions.assertEquals(2, physicalTopN.getOrderKeys().size());
@ -110,10 +111,10 @@ public class ImplementationTest {
public void toPhysicalLimitTest() {
int limit = 10;
int offset = 100;
LogicalLimit logicalLimit = new LogicalLimit<>(limit, offset, groupPlan);
LogicalLimit<GroupPlan> logicalLimit = new LogicalLimit<>(limit, offset, groupPlan);
PhysicalPlan physicalPlan = executeImplementationRule(logicalLimit);
Assertions.assertEquals(PlanType.PHYSICAL_LIMIT, physicalPlan.getType());
PhysicalLimit physicalLimit = (PhysicalLimit) physicalPlan;
PhysicalLimit<GroupPlan> physicalLimit = (PhysicalLimit<GroupPlan>) physicalPlan;
Assertions.assertEquals(limit, physicalLimit.getLimit());
Assertions.assertEquals(offset, physicalLimit.getOffset());
}