hcrosse opened a new pull request, #27782:
URL: https://github.com/apache/datafusion/pull/27782

   ## Which issue does this PR close?
   
   - Closes #27781.
   
   ## Rationale for this change
   
   Correlated subquery predicates in `JOIN ... ON` clauses fail on unaliased 
tables with a missing field schema error because `has_all_column_refs` ignores 
`Subquery::outer_ref_columns`. That lets `PushDownFilter` push predicates 
referencing one side of a join onto the opposite child.
   
   ## What changes are included in this PR?
   
   - Update 
[`has_all_column_refs`](https://github.com/apache/datafusion/blob/main/datafusion/optimizer/src/utils.rs#L148)
 to check `Subquery::outer_ref_columns` on `Exists`, `InSubquery`, 
`SetComparison`, and `ScalarSubquery` nodes, matching 
[`for_each_referenced_index`](https://github.com/apache/datafusion/blob/main/datafusion/optimizer/src/utils.rs#L112)
 and 
[`references_any_column`](https://github.com/apache/datafusion/blob/main/datafusion/optimizer/src/push_down_filter.rs#L806).
   - Keep direct `Expr::OuterReferenceColumn` nodes ignored at the outer level 
so joins inside correlated subqueries continue pushing predicates that 
reference an enclosing query scope.
   - This relies on `Subquery::outer_ref_columns` as populated on each subquery 
node and does not change subquery decorrelation or nested correlation 
propagation across skipped levels.
   
   ## What is the testing strategy for this PR?
   
   - Unit tests in `datafusion/optimizer/src/utils.rs` and 
`datafusion/optimizer/src/push_down_filter.rs` covering `INNER`, `LEFT`, and 
`RIGHT` joins, `OR` extraction, inferred join predicates, all four subquery 
variants, and joins inside correlated subqueries.
   - End to end SQL cases in `datafusion/sqllogictest/test_files/subquery.slt` 
and updated `exists_in_inner_join_on_reading_both_inputs` in 
`datafusion/sqllogictest/test_files/subquery_decorrelation.slt`, which now 
returns the expected rows.
   
   ## Are there any user-facing changes?
   
   No public API changes. Correlated `JOIN ... ON` predicates referencing one 
side of an inner join (or both sides, as in `subquery_decorrelation.slt`) now 
plan and execute instead of failing with a missing field schema error.
   


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