Fix Column identifier is already registered with additional_result_filter in UNION/EXCEPT#101051
Fix Column identifier is already registered with additional_result_filter in UNION/EXCEPT#101051alexey-milovidov wants to merge 6 commits intomasterfrom
Conversation
…_filter` in UNION/EXCEPT When multiple UNION branches share the same `GlobalPlannerContext` and each applies `additional_result_filter`, the `addAdditionalFilterStepIfNeeded` function creates a fake `TableNode` without an alias for each branch. Both branches try to register the same bare column identifier (e.g. "a") in the shared context, causing the second to throw a LOGICAL_ERROR. Fix by giving each fake table expression a unique alias so that column identifiers become unique across branches (e.g. "_additional_result_filter_0.a" and "_additional_result_filter_1.a"). Fixes #99931 https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100947&sha=d0c5ef2315e4d001a6d34cf2e54a9ee2b176a538&name_0=PR&name_1=Stress%20test%20%28amd_debug%29 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Workflow [PR], commit [52ac032] Summary: ❌
AI ReviewSummaryThis PR fixes Findings
ClickHouse Rules
Final Verdict
|
…er-additional-result-filter
…er-additional-result-filter
…er-additional-result-filter
| /// When multiple UNION branches share the same GlobalPlannerContext and each applies additional_result_filter, | ||
| /// the bare column names (e.g. "a") would collide. Give the fake table expression a unique alias | ||
| /// so that identifiers become unique (e.g. "_additional_result_filter_0.a"). | ||
| auto unique_alias = "_additional_result_filter_" + std::to_string(planner_context->getGlobalPlannerContext()->nextUniqueId()); |
There was a problem hiding this comment.
_additional_result_filter_0 and a projected column a, GlobalPlannerContext::createColumnIdentifier can still throw Column identifier ... is already registered for _additional_result_filter_0.a.
Please make the synthetic alias collision-resistant against existing identifiers in the shared context, e.g. loop over generated aliases until alias + "." + projection_column does not exist in GlobalPlannerContext (or use a truly unique suffix that cannot appear in user aliases).
LLVM Coverage Report
Changed lines: 87.50% (7/8) · Uncovered code |
When multiple UNION/EXCEPT branches share the same
GlobalPlannerContextand each appliesadditional_result_filter, theaddAdditionalFilterStepIfNeededfunction creates a fakeTableNodewithout an alias for each branch. Both branches try to register the same bare column identifier (e.g.a) in the shared context, causing the second to throw a LOGICAL_ERROR exception.Fix by giving each fake table expression a unique alias so that column identifiers become unique across branches.
Fixes #99931
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100947&sha=d0c5ef2315e4d001a6d34cf2e54a9ee2b176a538&name_0=PR&name_1=Stress%20test%20%28amd_debug%29
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix LOGICAL_ERROR exception "Column identifier is already registered" when
additional_result_filtersetting is used with UNION or EXCEPT queries.Documentation entry for user-facing changes