Only apply non-left-associative nesting to deferred join constraints - #2445
Open
revitalkr wants to merge 3 commits into
Open
Only apply non-left-associative nesting to deferred join constraints#2445revitalkr wants to merge 3 commits into
revitalkr wants to merge 3 commits into
Conversation
revitalkr
force-pushed
the
fix/non-left-assoc-join-chain-parsing
branch
from
August 20, 2026 14:23
bf6c5e8 to
99aaa65
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
For dialects with
supports_left_associative_joins_without_parens = false, nested joins are currently created even when no deferred join constraint exists.Problem
The non-left-associative join handling was introduced to support deferred join constraints such as:
A JOIN B JOIN C ON X ON Y
However, the same logic is also applied to queries such as:
A JOIN B LEFT JOIN C ON X
even though there is no deferred ON or USING constraint to attach.
This produces a nested join structure where a flat join chain is expected.
Solution
Only apply the nesting logic when a deferred join constraint (ON or USING) remains to be attached.
Queries without deferred constraints continue to use the normal flat join structure.
Test
Adds coverage for:
SELECT 'ORIGINAL' AS src,
o.order_id,
c.customer_id,
p.product_id
FROM orders AS o
JOIN customers AS c
LEFT JOIN products AS p
ON p.order_id = o.order_id
and verifies that both Generic and Snowflake dialects produce a flat join chain (joins.len() == 2).
Validation - Snowflake script
The following query executes successfully in Snowflake:
SELECT 'ORIGINAL' AS src,
o.order_id,
c.customer_id,
p.product_id
FROM orders AS o
JOIN customers AS c
LEFT JOIN products AS p
ON p.order_id = o.order_id;
and matches the flat interpretation:
(orders AS o JOIN customers AS c)
LEFT JOIN products AS p
ON p.order_id = o.order_id
while the nested interpretation generated by the current non-left-associative handling:
orders AS o
JOIN (
customers AS c
LEFT JOIN products AS p
ON p.order_id = o.order_id
)
is rejected by Snowflake.