Skip to content

Cherry pick #123103 to 26.9: Resolve a JOIN USING key from an alias only for the outermost JOIN - #131370

Merged
robot-ch-test-poll2 merged 5 commits into
backport/26.9/123103from
cherrypick/26.9/123103
Nov 16, 2026
Merged

robot-ch-test-poll2 merged 5 commits into
backport/26.9/123103from
cherrypick/26.9/123103

Conversation

@robot-ch-test-poll

Copy link
Copy Markdown
Contributor

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-pick locally.
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:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

vdimir and others added 4 commits October 1, 2026 14:18
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
@robot-ch-test-poll robot-ch-test-poll added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Nov 13, 2026
…103-26.9

# Conflicts:
#	src/Core/Settings.cpp
@robot-ch-test-poll2
robot-ch-test-poll2 merged commit efc7215 into backport/26.9/123103 Nov 16, 2026
2 checks passed
@robot-ch-test-poll2
robot-ch-test-poll2 deleted the cherrypick/26.9/123103 branch November 16, 2026 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants