Support implicit lateral joins for set-returning functions in FROM - #3152
Support implicit lateral joins for set-returning functions in FROM#3152zachmu wants to merge 3 commits into
Conversation
In Postgres, a function called in the FROM list may reference columns of tables that precede it in the same FROM clause: it is an implicit LATERAL join, and the LATERAL keyword is a noise word for function-call FROM items. Queries like the following now work: SELECT k.u FROM pg_index i, unnest(i.indkey) AS k(u) WHERE i.indexrelid = 'bug15_ab'::regclass; Function-call FROM items that follow another FROM item are now marked as lateral during AST conversion, and lateral function items are converted to a TableFuncExpr wrapped in a lateral subquery, which GMS knows how to scope and execute. This also fixes the explicit LATERAL keyword before a function call in FROM, which previously failed with an unsupported-syntax error, and WITH ORDINALITY over such functions. Fixes #3112
|
SummaryCoverage spans correlated array expansion across common join forms, aliasing, row numbering, independent functions, and scope boundaries, including edge cases such as empty arrays and nested joins. The core query behavior is broadly healthy, but outer-join preservation has a correctness gap that can silently omit source data. Merge with caution — this PR causes a medium-severity data-correctness failure in left joins when correlated expansion produces no rows, so affected results can be incomplete. A separate medium-severity parenthesized-join failure is unrelated to the PR and is a flag for later. Tests run by ItoAdditional Findings DetailsThese findings are unrelated to the current changes but were observed during testing. 🟡 Parenthesized joins fail before scope checking
Evidence PackageTip Reply with @itoqa to send us feedback on this test run. |
|
|
@zachmu DOLT
|
A left lateral join over a set-returning function that produces no rows must still return the left row, null-extended. Requires the go-mysql-server fix on branch zachmu/lateral-left-join-on-true (memo exec builder rebuilt filterless lateral joins as lateral cross joins) plus a GMS dependency bump.
|
Diff SummaryCoverage exercises correlated table-function queries across implicit and explicit join forms, including aliasing, row numbering, subquery scope, and matching results across related rows. It also checks edge cases such as empty or null inputs, filtered results, preserved rows in outer joins, and repeated constant values. Safe to merge — the exercised query behavior is healthy across normal flows and important boundary cases, with no PR-attributable regressions or failing checks. No merge blocker was identified. Tests run by Ito
Tests that are no longer relevantBelow are tests that previously ran and are no longer relevant:
Tip Reply with @itoqa to send us feedback on this test run. |


Set-returning functions in the FROM list can now reference columns of preceding tables (implicit and explicit LATERAL joins).
Fixes #3112.