Repository navigation
Fix LOGICAL_ERROR "Column identifier is already registered" in UNION ALL - #100770
tiandiwonder merged 7 commits into
Conversation
|
Workflow [PR], commit [7b1d893] Summary: ❌
AI ReviewSummaryThis PR hardens Final VerdictStatus: ✅ Approve |
There was a problem hiding this comment.
Pull request overview
Fixes a planner LOGICAL_ERROR (“Column identifier is already registered”) that can occur in UNION ALL planning when both branches register the same dummy column identifier in a shared GlobalPlannerContext.
Changes:
- Add
GlobalPlannerContext::getOrCreateColumnIdentifier()to make column-identifier registration idempotent for specific planner paths. - Switch the dummy “smallest column” registration in
prepareBuildQueryPlanForTableExpression()to use the idempotent API. - Add a regression test covering the
UNION ALL+count()planning path.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/queries/0_stateless/04056_union_column_identifier_duplicate.sql | Adds a regression query to exercise the UNION ALL planning path that triggers dummy column registration. |
| tests/queries/0_stateless/04056_union_column_identifier_duplicate.reference | Adds expected output for the new regression query. |
| src/Planner/PlannerJoinTree.cpp | Uses the new idempotent column-identifier registration in the dummy-read-column fallback. |
| src/Planner/PlannerContext.h | Introduces the new getOrCreateColumnIdentifier() API with rationale and usage guidance. |
| src/Planner/PlannerContext.cpp | Implements getOrCreateColumnIdentifier() to return an existing identifier instead of throwing. |
| auto [it, inserted] = column_identifiers.emplace(column_identifier); | ||
| return *it; |
There was a problem hiding this comment.
inserted is computed but unused, which can trigger compiler warnings (and potentially fail builds if warnings are treated as errors). Consider avoiding the unused binding (e.g., use .emplace(...).first directly, or explicitly mark/suppress the unused value via (void)inserted / [[maybe_unused]]).
| auto [it, inserted] = column_identifiers.emplace(column_identifier); | |
| return *it; | |
| return *column_identifiers.emplace(column_identifier).first; |
| std::string column_identifier; | ||
|
|
||
| const auto & source_alias = column_source_node->getAlias(); | ||
| if (!source_alias.empty()) | ||
| column_identifier = source_alias + "." + column.name; | ||
| else | ||
| column_identifier = column.name; |
There was a problem hiding this comment.
The identifier formatting logic is now embedded in getOrCreateColumnIdentifier(). To reduce the risk of future divergence from createColumnIdentifier() (e.g., if identifier formatting rules change), consider extracting this formatting into a single shared helper (private method/free function) used by both APIs.
99b7671 to
d67458f
Compare
|
@groeneai, investigate and fix the failure of the integration test, "test_format_avro_confluent". Send a separate PR with the fix or link the existing PR here. |
|
@alexey-milovidov — investigated; no fix is needed. Details: What was the failure?Commit This is the schema-registry container itself returning HTTP 500 with It already self-resolvedAll six Not caused by this PRPR #100770's diff is a single hunk in Test is not chronically flaky either30-day CIDB query for
Master failures since 2026-01-01: only 4 hits, all on 2026-03-17 — which was a system-wide CI outage (130,519 integration-test failures across 4,812 distinct tests that day, not test-specific). Excluding that outage day, this test has had zero master failures in 2026. Conclusion
If a — Groene AI 🤖 (session |
…low scope on fork push
|
Refreshed master to absorb 53 days of fixes. Workflow file was kept at the pre-merge state to bypass the OAuth @groeneai, please investigate the failure of |
|
@alexey-milovidov investigated Cross-PR / 90-day CIDB confirms this is a chronic flake (not specific to PR #100770), matching what you described:
Root cause: Fix: add Local verification: 30/30 passes on debug with randomized regular settings still enabled. This PR ( |
Workflow files in this branch were stale or had been deleted as a workaround for GitHub's workflow-scope check. Restoring them to match `master` so the PR diff no longer contains those unrelated changes.
LLVM Coverage Report
Changed lines: 83.33% (5/6) | lost baseline coverage: 51 line(s) · Uncovered code |
835ad2e
…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
…r runners Add `no-random-merge-tree-settings` so the CI runner does not inject defaults like `index_granularity = 3` that turn the two `OPTIMIZE FINAL` vertical merges into a >600 s walk under MSan + WasmEdge and similar slow runners. The test already pins every MergeTree setting it cares about (`min_bytes_for_wide_part = 0`, `vertical_merge_algorithm_min_rows_to_activate = 1`, `vertical_merge_optimize_lightweight_delete = 1`, ...) in the table SETTINGS, so randomizing the rest only adds variance, not coverage. Sibling vertical-merge tests 02981, 04041, 04145 use the same tag. Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100770&sha=fe0c8cb7986e4c9b83529a24215c5ed28b2a2137&name_0=PR&name_1=Stateless%20tests%20%28amd_msan%2C%20WasmEdge%2C%20parallel%2C%202%2F2%29 PR: ClickHouse#100770
…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
The AST fuzzer can produce ASTSelectWithUnionQuery nodes where two UNION
branches share the same physical ASTPtr. If such sharing reaches the
analyzer, the resulting QueryTree can also contain shared nodes. When the
planner then registers column identifiers in the shared GlobalPlannerContext
— specifically in the columns_names.empty() fallback of
prepareBuildQueryPlanForTableExpression that picks a dummy "smallest column"
to read — the second branch throws a LOGICAL_ERROR ("Column identifier is
already registered").
Fix: after each recursive fuzz() round on UNION children, deduplicate
sibling branch pointers — any branch that is the same pointer as a
previously seen sibling is replaced with a clone, normalizing the invalid
shared state before it reaches the analysis pipeline.
Fix #100678
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Documentation entry for user-facing changes
Note
Low Risk
Low risk: change is isolated to
QueryFuzzerand only normalizes invalid fuzzer-generated UNION AST sharing by cloning duplicate sibling pointers.Overview
Prevents the AST fuzzer from emitting
UNIONqueries where multiple branches share the same underlying AST node.After fuzzing
ASTSelectWithUnionQuerychildren, the code now detects duplicate siblingASTPtrs and replaces repeats withclone()d nodes, avoiding downstream analyzer/planner failures likeLOGICAL_ERROR ("Column identifier is already registered").Reviewed by Cursor Bugbot for commit 7b1d893. Bugbot is set up for automated code reviews on this repo. Configure here.
Version info
26.6.1.174