tlfua opened a new issue, #27801:
URL: https://github.com/apache/datafusion/issues/27801

   ### Describe the bug
   
   A correlated subquery fails to plan when the `ON` clause of a join inside 
the subquery reads an outer column.
   
   ### To Reproduce
   
   ```sql
   CREATE TABLE t (a INT) AS VALUES (1), (2), (4);
   CREATE TABLE i (a INT) AS VALUES (1), (2), (2), (3);
   CREATE TABLE u (b INT) AS VALUES (10), (20);
   
   SELECT o.a FROM t o WHERE EXISTS (
     SELECT 1 FROM i JOIN u ON u.b > o.a * 5
   ) ORDER BY o.a;
   ```
   
   DataFusion main:
   
   ```text
   DataFusion error: Optimizer rule 'simplify_expressions' failed
   caused by
   Schema error: No field named o.a. Did you mean 't.a'?
   Valid fields are t.a, __correlated_sq_2.b.
   ```
   
   The same happens with a correlated `WHERE` as well (`... ON u.b > o.a * 5 
WHERE i.a = o.a`).
   
   ### Expected behavior
   
   `1`, `2` (DuckDB 2.0.1), or a "not implemented" error if this shape can't be 
decorrelated.
   
   ### Additional context
   
   The outer reference in the join filter seems to survive decorrelation as a 
plain `o.a` column. This is different from 
https://github.com/apache/datafusion/issues/27781 , where the subquery itself 
is in the outer query's `JOIN ... ON`. Found while testing 
https://github.com/apache/datafusion/pull/27783 .
   
   ### Willingness to contribute
   
   I cannot contribute a fix for this bug at this time
   


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