Repository navigation
Cherry pick #123103 to 26.3: Resolve a JOIN USING key from an alias only for the outermost JOIN - #131368
Merged
robot-ch-test-poll2 merged 5 commits intoNov 16, 2026
Conversation
With `analyzer_compatibility_join_using_top_level_identifier` the alias lookup ran for every `JOIN` of the query. A projection alias that refers to the right side of an inner `JOIN`, such as `if(m.symbol = '', b.symbol, m.symbol) AS symbol` over `FROM m FULL JOIN b USING (symbol) FULL JOIN dttm ON 1 = 1`, therefore failed with `UNKNOWN_IDENTIFIER`. The old analyzer rewrote a query with several joins into nested subqueries, so an inner `JOIN` never saw such an alias and resolved the key from its left table; only the outermost `JOIN` does now. The alias probe also re-resolved the already resolved left join tree, so an inner `USING` join below an aliased outermost `USING` key failed with `USING clause expected identifier`; the `USING` branch of `resolveJoin` returns early for a list that is already resolved. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…tree again `try_resolve_identifier_from_query_projection` built a query whose join tree was the already resolved left side of the `JOIN` and resolved that query. An inner `USING` join below an aliased outermost `USING` key therefore failed with `USING clause expected identifier`: its `USING` list held columns by then. The probe now keeps a fresh scope over the left side, takes over the table expression data of its leaves from the current scope and resolves only the aliased expression with `resolveExpressionNode`. Nothing is resolved twice, so the early return for an already resolved `USING` list is gone. The query node of the probe stays as the scope of the resolution: an unqualified matcher inside the expression, such as `tuple(*) AS k`, finds the left side only through the nearest query scope, which the test now pins. The outermost `JOIN` check is evaluated on demand, and the comments no longer claim the old analyzer used an alias for the outermost `JOIN` of a multi-join query: it rejected that shape altogether, so only an inner `JOIN` resolving its key from the left table is old-analyzer behaviour. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…d resolve it as in `PREWHERE` The probe of `try_resolve_identifier_from_query_projection` resolves the aliased expression in a fresh scope over the already resolved left side, but the scope held only the table expression data of the leaves. A qualified matcher finds its table only through `alias_name_to_table_expression_node`, so `tuple(t1.*) AS k ... USING (k)` failed with `Qualified matcher t1.* does not find table`, even for a single `JOIN`. The scope now also registers the aliases of the leaves and counts `joins_count` and `using_joins_count` over the left side, as `resolveQuery` does for a join tree. The synthesized key is an ALIAS column of its source table and is computed right after that table is read, before the joins of the left side. A column of a `USING` key inside the left side therefore has to keep the type it is read with: resolving `t1.a` with the supertype of an inner `USING (a)` raised a `LOGICAL_ERROR` (`Unexpected return type from tuple`) when the alias action ran on the read column. The probe scope sets `allow_resolve_from_using = false`, the mechanism `PREWHERE` uses for the same reason, next to the existing `join_use_nulls = false`. As in `PREWHERE`, an unqualified matcher that expands the key column of the inner `USING` join from both of its tables has no single source table and does not become a key. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…termost-join Resolve a JOIN USING key from an alias only for the outermost JOIN
…103-26.3 # Conflicts: # src/Analyzer/Resolve/QueryAnalyzer.cpp # src/Core/Settings.cpp
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.
Original pull-request #123103
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job