Repository navigation
Analyzer: fix qualified CTE column references in views - #111386
Merged
Merged
Conversation
CREATE VIEW expands CTE references in FROM into subqueries with cte_name set (ApplyWithSubqueryVisitor). QueryTreeBuilder dropped that name, so qualified identifiers like `c.x` in `WITH c AS (...) SELECT c.x FROM c AS s` stopped resolving when the query was stored in a view, while working inline. ClickHouse/clickhouse-private#55715 (comment)
Co-Authored-By: Claude Fable 5 <[email protected]>
Contributor
|
Workflow [PR], commit [805786a] Summary: ✅
AI ReviewSummaryThis PR propagates Final Verdict✅ No blocking or major issues found in the current patch. |
The style check forbids the phrase "new analyzer" since the analyzer is enabled by default. Use `enable_analyzer = 0/1` in section headers instead. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111386&sha=05a05f6abb44d7724ff155756e6bd671de2a25bb&name_0=PR&name_1=Style%20check #111386
…te-qualified-column
…te-qualified-column
Contributor
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 10/10 (100.00%) · Uncovered code |
KochetovNicolai
approved these changes
Jul 31, 2026
This was referenced Jul 31, 2026
clickhouse-gh Bot
added a commit
that referenced
this pull request
Jul 31, 2026
Backport #111386 to 26.7: Analyzer: fix qualified CTE column references in views
novikd
added a commit
that referenced
this pull request
Aug 3, 2026
Backport #111386 to 26.5: Analyzer: fix qualified CTE column references in views
novikd
added a commit
that referenced
this pull request
Aug 3, 2026
Backport #111386 to 26.6: Analyzer: fix qualified CTE column references in views
UnamedRus
pushed a commit
to UnamedRus/ClickHouse
that referenced
this pull request
Aug 12, 2026
…n references in views
kewin-robetti
pushed a commit
to viasoftkorp/ClickHouse
that referenced
this pull request
Aug 24, 2026
…n references in views
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.
Related: https://github.com/ClickHouse/clickhouse-private/issues/55715
Queries stored in views lost the ability to qualify columns by CTE name under the analyzer (
enable_analyzer = 1):The same query works inline under both analyzers.
CREATE VIEWexpands CTE references inFROMinto subqueries withcte_nameset (ApplyWithSubqueryVisitor, needed soAddDefaultDatabaseVisitordoes not qualify the CTE name with the default database), andQueryTreeBuilderdropped that name when building the query tree, so the table expression was addressable only by its alias. Inline, the analyzer resolves the CTE reference from theWITHsection, and the resulting table expression keeps both the CTE name and the alias.The fix propagates
cte_nameof the expanded subquery into the query tree node, making views (and everything else going throughApplyWithSubqueryVisitor, e.g. materialized views andALTER TABLE ... MODIFY QUERY) behave identically to inline queries. Thecte_nameofASTSubqueryin IN-clause subqueries is intentionally left untouched — nothing binds identifiers against the name of an IN subquery.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
UNKNOWN_IDENTIFIERerror for columns qualified by CTE name (cte_name.column) in queries stored in views when the analyzer is enabled.Version info
26.8.1.503(included in26.8and later)26.7.2.49,26.6.2.149,26.5.6.108