Repository navigation
Fix UNKNOWN_IDENTIFIER on ALTER TABLE ... DROP COLUMN with aliased default expression - #109374
Merged
Merged
Conversation
…fault expression When a column has a `DEFAULT` or `MATERIALIZED` expression that defines and later references an inline alias (e.g. `f(...) AS a, ..., a`), `ALTER TABLE ... DROP COLUMN` of an unrelated column failed with `UNKNOWN_IDENTIFIER`. The column-dependency check performed for the dropped column resolves each remaining default expression as a standalone query tree node via `QueryAnalyzer::resolve`. That function collected inline aliases into the resolution scope only when the node was a `LIST`, not when it was a single expression node (which is what `buildQueryTree` produces for a bare default expression). As a result the internal alias was never registered and the later reference to it could not be resolved, while the same expression validates fine at `CREATE TABLE` time (where it is wrapped in a query node). Collect the aliases for the single-node case as well, making standalone expression resolution consistent with list resolution. Closes: #109370 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Contributor
|
Workflow [PR], commit [9fe5eb7] Summary: ✅
AI ReviewSummaryThis PR fixes standalone-expression alias resolution in Final VerdictStatus: ✅ Approve |
`lowerUTF8` requires ICU, which is excluded from the Fast test build, so the test failed there with `Function with name 'lowerUTF8' does not exist`. The function is applied to `hex(MD5(url))`, which is ASCII hex, so `lower` produces an identical result. It is used in the `MATERIALIZED md5` column, which is dropped by the test, so the expected output is unchanged. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109374&sha=4fdec8aa98df6b893755f3590d0dbd8a1b05f465&name_0=PR&name_1=Fast%20test Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Address review: the fix in `QueryAnalyzer::resolve` (which runs
`QueryExpressionsAliasVisitor` before resolving a standalone expression
node so that inline aliases like `f(...) AS a, ..., a` are collected into
the scope) was missing from the sibling `QueryAnalyzer::resolveConstantExpression`.
`StorageMergeTreeAnalyzeIndexes` builds a query tree from a user-supplied
predicate and resolves it via `resolveConstantExpression`, so a predicate
that defines and later references an inline alias hit the same
`UNKNOWN_IDENTIFIER` failure, e.g.:
SELECT * FROM mergeTreeAnalyzeIndexes(currentDatabase(), data,
concat(substring(toString(key) AS h, 1, 1), h) = '11')
Code: 47. Unknown expression or function identifier `h` ...
While executing MergeTreeAnalyzeIndexes. (UNKNOWN_IDENTIFIER)
Mirror the same alias-collection pre-pass in `resolveConstantExpression`
and add a focused regression test that exercises the
`mergeTreeAnalyzeIndexes` predicate path.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This was referenced Jul 12, 2026
Contributor
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 10/11 (90.91%) · Uncovered code |
This was referenced Jul 23, 2026
clickhouse-gh Bot
added a commit
that referenced
this pull request
Jul 23, 2026
Backport #109374 to 26.6: Fix UNKNOWN_IDENTIFIER on ALTER TABLE ... DROP COLUMN with aliased default expression
PedroTadim
added a commit
that referenced
this pull request
Jul 24, 2026
Backport #109374 to 26.3: Fix UNKNOWN_IDENTIFIER on ALTER TABLE ... DROP COLUMN with aliased default expression
PedroTadim
added a commit
that referenced
this pull request
Jul 24, 2026
Backport #109374 to 26.4: Fix UNKNOWN_IDENTIFIER on ALTER TABLE ... DROP COLUMN with aliased default expression
PedroTadim
added a commit
that referenced
this pull request
Jul 24, 2026
Backport #109374 to 26.5: Fix UNKNOWN_IDENTIFIER on ALTER TABLE ... DROP COLUMN with aliased default expression
UnamedRus
pushed a commit
to UnamedRus/ClickHouse
that referenced
this pull request
Aug 12, 2026
…ABLE ... DROP COLUMN with aliased default expression
kewin-robetti
pushed a commit
to viasoftkorp/ClickHouse
that referenced
this pull request
Aug 24, 2026
…ABLE ... DROP COLUMN with aliased default expression
kewin-robetti
pushed a commit
to viasoftkorp/ClickHouse
that referenced
this pull request
Aug 24, 2026
…ABLE ... DROP COLUMN with aliased default expression
kewin-robetti
pushed a commit
to viasoftkorp/ClickHouse
that referenced
this pull request
Aug 24, 2026
…ABLE ... DROP COLUMN with aliased default expression
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
…olumn-default-alias Fix UNKNOWN_IDENTIFIER on ALTER TABLE ... DROP COLUMN with aliased default expression
bytehalo-infra
added a commit
to sentioxyz/ClickHouse
that referenced
this pull request
Sep 25, 2026
STOR: DROP COLUMN when a DEFAULT/MATERIALIZED expression defines an inline alias -> exc. Effect in the production build a394e92: wrong/failing (the upstream test fails on it and passes on official 26.8.8.8; evidence/fix_ci_20260925/upstream_repro/residual/109374.PROD263.txt). Upstream patch unchanged, with its test(s): 04502_alter_drop_column_default_with_alias, 04514_mergetree_analyze_indexes_alias_predicate. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Closes: #109370
When a column has a
DEFAULTorMATERIALIZEDexpression that defines and later references an inline alias (for examplef(...) AS a, ..., a), anALTER TABLE ... DROP COLUMNof an unrelated column failed withUNKNOWN_IDENTIFIER, even though the very same expression is accepted atCREATE TABLEtime.The column-dependency check that runs before dropping a column resolves each remaining default expression as a standalone query-tree node via
QueryAnalyzer::resolve. That function collected inline aliases into the resolution scope only when the node was aLIST, but not when it was a single expression node — which is exactly whatbuildQueryTreeproduces for a bare default expression. As a result the internal alias was never registered in the scope and the later reference to it could not be resolved.The fix collects the aliases for the single-expression case as well, making standalone expression resolution consistent with list resolution (the path already used by
CREATE TABLEvalidation).A new stateless test
04502_alter_drop_column_default_with_aliascovers both a simple aliased default and the nested-lambda case from the report.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
UNKNOWN_IDENTIFIERerror onALTER TABLE ... DROP COLUMNwhen another column has aDEFAULTorMATERIALIZEDexpression that defines and references an inline alias.Version info
26.7.1.939(included in26.7and later)26.6.2.109,26.5.6.71,26.4.5.157,26.3.17.74