feiniaofeiafei commented on code in PR #63690:
URL: https://github.com/apache/doris/pull/63690#discussion_r3402043228


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/eageraggregation/EagerAggRewriter.java:
##########
@@ -534,21 +656,382 @@ public Plan visitLogicalRelation(LogicalRelation 
relation, PushDownAggContext co
     }
 
     private Plan genAggregate(Plan child, PushDownAggContext context) {
-        if (context.isValid() && checkStats(child, context)) {
+        if (isPushDisabledByVariable(context)) {
+            context.getBilateralState().registerNoCountSlot(child);
+            return child;
+        }
+        if (checkStats(child, context) || isPushEnabledByVariable(context)) {
             List<NamedExpression> aggOutputExpressions = new ArrayList<>();
             for (AggregateFunction func : context.getAggFunctions()) {
                 aggOutputExpressions.add(context.getAliasMap().get(func));
             }
+            Alias countStarAlias = null;
+            boolean countStarAlreadyProjected = false;
+            Count countStar = new Count();

Review Comment:
   Done. I changed count(*) emission to be conditional instead of unconditional 
in genAggregate().
   
   The rewrite now carries a needOutputCount flag in PushDownAggContext. A 
pushed aggregate only emits count(*) when the parent needs it for upper-level 
join count propagation, or when the subtree may participate in bilateral join 
multiplicity recovery. For pure one-side pushdown paths where the count is not 
consumed, genAggregate() no longer adds the extra count(*) output.
   
   Also, if the original query already contains count(*), the rewrite reuses 
that existing count(*) output as the count slot instead of emitting a duplicate 
synthetic count column in LogicalJoin and LogicalUnion.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to