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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Rewriter.java:
##########
@@ -675,8 +675,12 @@ public class Rewriter extends AbstractBatchJobExecutor {
                         cascadesContext -> 
cascadesContext.rewritePlanContainsTypes(LogicalAggregate.class)
                                 || 
cascadesContext.rewritePlanContainsTypes(LogicalJoin.class)
                                 || 
cascadesContext.rewritePlanContainsTypes(LogicalUnion.class),
-                        topDown(new EliminateGroupByKey()),
+                        // PushDownAggThroughJoinOnPkFk must run before 
EliminateGroupByKey,
+                        // because EliminateGroupByKey wraps FD-redundant 
group-by keys with
+                        // ANY_VALUE and rewrites ExprIds, which 
PushDownAggThroughJoinOnPkFk
+                        // cannot fully handle (especially for non-PK/FK 
primary table columns).
                         topDown(new PushDownAggThroughJoinOnPkFk()),
+                        custom(RuleType.ELIMINATE_GROUP_BY_KEY, 
EliminateGroupByKey::new),

Review Comment:
   EliminateGroupByKey changes a producer aggregate output from slot#old to 
any_value(slot#old) AS slot#new, so the CTE consumer mapping must be updated 
accordingly:
   consumerSlot -> producerSlot#old
   to:
   consumerSlot -> producerSlot#new
   However, this rule runs in beforePushDownJobs, where RewriteCteChildren 
rewrites the consumer and producer sides in separate CascadesContexts:
   The consumer side is rewritten first, before the old -> new mapping exists.
   The producer side is rewritten later, after the mapping is created, but it 
cannot see the outer consumers.
   Moreover, each EliminateGroupByKey.rewriteRoot() creates a separate local 
replaceMap, so the mappings are not shared across CTE subtrees.
   As a result, the producer outputs #new, while 
CTEConsumer.consumerToProducerOutputMap still refers to #old, leaving the 
producer and consumer slot mappings inconsistent.



-- 
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