Fix correlated project pushdown for SQL federation IN subqueries#38405
Fix correlated project pushdown for SQL federation IN subqueries#38405ym0506 wants to merge 3 commits intoapache:masterfrom
Conversation
|
Hi @ym0506, this pr looks great, can you add an e2e sql test in |
thank you The new case covers the correlated non-join IN subquery path that triggered this issue: I limited it with order_id < 1010 so the expected result stays small and deterministic. |
|
I adjusted the e2e regression case to keep the outer side selective while preserving the correlated non-join IN-subquery path. The new SQL still covers the original issue pattern, but wraps the outer table in a filtered derived table so the outer scan can keep |
Summary
This PR fixes correlated
INsubqueries that fail when the subquery projects an outer reference from a non-join subquery.Root Cause
PushProjectIntoScanRulepushed project expressions intoLogicalScanwithout checking whether the projection contained correlated references.For queries like:
the projected expression inside the subquery contains an outer reference. After it was pushed into
LogicalScan, the scan conversion path failed because the pushed-down scan tree still contained correlated expressions.The more complex join case succeeded because it did not go through the same simple project-to-scan pushdown path.
Fix
This change makes
PushProjectIntoScanRuleskip pushdown when a projected expression contains correlated references.Specifically:
RexCorrelVariableRexFieldAccessthat references a correlated expressionRexCalloperandsTests
Added regression coverage for:
PushProjectIntoScanRuleTestSQLStatementCompilerIT#assertCompileWhenCorrelatedInSubqueryProjectsOuterColumnFixes #37439