englefly commented on code in PR #46627:
URL: https://github.com/apache/doris/pull/46627#discussion_r1908266099


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/ProjectAggregateExpressionsForCse.java:
##########
@@ -102,8 +103,16 @@ public Plan 
visitPhysicalHashAggregate(PhysicalHashAggregate<? extends Plan> agg
         }
 
         if (aggregate.child() instanceof PhysicalProject) {
+            List<NamedExpression> newProjections = Lists.newArrayList();
             PhysicalProject<? extends Plan> project = (PhysicalProject<? 
extends Plan>) aggregate.child();
-            List<NamedExpression> newProjections = 
Lists.newArrayList(project.getProjects());
+            Set<Slot> newInputSlots = aggOutputReplaced.stream()
+                    .flatMap(expr -> expr.getInputSlots().stream())
+                    .collect(Collectors.toSet());
+            for (NamedExpression expr : project.getProjects()) {
+                if (!(expr instanceof SlotReference) || 
newInputSlots.contains(expr)) {

Review Comment:
   if it is not slot, it is alias. if it is alias, it must be used by Aggregate 
in 2 cases:
   1. directly used by Agg after rewrite
   2. used by inferred common expression.
   In both cases, alias should not be pruned.



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to