bvolpato commented on code in PR #26184:
URL: https://github.com/apache/datafusion/pull/26184#discussion_r4240281188


##########
datafusion/common/src/cse.rs:
##########
@@ -363,14 +366,17 @@ where
             // If we are already in a node that can short-circuit then start 
new
             // traversals on its normal conditional children.
             match C::conditional_children(node) {
-                Some((normal, conditional)) => {
-                    normal
-                        .into_iter()
-                        .try_for_each(|n| n.visit(self).map(|_| ()))?;
-                    self.conditional = true;
-                    conditional
-                        .into_iter()
-                        .try_for_each(|n| n.visit(self).map(|_| ()))?;
+                Some((_normal, conditional)) => {
+                    // Visit the children in tree order, whatever order the
+                    // controller lists them in. `CSERewriter` reads 
`id_array` in
+                    // pre-order, so the indexes that this visitor assigns must
+                    // follow the same order.
+                    node.apply_children(|child| {
+                        self.conditional =
+                            conditional.iter().any(|c| std::ptr::eq(*c, 
child));

Review Comment:
   could we use a set of child pointers here? Scanning `conditional` for every 
child makes wide CASE traversal quadratic. In an optimized CSE probe, 10k arms 
went from ~1.4 ms to ~39 ms, and 40k from ~7.4 ms to ~616 ms (base vs PR, CSE 
alone rather than whole-query planning). A set would preserve tree order 
without the repeated scans.



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