alamb commented on code in PR #27019:
URL: https://github.com/apache/datafusion/pull/27019#discussion_r4671691508


##########
datafusion/optimizer/src/decorrelate.rs:
##########
@@ -112,6 +112,21 @@ pub struct PullUpCorrelatedExpr {
     /// `f_down`'s `Limit` arm reads it: a `Limit` is only dropped from an
     /// `EXISTS` subquery when this holds for every node above it.
     depends_only_on_input_having_rows_above: Vec<bool>,
+    /// For each node on that same path, how many plans [`Self::alias_order`]
+    /// held when `f_down` reached the node. Pushed and popped with
+    /// [`Self::column_refs_above`].
+    aliases_before: Vec<usize>,
+    /// Each `SubqueryAlias` plan `f_up` has returned so far, in the order it
+    /// first did, and whether it has had facts in
+    /// `correlated_subquery_cols_map` or `collected_count_expr_map`.
+    ///
+    /// Both maps are keyed by the plan value, so two equal `SubqueryAlias`
+    /// nodes at different places in the subquery share one entry, and one of
+    /// them reads or replaces the facts of the other. When a node returns a
+    /// `SubqueryAlias` plan that some node outside its own subtree returned
+    /// first, and either of them has facts, the pull up stops. See
+    /// <https://github.com/apache/datafusion/issues/26692>.
+    alias_order: HashMap<LogicalPlan, (usize, bool)>,

Review Comment:
   this kind of stuff is why I am convinced that the current subquery 
decorrelation code is doomed to fail in general (we need a rewrite / refactor 
to make it work generally)



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