yujun777 commented on code in PR #52748:
URL: https://github.com/apache/doris/pull/52748#discussion_r2207062393


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/EliminateJoinByFK.java:
##########
@@ -79,24 +81,42 @@ public Rule build() {
         }
         Set<Slot> output = project.getInputSlots();
         Set<Slot> foreignKeys = Sets.intersection(foreign.getOutputSet(), 
equalSet.getAllItemSet());
-        Map<Expression, Expression> outputToForeign =
-                tryMapOutputToForeignPlan(foreign, output, equalSet);
+        Map<Slot, Slot> outputToForeign = tryMapOutputToForeignPlan(foreign, 
output, equalSet);
         if (outputToForeign != null) {
+            Pair<Plan, Set<Slot>> newChildPair = 
applyNullCompensationFilter(foreign, foreignKeys);
+            Map<Slot, Expression> replacedSlots = 
getReplaceSlotMap(outputToForeign, newChildPair.second);
             List<NamedExpression> newProjects = project.getProjects().stream()
-                    .map(e -> outputToForeign.containsKey(e)
-                            ? new Alias(e.getExprId(), outputToForeign.get(e), 
e.toSql())
-                            : (NamedExpression) e.rewriteUp(s -> 
outputToForeign.getOrDefault(s, s)))
+                    .map(e -> replacedSlots.containsKey(e)
+                            ? new Alias(e.getExprId(), replacedSlots.get(e), 
e.toSql())
+                            : (NamedExpression) e.rewriteUp(s -> 
replacedSlots.getOrDefault(s, s)))
                     .collect(ImmutableList.toImmutableList());
-            return project.withProjects(newProjects)
-                    .withChildren(applyNullCompensationFilter(foreign, 
foreignKeys));
+            return 
project.withProjects(newProjects).withChildren(newChildPair.first);
         }
         return project;
     }
 
-    private @Nullable Map<Expression, Expression> 
tryMapOutputToForeignPlan(Plan foreignPlan,
+    // include two types:
+    // primary slot => foreign slot
+    // foreign slot => NonNullable(foreign slot)
+    private Map<Slot, Expression> getReplaceSlotMap(Map<Slot, Slot> 
outputToForeign,

Review Comment:
   add



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