peter-toth commented on code in PR #10832:
URL: https://github.com/apache/datafusion/pull/10832#discussion_r1632037636


##########
datafusion/optimizer/src/common_subexpr_eliminate.rs:
##########
@@ -782,9 +786,11 @@ impl TreeNodeRewriter for CommonSubexprRewriter<'_> {
             return Ok(Transformed::new(expr, false, TreeNodeRecursion::Jump));
         }
 
-        let (up_index, expr_id) = &self.id_array[self.down_index];
+        let (up_index, expr_id, aliased) = &self.id_array[self.down_index];
         self.down_index += 1;
 
+        self.aliased |= aliased;

Review Comment:
   This looks suspicuous to me. We don't need to alias if any of the ancestor 
nodes is an alias, do we? But the `f_down()` is called DFS way so if we 
calculate `self.aliased` as `self.aliased |= aliased` then we can take into 
account other nodes than just the ancestors in 2nd+ childrens.
   
   I think we need to maintain some kind of boolan stack with 
`f_down()`/`f_up()` of `CommonSubexprRewriter` to decide about aliasing.



-- 
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: github-unsubscr...@datafusion.apache.org

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


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

Reply via email to