Repository navigation
Fix Block structure mismatch in JoinStep for decorrelated correlated subquery with duplicate column name - #109114
Conversation
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-2:20260702-032400 |
|
cc @davenger @novikd — could you review this? A correlated subquery decorrelated into an ANY RIGHT JOIN over a relation with a duplicated column name (from |
|
Workflow [PR], commit [8fdd52e] Summary: ✅
AI ReviewSummaryThis PR narrows the Final Verdict
|
…subquery with duplicate join key A correlated scalar subquery over a relation whose header carries the join KEY column name more than once (e.g. `WITH t AS (SELECT number, * FROM numbers(3))` yields two columns named `number`) is decorrelated into an ANY RIGHT JOIN. With join runtime filters enabled the filter is built on that duplicated key column. The runtime-filter machinery is name-keyed (BuildRuntimeFilterStep on the key name, findInOutputs, name-keyed permutations) and cannot disambiguate two identically-named key columns, so applying the filter changes a downstream join step's stream multiplicity and aborts with 'Block structure mismatch in JoinStep' (a LOGICAL_ERROR, i.e. a handled exception in release builds, a server abort in debug/sanitizer builds). Skip the runtime-filter optimization only when a BUILD-side join KEY column name is duplicated in the build input header. A duplicated non-key build column, or a duplicated key on the probe side (where the filter is only applied and preserves the header), is harmless and must keep the filter - narrowing the guard to the build keys avoids stripping legitimate runtime filters (see 03777_join_runtime_filter_duplicate_columns). The runtime filter is a pure optimization, so skipping it only forgoes the filter and never changes results. Mirrors JoinStepLogical::canRemoveUnusedColumns(), which disables a sibling optimization on duplicated join-condition inputs. Found by the AST fuzzer (Stress test (amd_debug), STID 0993-386d). Co-Authored-By: Claude Opus 4.8 <[email protected]>
5d57b30 to
ff52fbd
Compare
|
Update (narrowed the guard). The initial version skipped the runtime filter whenever any input header had a duplicate column name. That was too broad: it stripped a legitimate runtime filter in the pre-existing test Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-3:20260702-074200 |
CI finish ledger — ff52fbdEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
All other 168 checks green (Build ×all, Stateless, Integration, Stress ×11, AST fuzzer ×6, BuzzHouse ×4, Unit, Upgrade, Performance, Fast test, Mergeable Check, Finish Workflow). The PR-caused Fast-test 03777 failure on the prior head 5d57b30 was fixed here by narrowing the runtime-filter duplicate-name guard. Session id: cron:our-pr-ci-monitor:20260702-120000 |
alexey-milovidov
left a comment
There was a problem hiding this comment.
Yes, very reasonable. Thank you!
|
@groeneai, the "Not-ready Set" has been fixed in master. Please update the branch. |
…e-filter-dup-column-decorrelation
|
Branch updated: merged latest master (now including the Not-ready Set fix). Head is now 76bcc25. |
The two EXPLAIN assertions in 04493_correlated_subquery_join_runtime_filter_dup_column check that a BuildRuntimeFilter step is present. The runtime filter is only added for hash-family join algorithms (supportsRuntimeFilter: hash, parallel_hash, grace_hash). CI randomizes join_algorithm, so runs that pick full_sorting_merge/partial_merge built no filter and the assertions returned 0 instead of 1, making the new test flap in the flaky check. Pin join_algorithm='hash' at query level in those two EXPLAIN subqueries. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
@groeneai, the failure of the "distributed plan" is what we fixed in master. Please update the branch. |
…e-filter-dup-column-decorrelation
|
Branch updated: merged latest master (now includes the distributed-plan fix), head is now 8fdd52e. |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 19/19 (100.00%) · Uncovered code |
Picks up ClickHouse#109114 (merge 5e9c1f3, 2026-07-17), which owns the Stress test (amd_debug) 'Block structure mismatch in JoinStep' failure recorded on the previous head's CI ledger, and gets a current-base run.
…me-filter-dup-column-decorrelation Fix Block structure mismatch in JoinStep for decorrelated correlated subquery with duplicate column name
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a
Block structure mismatch in JoinSteplogical error (server abort in debug/sanitizer builds) when a correlated subquery is decorrelated into a join and the source relation carries a column name more than once, e.g.WITH t AS (SELECT number, * FROM numbers(3)) SELECT *, (SELECT t.number WHERE t.number >= 0) FROM twithcorrelated_subqueries_default_join_kind = 'right'.Description
Found by the AST fuzzer (
Stress test (amd_debug), STID 0993-386d, CI report). Also observed as 0993-308a on tsan and 2228-453d on ubsan.Closes: #109215
Reproducer:
Aborts with:
Root cause. The CTE
t = SELECT number, * FROM numbers(3)legitimately produces a relation whose header carries the column name__table3.numbertwice. The correlated scalar subquery is decorrelated into anANY RIGHT JOINover that relation. When join runtime filters are enabled (enable_join_runtime_filters = 1, the default),tryAddJoinRuntimeFilterbuilds a filter on the duplicated key column and inserts filter/key expressions addressed by column name. Because that machinery is name-keyed (findInOutputs,BuildRuntimeFilterStepon the key name, name-keyed permutations), it cannot represent the duplicated column: applying the filter changes the physical stream's column multiplicity so a downstream join step's declared header no longer matches its pipeline, trippingassertBlocksHaveEqualStructure. Plain right joins over such relations do not hit this because their surrounding plan does not contain the nested join whose declared header desyncs.Fix. Skip the runtime-filter optimization for a join whose input header contains a duplicate column name. A runtime filter is a pure optimization, so skipping it only forgoes the filter and never changes results. This mirrors the existing
JoinStepLogical::canRemoveUnusedColumns(), which likewise disables an optimization when a join condition input column is duplicated by name ("dealing with duplicate columns by name instead of positions ... breaks HashJoin"). Normal joins are unaffected: EXPLAIN still showsBuildRuntimeFilterfor joins without duplicated column names.Verified the added test
04493_correlated_subquery_join_runtime_filter_dup_columnfails (server abort) without the fix and passes with it, and that existing correlated-subquery tests continue to pass.Closes #109215
Version info
26.7.1.1061(included in26.7and later)