Repository navigation
Fix exception in join order optimizer when column names overlap - #100401
Conversation
The `JoinExpressionActions` constructor throws a LOGICAL_ERROR when left and right join headers contain overlapping column names. This can happen when scalar subquery results and join table aliases collide in complex queries (e.g. both sides produce a column named `__table2`). Skip the join order optimization in this case, falling back to the unoptimized join which handles overlapping names correctly. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100398&sha=d69b29735a13a4e8b1c0b95f263a4d962a8943da&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%2C%20old_compatibility%29 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Workflow [PR], commit [f94e1ac] Summary: ✅ AI ReviewSummaryThis PR fixes a real correctness issue in join-order optimization: when left/right headers have overlapping internal column names, reordering could throw a ClickHouse Rules
Final Verdict
|
The test needs the exact fuzzed query with the original table schema (including LowCardinality types) to reproduce the internal column name collision. Removed serverError expectation since LOGICAL_ERROR cannot be used in tests (it aborts in debug builds). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The join order optimizer is a new-analyzer feature, and the fuzzed query causes stack overflow in `ApplyWithSubqueryVisitor` with the old analyzer. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…overlapping-names
|
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. |
LLVM Coverage Report
Changed lines: 78.95% (15/19) · Uncovered code |
… names The join order optimizer's `JoinExpressionActions` constructor enforces `input_nodes.size() == left_header.columns() + right_header.columns()`. When a child plan produces an output header with duplicate column names (for example from `SELECT 1 AS x, 2 AS y, x, y QUALIFY 7`, or when a correlated scalar subquery preserves pre-projection duplicates), `foldActionsByProjection` deduplicates INPUT nodes by name in the folded DAG, so the count invariant fails and the exception `Input nodes size mismatch in dag` is raised inside `optimizeJoinLogicalImpl` → `chooseJoinOrder`. PR ClickHouse#100401 already skips reordering when left and right headers share names (`Left and right columns have same names`). This change extends the same early-exit to duplicates that appear *within* one side. Both are situations that the reconstruction cannot represent, so skipping the optimization preserves the original plan and avoids the exception. Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=2892de442814d1e629f7ea1e25ed88d7c6441297&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_debug%29 STID: 4752-593c
|
Backport labels have been automatically added based on https://github.com/ClickHouse/clickhouse-core-incidents/issues/1740 Labels added:
These labels ensure backport PRs are properly created for each affected release version. The release automation will create backport PRs as needed based on these labels. |
Cherry pick #100401 to 26.2: Fix exception in join order optimizer when column names overlap
…column names overlap
Cherry pick #100401 to 26.3: Fix exception in join order optimizer when column names overlap
…column names overlap
Backport #100401 to 26.3: Fix exception in join order optimizer when column names overlap
|
Backport labels have been automatically added based on https://github.com/clickhouse/clickhouse-core-incidents/issues/1740 Labels added:
These labels ensure backport PRs are properly created for each affected release version. The release automation will create backport PRs as needed based on these labels. |
Linked issues
Fix exception in join order optimizer when left and right join headers contain overlapping internal column names (e.g. both sides produce
__table2). This can happen when scalar subquery results and join table aliases collide in complex fuzzed queries. The optimizer now skips reordering in this case, falling back to the unoptimized join which handles overlapping names correctly.Closes #89166
AST fuzzer report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100398&sha=d69b29735a13a4e8b1c0b95f263a4d962a8943da&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%2C%20old_compatibility%29
#100398
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
Version info
26.4.1.59326.3.14.27