Skip to content

Fix analyzer conflict between a column alias and a table expression alias - #115714

Merged
alexey-milovidov merged 1 commit into
masterfrom
fix-analyzer-table-alias-conflict
Aug 21, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
fix-analyzer-table-alias-conflict

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 21, 2026 •

Copy link
Copy Markdown
Member

Closes: #79966
Related: #66143

The analyzer rejected queries where a column alias coincides with the alias of a table expression in the FROM section:

SELECT number AS test_name
FROM (SELECT * FROM numbers(1000)) AS test_name
Code: 179. DB::Exception: Duplicate aliases test_name for table expressions in FROM section are not allowed.
Try to register SELECT * FROM numbers(1000). Already registered number AS test_name. (MULTIPLE_EXPRESSIONS_FOR_ALIAS)

This is a regression from #66143 (25.2): QueryExpressionsAliasVisitor started to speculatively register aliased short identifiers from expression sections (e.g. the projection number AS test_name) in the table expression alias map, because such an alias can transitively name a table expression. When a table expression in the FROM section has the same alias, its registration in resolveQueryJoinTreeNode collided with the speculative entry, and the query was rejected. The same conflict also affected aliases of ARRAY JOIN result columns and identifier aliases defined in the WITH section.

Now the actual table expression takes over the alias in the table expression namespace, which matches the old analyzer behavior: a column alias and a table expression alias live in different namespaces, and for table lookups the alias from the FROM section wins. Genuine duplicate aliases between table expressions are still rejected by TableExpressionsAliasVisitor, which runs before this code.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix the MULTIPLE_EXPRESSIONS_FOR_ALIAS error in queries where a column alias coincides with the alias of a table expression in the FROM section (an analyzer regression in version 25.2).


Workflow [PR]
Sync PR [sync-upstream/pr/115714]

Version info

  • Backported to: 26.7.10.6, 26.6.9.12

…lias

`QueryExpressionsAliasVisitor` speculatively registers an aliased short
identifier from expression sections (e.g. the projection
`number AS test_name`) in the table expression alias map, because such an
alias can transitively name a table expression. When a table expression in
the FROM section had the same alias, its registration in
`resolveQueryJoinTreeNode` collided with the speculative entry and the
query was rejected with `MULTIPLE_EXPRESSIONS_FOR_ALIAS`. Let the actual
table expression take over the alias in the table expression namespace,
matching the old analyzer behavior. Genuine duplicate aliases between
table expressions are still rejected by `TableExpressionsAliasVisitor`.

Example: #79966

Co-Authored-By: Claude Fable 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c068f58]

Summary: ✅


AI Review

Summary

This PR fixes the analyzer regression where a speculative table-expression alias collected from an identifier alias could wrongly block a real alias from the FROM section with MULTIPLE_EXPRESSIONS_FOR_ALIAS. I traced the alias collection, join-tree initialization, table-expression registration, and qualified-identifier lookup paths against the new regression coverage and did not find a remaining correctness issue in the patched flow.

Final Verdict

✅ Approve.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 87.00% 87.00% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 79.40% 79.30% -0.10%

Changed lines: Changed C/C++ lines covered: 13/13 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 21, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing c068f584f with master c0f1b119f (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 704.53 MiB 701.48 MiB -3.05 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

7 translation units recompiled, 17 s compile time in total, 7 of them have a recent master baseline.

Job report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@alexey-milovidov alexey-milovidov self-assigned this Aug 21, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 21, 2026
Merged via the queue into master with commit d3076c5 Aug 21, 2026
181 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-analyzer-table-alias-conflict branch August 21, 2026 17:58
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 21, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR labels Sep 15, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 15, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 15, 2026
Backport #115714 to 26.7: Fix analyzer conflict between a column alias and a table expression alias
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 17, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 17, 2026
Backport #115714 to 26.6: Fix analyzer conflict between a column alias and a table expression alias
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.4-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MULTIPLE_EXPRESSIONS_FOR_ALIAS alias clash between column name alias and table name alias

4 participants