englefly commented on code in PR #64330:
URL: https://github.com/apache/doris/pull/64330#discussion_r3385360883
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PullUpProjectExprUnderTopN.java:
##########
@@ -534,8 +556,34 @@ private static LogicalProject<? extends Plan>
simplifyProject(
if (!pulledUpExprIds.contains(ne.getExprId())
&& !isUnavailablePullUpSlot(ne, context,
childOutputExprIds)) {
NamedExpression resolved = resolveNamedExpression(ne, context,
childOutputExprIds);
- simplified.add(resolved);
- existingExprIds.add(resolved.getExprId());
+
+ // If the resolved expression can be provided by the upper
+ // project (via chain resolution: v1#4 → SlotRef#10 →
+ // ElementAt(sa#1,'fa')), skip it in the lower project to
+ // avoid duplicate computation. Only keep the base slots
+ // so they pass through the TopN for lazy materialization.
+ boolean pulledAbove = false;
+ if (resolved != ne) {
+ Expression replaceExpr = getPullUpReplaceExpression(
+ resolved.toSlot(), context);
Review Comment:
r1
--
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]