Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ public Plan visitLogicalJoin(LogicalJoin<? extends Plan, ? extends Plan> join, P
context.needOutputCount(), rightFuncs);
boolean rightNeedOutputCount = needOutputCountForJoinChild(join, toRight, toLeft,
context.needOutputCount(), leftFuncs);
Optional<PushDownAggContext> leftChildContext = toLeft ? Optional.of(context.forOneBranch(leftFuncs,
Optional<PushDownAggContext> leftChildContext = toLeft ? Optional.ofNullable(context.forOneBranch(leftFuncs,
leftAliasMap, leftChildGroupByKeys, passThroughBigJoin, leftNeedOutputCount)) : Optional.empty();
Optional<PushDownAggContext> rightChildContext = toRight ? Optional.of(context.forOneBranch(rightFuncs,
Optional<PushDownAggContext> rightChildContext = toRight ? Optional.ofNullable(context.forOneBranch(rightFuncs,
rightAliasMap, rightChildGroupByKeys, passThroughBigJoin, rightNeedOutputCount)) : Optional.empty();

Plan newLeft = join.left();
Expand Down Expand Up @@ -744,6 +744,9 @@ public Plan visitLogicalFilter(LogicalFilter<? extends Plan> filter, PushDownAgg

@Override
public Plan visitLogicalRelation(LogicalRelation relation, PushDownAggContext context) {
if (context.aggFuncAndGroupKeyAllEmpty()) {
return relation;
}
return genAggregate(relation, context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ public PushDownAggContext withGroupKeys(List<SlotReference> groupKeys) {
public PushDownAggContext forOneBranch(List<AggregateFunction> branchAggFunctions,
Map<AggregateFunction, Alias> branchAliasMap, List<SlotReference> groupKeys,
boolean passThroughBigJoin, boolean needOutputCount) {
if (branchAggFunctions.isEmpty() && groupKeys.isEmpty()) {
return null;
}
return new PushDownAggContext(branchAggFunctions, groupKeys, branchAliasMap,
cascadesContext, passThroughBigJoin, hasDecomposedAggIf, hasCaseWhen,
bilateralState, needOutputCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
import org.apache.doris.nereids.trees.plans.logical.LogicalFilter;
import org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
import org.apache.doris.nereids.trees.plans.logical.LogicalRelation;
import org.apache.doris.nereids.types.BigIntType;
import org.apache.doris.nereids.util.MemoPatternMatchSupported;
import org.apache.doris.nereids.util.PlanChecker;
Expand Down Expand Up @@ -464,6 +465,27 @@ void testBilateralPushMultiLevelJoin() {
}
}

@Test
void testEmptyContextDoesNotAddRelationAggregate() {
Comment thread
morrySnow marked this conversation as resolved.
connectContext.getSessionVariable().setEagerAggregationMode(1);
try {
PlanChecker planChecker = PlanChecker.from(connectContext).analyze("select * from t1");
Plan analyzedPlan = planChecker.getPlan();
LogicalRelation relation = findFirstPlan(analyzedPlan, LogicalRelation.class);
Assertions.assertNotNull(relation, analyzedPlan.treeString());
PushDownAggContext context = new PushDownAggContext(
Collections.emptyList(), Collections.emptyList(), Collections.emptyMap(),
planChecker.getCascadesContext(),
true, false, false, new BilateralState(), false);

Plan rewritten = relation.accept(new EagerAggRewriter(), context);

Assertions.assertSame(relation, rewritten, rewritten.treeString());
} finally {
connectContext.getSessionVariable().setEagerAggregationMode(0);
}
}

@Test
void testVolatileJoinConjunctBlocksPushDown() {
connectContext.getSessionVariable().setEagerAggregationMode(1);
Expand Down
Loading