Repository navigation
Fix exception in GlobalPlannerContext::createColumnIdentifier for UNION ALL queries - #101104
Conversation
…NION ALL queries In UNION ALL queries, all branches share the same `GlobalPlannerContext`. When both branches reference a table expression with no alias and the same column name, `createColumnIdentifier` would throw "Column identifier is already registered". This was triggered by the AST fuzzer. Fix by disambiguating with a numeric suffix instead of throwing. Found in: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=101023&sha=c1dde15b4607b68f7bbecd414d3d65fe2dc8e088&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Workflow [PR], commit [a6dd601] Summary: ✅ AI ReviewSummaryThis PR adds a focused stateless regression test for a previously fixed planner exception in ClickHouse Rules
Final VerdictStatus: ✅ Approve |
…rContext` The previous approach of disambiguating with a numeric suffix (`_0`, `_1`, ...) broke the column identifier mapping — the second UNION ALL branch's `TableExpressionData` would store identifier `m_0` while the execution layer expected `m`, causing missing rows. The correct fix is simpler: just return the existing identifier on collision. Each UNION ALL branch has its own `PlannerContext` with separate `TableExpressionData`, so they can safely share the same column identifier string. Also add `ORDER BY` to the test to make output deterministic. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…identifier-union-all
…identifier-union-all
…identifier-union-all
…nstead of reusing Instead of silently reusing an existing identifier on collision in `GlobalPlannerContext::createColumnIdentifier`, append a numeric suffix (e.g. `_0`, `_1`) to maintain uniqueness. This prevents hiding logical errors while still supporting UNION ALL branches that share a `GlobalPlannerContext`. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…identifier-union-all
…identifier-union-all
…identifier-union-all
|
Does not reproduce anymore. Let's try to keep the test only. |
The bug in `GlobalPlannerContext::createColumnIdentifier` no longer reproduces on current master, so revert the planner code changes and keep only the regression test. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
The flaky check failure is fixed in #102148, let's update the branch. |
…identifier-union-all
The revert was premature — CI (arm_asan_ubsan targeted, and multiple flaky-check shards) still reproduces "Column identifier m is already registered" from the regression test added in this PR. Restore the disambiguation with a numeric suffix. On collision, append `_0`, `_1`, ... to keep identifiers unique across `UNION ALL` branches that share a `GlobalPlannerContext`. Reference CI run: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=101104&sha=09c1177f0af08116d6c26b2486d4d0eb622dc329&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20targeted%29 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…identifier-union-all
…identifier-union-all
…identifier-union-all
|
The bug does not reproduce by the provided test. Was it fixed by any other previous PRs? |
…identifier-union-all # Conflicts: # src/Planner/PlannerContext.cpp
| @@ -0,0 +1,11 @@ | |||
| -- Reproducer for a bug where UNION ALL branches sharing the same GlobalPlannerContext | |||
There was a problem hiding this comment.
Minor typo in the test comment: branches sharing reads as ungrammatical here.
Suggested wording:
-- Reproducer for a bug where UNION ALL branches that share the same GlobalPlannerContext
LLVM Coverage Report
Changed lines: 36.36% (4/11) · Uncovered code |
…identifier-union-all
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]>
…identifier-union-all
…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
This PR adds a regression test for an exception that used to be raised by
GlobalPlannerContext::createColumnIdentifierfor someUNION ALLqueries:In
UNION ALLqueries, all branches share the sameGlobalPlannerContext. When two branches referenced a table expression with no alias and the same column name,createColumnIdentifierwould throwColumn identifier is already registered. This was originally found by the AST Fuzzer.The underlying issue is already fixed on master by:
Fix exception "Column identifier is already registered" in plannerFix Column identifier is already registered with additional_result_filter in UNION/EXCEPTSo this PR keeps only the regression test (no source code changes) as a guard against future regressions.
Original report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=101023&sha=c1dde15b4607b68f7bbecd414d3d65fe2dc8e088&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29 (#101023)
Changelog category (leave one):
Documentation entry for user-facing changes
Version info
26.5.1.145