Repository navigation
Conversation
The join order optimizer reconstructs join steps with JoinExpressionActions, which maps each input to a join side by name and requires the input count to equal the two sides' column counts. A JoinStepLogical whose expression DAG already contains two INPUT nodes with the same qualified name cannot be represented, and reconstruction aborted the server with a LOGICAL_ERROR (Input nodes size mismatch in dag) in debug/sanitizer builds. Such a step arises when a correlated scalar subquery referencing the same outer column twice is decorrelated. Detect duplicate-named inputs across the flattened join set up front and skip reordering, mirroring the existing overlapping-column-names guard. The unoptimized plan handles the query. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-1:20260716-143400 |
|
cc @vdimir @novikd — could you review? This skips join reordering when a JoinStepLogical's expression DAG already has two INPUT nodes with the same qualified name (from a correlated scalar subquery referencing the same outer column twice, e.g. |
|
Workflow [PR], commit [195032a] Summary: ✅
AI ReviewSummaryThis PR adds a pre-check in Missing context / blind spots
Final Verdict✅ No new findings. |
The duplicate-input pre-check gave both children join_steps_limit - 1, but buildQueryGraph flattens the left first and gives the right side only the leftover budget (join_steps_limit - lhs_count). The asymmetry let the check inspect, and disable reordering for, a right-side duplicate-input join the real reorder would never flatten, turning the guard into a false-positive optimization regression. Thread the relation count through the traversal and spend the budget left-first, matching buildQueryGraph and the sibling overlap guard (collectJoinGraphRelationHeadersForJoin), so the guard only fires for steps the real reorder would reconstruct. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ad8-join-reorder-duplicate-input
|
The amd_debug stress failure on 1e5cfb5 (STID 0993-386d, "Block structure mismatch in JoinStep: [__table3.number, __table3.number] and [__table3.number]") was not this PR's reorder path. The crash query is the first statement of 04493_correlated_subquery_join_runtime_filter_dup_column.sql, and the stack is JoinStep::updatePipeline -> checkBlockStructure with no buildQueryGraph/chooseJoinOrder frame: it is the runtime-filter duplicate-key crash already fixed on master by #109114 (joinRuntimeFilter.cpp guard + test 04493, merged 2026-07-14). This branch was 442 commits behind and predated that fix, so the stress build lacked it. Merged master (195032a) to pick up #109114. Verified on a debug build (Build ID F9C9CA7B): 04493, 04517, and 04327 all match their references; the three crash-query variants (right/left/double-star) return correct rows with no LOGICAL_ERROR. No source change in this PR beyond the merge. |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 46/47 (97.87%) · Uncovered code |
CI finish ledger — 195032aCI fully finished (aggregator complete, >20 min buffer). No failed checks on this commit — every job is pass or skipped.
Session id: cron:our-pr-ci-monitor:20260717-153000 |
|
Closing this: the defect it guards against was fixed upstream at its source, so the change here is now dead code and its regression test can no longer be satisfied. What changedCommit MeasurementsDebug build at this branch merged with master
Local sweeps cannot cover fuzzer mutations, which is where the original reports came from, so for that I used CIDB: Why not keep itBesides being unreachable, If the shape reappears on a build that does contain |
|
Superseded by the upstream fix in 8e93388 (PR 108289); details in the comment above. |
Related: #110227
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a
LOGICAL_ERROR(Input nodes size mismatch in dag) in the join order optimizer that could be triggered by a correlated scalar subquery referencing the same outer column more than once.Description
Chronic trunk
LOGICAL_ERRORsurfaced by the AST/BuzzHouse/stress fuzzers (STID 4752-5ad8), server abort in debug/sanitizer builds. 20 hits across 16 unrelated PRs in the last 30 days (0 on master). Reported on PR #108721 by @ alexey-milovidov.Report (Stress test, amd_msan):
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108721&sha=bfeef0e4f26d24a5c1eef3c7389d7b689c1a5ece&name_0=PR&name_1=Stress%20test%20%28amd_msan%29
Root cause: the join order optimizer reconstructs join steps with
JoinExpressionActions, whose 3-argument constructor maps every input to a join side by name and requires the input count to equal the two sides' column counts (JoinExpressionActions.cpp:124). AJoinStepLogicalwhose expression DAG already contains twoINPUTnodes with the same qualified name (e.g.__table3.numbertwice) cannot be represented, sochooseJoinOrder->optimizeJoinLogicalImpl->QueryPlan::optimizeaborted the server. Such a step arises when a correlated scalar subquery that references the same outer column twice (e.g.(SELECT number + number)) is decorrelated into a join.This is distinct from the cross-side overlap handled by #110227: there the two sides expose the same name (
Left and right columns have same names); here a single side's DAG carries a duplicateINPUTfor one name (size mismatch, one guard earlier). #110227 does not cover it (verified: the reproducer still aborts with #110227 applied).Fix: mirror the existing
joinGraphHasOverlappingColumnNamesguard. Before building the query graph (buildQueryGraphis destructive, so the check must be up front), walk the join steps the optimizer would flatten and skip reordering when any of them exposes duplicate-named inputs. The unoptimized plan handles the query. The guard is targeted: normal reorderable joins are unaffected.