github-actions[bot] commented on code in PR #65682:
URL: https://github.com/apache/doris/pull/65682#discussion_r3594679199


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/joinorder/hypergraphv2/receiver/PlanReceiver.java:
##########
@@ -293,27 +293,42 @@ private LogicalPlan proposeProject(LogicalPlan join, 
List<Edge> edges, long left
         Set<Slot> outputSet = join.getOutputSet();
         // calculate required columns by all parents
         Set<Slot> requireSlots = calculateRequiredSlots(left, right, edges);
+        // Pending projected aliases may reference input slots (e.g., A.v, B.v 
for
+        // s=A.v+B.v) that are not in finalRequiredSlots or unused edges. 
Preserve
+        // them so the join output still contains the base columns needed to 
evaluate
+        // the alias expressions, both for aliases emitted at this stage and 
those
+        // deferred to a later join whose bitmap is a superset.
+        requireSlots.addAll(hyperGraph.getAllAliasInputSlotsForNodes(
+                LongBitmap.newBitmapUnion(left, right)));
         List<NamedExpression> allProjects = new ArrayList<>(outputSet.size());
         for (Slot slot : outputSet) {
             if (requireSlots.contains(slot)) {
                 allProjects.add(slot);
             }
         }
-        if (hyperGraph.hasLiteralAlias()) {
-            allProjects.addAll(hyperGraph.getLiteralAlias(left, right));
-        }
 
         if (allProjects.isEmpty()) {
             allProjects.add(new Alias(new ExprId(-1), new 
TinyIntLiteral((byte) 1)));
         }
 
-        // propose logical project
+        // propose logical project for the slot pass-through
         LogicalPlan logicalPlan;
         if (outputSet.equals(new HashSet<>(allProjects))) {
             logicalPlan = join;
         } else {
             logicalPlan = new LogicalProject<>(allProjects, join);
         }
+
+        // Emit projected alias layers as separate LogicalProject nodes.
+        // Each layer corresponds to one original Project in the source plan,
+        // preserving materialization boundaries for volatile expressions
+        // (e.g., uuid()) that cannot be flattened into a single Project.
+        if (hyperGraph.hasProjectedAliases()) {
+            for (List<NamedExpression> layer : 
hyperGraph.getProjectedAliasLayers(left, right)) {
+                logicalPlan = new LogicalProject<>(layer, logicalPlan);

Review Comment:
   [P1] Preserve pass-through slots in each rebuilt Project layer
   
   A `LogicalProject` outputs exactly its explicit project list, but each 
stored layer contains only aliases. For example:
   
   ```text
   LeftOuterJoin(C.k = D.k)
     C
     Project[D.k, coalesce(D.v, 0) AS dv]
       D
   ```
   
   `addGroup({D})` first retains `D.k` for the unused parent edge and `D.v` for 
`dv`, then this loop replaces that output with `Project[dv]`. The parent join 
still references `D.k`, so the copied plan has a predicate bound to a missing 
child slot and can fail `CheckAfterRewrite`. This is distinct from the existing 
pending-input thread: the inputs are now retained before alias evaluation, then 
the newly added separate layer discards the companion key. Carry forward every 
still-required child slot in each layer (or record the source Project's 
complete outputs), and cover a nullable Project that returns both its join key 
and retained alias.



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