This is an automated email from the ASF dual-hosted git repository.
morrySnow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 8b9199b9599 [fix](eager-agg) Skip eager aggregation for empty relation
context (#65257)
8b9199b9599 is described below
commit 8b9199b95991a027518dda9110b535837324f74a
Author: feiniaofeiafei <[email protected]>
AuthorDate: Wed Jul 8 15:08:09 2026 +0800
[fix](eager-agg) Skip eager aggregation for empty relation context (#65257)
### What problem does this PR solve?
Related PR: #63690
Problem Summary: Eager aggregation could reach a logical relation with
no aggregate functions or group keys and generate an invalid empty
aggregate. Return the relation unchanged for this empty push-down
context and add a focused unit test covering the visitor path.
### Release note
Prevent eager aggregation rewrite from generating an empty aggregate on
a relation.
---
.../rewrite/eageraggregation/EagerAggRewriter.java | 7 +++++--
.../eageraggregation/PushDownAggContext.java | 3 +++
.../eageraggregation/EagerAggRewriterTest.java | 22 ++++++++++++++++++++++
3 files changed, 30 insertions(+), 2 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/eageraggregation/EagerAggRewriter.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/eageraggregation/EagerAggRewriter.java
index 55ee5780607..748a17f99b3 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/eageraggregation/EagerAggRewriter.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/eageraggregation/EagerAggRewriter.java
@@ -149,9 +149,9 @@ public class EagerAggRewriter extends
DefaultPlanRewriter<PushDownAggContext> {
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();
@@ -747,6 +747,9 @@ public class EagerAggRewriter extends
DefaultPlanRewriter<PushDownAggContext> {
@Override
public Plan visitLogicalRelation(LogicalRelation relation,
PushDownAggContext context) {
+ if (context.aggFuncAndGroupKeyAllEmpty()) {
+ return relation;
+ }
return genAggregate(relation, context);
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/eageraggregation/PushDownAggContext.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/eageraggregation/PushDownAggContext.java
index cd315da374a..17c73dcfdf4 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/eageraggregation/PushDownAggContext.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/eageraggregation/PushDownAggContext.java
@@ -158,6 +158,9 @@ public class PushDownAggContext {
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,
containsNullToNonNull,
bilateralState, needOutputCount);
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/eageraggregation/EagerAggRewriterTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/eageraggregation/EagerAggRewriterTest.java
index 5e58f6a8ef5..c9d4a4bd788 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/eageraggregation/EagerAggRewriterTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/eageraggregation/EagerAggRewriterTest.java
@@ -29,6 +29,7 @@ import org.apache.doris.nereids.trees.plans.Plan;
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;
@@ -464,6 +465,27 @@ class EagerAggRewriterTest extends TestWithFeService
implements MemoPatternMatch
}
}
+ @Test
+ void testEmptyContextDoesNotAddRelationAggregate() {
+ 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);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]