Repository navigation
Fix exception "Column identifier is already registered" in planner - #101048
Conversation
During AST fuzzer stress testing, `prepareBuildQueryPlanForTableExpression` could attempt to register the same column identifier twice when the same table expression was processed multiple times with an empty column list. Use `createColumnIdentifierOrGet` to avoid the duplicate registration, and guard `addColumn` with a `hasColumn` check. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Workflow [PR], commit [309b75d] Summary: ✅ AI ReviewSummaryThis PR fixes a planner ClickHouse Rules
Final Verdict
|
|
Add a test. |
Apply proper quoting with `backQuoteIfNeed` when constructing column identifiers from source alias and column name, in both `createColumnIdentifier` and `createColumnIdentifierOrGet`. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The `backQuoteIfNeed` quoting applied to column identifiers in `createColumnIdentifier` and `createColumnIdentifierOrGet` breaks column lookup throughout the planner, because these identifiers are used as internal keys (not SQL identifiers). Names containing dots (e.g. `nested.key`, `u2.uid`) get backtick-quoted, causing `NOT_FOUND_COLUMN_IN_BLOCK` exceptions and EXPLAIN output mismatches. Revert to the original unquoted identifier construction, which is consistent with how the rest of the planner resolves columns. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The planner could throw a LOGICAL_ERROR "Column identifier is already registered" when `prepareBuildQueryPlanForTableExpression` processed a table expression multiple times with an empty selected-column list. This was found by the AST fuzzer during stress testing. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Use `backQuoteIfNeed` for both alias and column name when building column identifiers in `createColumnIdentifier` and `createColumnIdentifierOrGet` to avoid collisions for quoted names containing dots. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The `backQuoteIfNeed` change in `createColumnIdentifier` causes EXPLAIN output to backtick-quote column identifiers containing dots, parens, or numeric names (e.g. `__table1.json.a` → `__table1.\`json.a\``). Update reference files for affected tests: - 03275_subcolumns_in_primary_key - 03302_analyzer_distributed_filter_push_down - 03375_l2_distance_transposed_partial_reads_pass - 03405_merge_filter_into_join - 03445_subcolumns_prewhere_pushdown - 03786_outer_to_semi_or_anti Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Extract the shared identifier-building logic from `createColumnIdentifier` and `createColumnIdentifierOrGet` into a static `buildColumnIdentifier` helper, as suggested in review. Fix the `03375_l2_distance_transposed_partial_reads_pass` reference file where the EXPLAIN output truncation point for `cosineDistanceTransposed` was off by 8 characters (due to backtick-quoted column names making the line longer). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…istance_transposed_partial_reads_pass\` The EXPLAIN output truncation point for the \`L2DistanceTransposed\` function result name was off — the backtick-quoted column identifiers make the line longer, so the fixed-width truncation cuts deeper into the result name. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…eIfNeed` in column identifiers The `backQuoteIfNeed` change in `buildColumnIdentifier` causes EXPLAIN output to backtick-quote column identifiers containing dots (e.g. `__table1.json.a` → `__table1.\`json.a\``). This test was missed in the earlier reference update. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…te-column-identifier
|
The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix. |
…te-column-identifier
…te-column-identifier
…te-column-identifier
…te-column-identifier
…te-column-identifier
…te-column-identifier
…te-column-identifier
LLVM Coverage Report
Changed lines: 100.00% (17/17) · Uncovered code |
alexey-milovidov
left a comment
There was a problem hiding this comment.
A little bit questionable, but at least the change with quoting is good.
|
Hi — this PR may need backporting to Affected code: Why: Fix in If this should be backported, consider adding |
The original "Column identifier is already registered" exception is fixed by other PRs that landed on master: - #101048 ("Fix exception 'Column identifier is already registered' in planner") - #101051 ("Fix Column identifier is already registered with additional_result_filter in UNION/EXCEPT") Per the author's review comment on this PR, drop the disambiguation workaround in `GlobalPlannerContext::createColumnIdentifier` and keep only the regression test from this PR as a guard. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Reword the comment per review feedback and note that the underlying bug was fixed by other PRs (#101048, #101051), so this test remains as a regression guard rather than as a reproducer. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…UPDATE with EXISTS When the mutations analyzer rewrites `exists((subq))` to `1 IN (SELECT 1 FROM (subq) LIMIT 1)` (the `only_analyze` path), the resulting subquery tree can reach `buildSubqueryPlansForSetsAndAdd` with inner source nodes that have no `__tableN` aliases. The planner then registers `dummy` (or any bare column name) once via `prepareBuildQueryPlanForTableExpression` for the wrapping `QueryNode` and again via `CollectSourceColumnsVisitor` for the inner `TableNode`, producing the LOGICAL_ERROR. Re-running `createUniqueAliasesIfNecessary` on the detached subquery tree before planning guarantees every table expression has a unique alias, so the two registrations produce distinct identifiers like `__table1.dummy` and `__table2.dummy`. Adds a regression test that reproduces the original AST-fuzzer query (STID 4697-4326) from issue #104877. The prior fix family (#100770, #101048, #101051, #101104) addressed the same error class for UNION ALL / additional_result_filter SELECT paths but did not cover the mutations + EXISTS pattern. Issue: #104877 STID: 4697-4326 Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=3120048c80b01b65ef75858d34e17b669505de6a&name_0=MasterCI&name_1=AST%20fuzzer%20%28arm_asan_ubsan%29
…UPDATE with EXISTS When the mutations analyzer rewrites `exists((subq))` to `1 IN (SELECT 1 FROM (subq) LIMIT 1)` (the `only_analyze` path), the resulting subquery tree can reach `buildSubqueryPlansForSetsAndAdd` with inner source nodes that have no `__tableN` aliases. The planner then registers `dummy` (or any bare column name) once via `prepareBuildQueryPlanForTableExpression` for the wrapping `QueryNode` and again via `CollectSourceColumnsVisitor` for the inner `TableNode`, producing the LOGICAL_ERROR. Re-running `createUniqueAliasesIfNecessary` on the detached subquery tree before planning guarantees every table expression has a unique alias, so the two registrations produce distinct identifiers like `__table1.dummy` and `__table2.dummy`. Adds a regression test that reproduces the original AST-fuzzer query (STID 4697-4326) from issue ClickHouse#104877. The prior fix family (ClickHouse#100770, ClickHouse#101048, ClickHouse#101051, ClickHouse#101104) addressed the same error class for UNION ALL / additional_result_filter SELECT paths but did not cover the mutations + EXISTS pattern. Issue: ClickHouse#104877 STID: 4697-4326 Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=3120048c80b01b65ef75858d34e17b669505de6a&name_0=MasterCI&name_1=AST%20fuzzer%20%28arm_asan_ubsan%29
During AST fuzzer stress testing,
prepareBuildQueryPlanForTableExpressioncould attempt to register the same column identifier twice when the same table expression was processed multiple times with an empty column list. UsecreateColumnIdentifierOrGetto avoid the duplicate registration, and guardaddColumnwith ahasColumncheck.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
LOGICAL_ERROR"Column identifier is already registered" in the planner that could occur when the same table expression was processed multiple times.Documentation entry for user-facing changes