Repository navigation
Do not narrow a pipe that contains a fan-out which must push to all of its outputs - #121227
Conversation
…f its outputs narrowPipe glues independent streams behind a ConcatProcessor to keep the number of open sources down. A ConcatProcessor demands its inputs strictly one at a time: it calls setNeeded() on the current input only, and advances when that input finishes. A ScatterByPartitionTransform has the opposite requirement: pushOutputChunks() leaves all_outputs_processed false for any non-finished output with a non-empty share whose canPush() is false, and prepare() then returns PortFull, so the scatter cannot take its next chunk until every output has accepted a share of the current one. Put one above the other and they deadlock. The lanes feeding the Concat's later inputs are never demanded, so their prepare() is never called at all (state NotStarted); the scatter cannot push those shares and parks in PortFull, where it can neither pull nor finish; so the lane the Concat is waiting on never finishes either, and the Concat never advances to the next input. PipelineExecutor::finalizeExecution then throws Pipeline stuck. This is reachable without any unusual setting beyond the join algorithm: ReadFromMerge::readFromMerge narrows the streams of the tables it reads, so a Merge table or merge() over a view whose body contains a sharded merge join hits it, and max_streams_for_union_step reaches it through UnionStep. A window function with PARTITION BY builds the same fan-out, though the Resize the window step places above it keeps that path awake in practice. Decline to narrow such a pipe. narrowPipe returns early when any processor in the pipe answers the new IProcessor::requiresAllOutputsPushable(), overridden by the three processors carrying that contract: ScatterByPartitionTransform, CopyTransform (the GROUPING SETS copier, with byte-identical accounting in prepareGenerate) and ForkProcessor (identical accounting, no users today, so the override states the contract). ResizeProcessor moves data between any ready pair and has no such contract. Narrowing is a memory and file-handle optimization, never a correctness requirement, and both call sites already suppress it conditionally (should_not_narrow in StorageMerge, allow_narrowing in UnionStep), so this is a third reason in the shape the code already has; the pipeline simply stays wide, which is what the same query already gets when either existing suppression fires. Buffering the un-pushable shares inside the scatter was rejected as unbounded memory, the design already refused for the BufferedShardByHashTransform family; making Concat demand all of its inputs would delete the optimization it exists for. The comment in optimizeJoinByShards that excluded the full-sort path from this deadlock class is corrected: the drain it relies on only helps a lane that some consumer has already demanded. Found by CI on ClickHouse#121125, Stress test (amd_debug) at commit d8d2fdd. Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 gate finding plus 5 from my own
Also checked and clean: both Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20260920-180109 |
Pre-PR validation (a-i)
Also: the original CI statement and the |
|
Workflow [PR], commit [c5fafe0] Summary: ✅
AI ReviewSummaryThis PR teaches Final Verdict✅ No findings. LLVM Coverage ReportMeasured on commit c5fafe0.
Changed lines: Changed C/C++ lines covered: 12/14 (85.71%) · Uncovered code |
CI finish ledger - dffd2c7Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Measured on this head: 176 contexts, 156 SUCCESS / 18 SKIPPED / 2 FAILURE, and CIDB records Session id: cron:our-pr-ci-monitor:20260921-050309 |
e1a19d4
Related: #121125
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a
Pipeline stucklogical error when a query combined a merge join usingjoin_algorithm = 'parallel_full_sorting_merge'with a step that glues independent streams together, such as reading from aMergetable, or aUNION ALLnarrowed bymax_streams_for_union_step. Such a query now runs instead of failing.Description
narrowPipeglues independent streams behind aConcatProcessorto keep the number of open sources down, and thatConcatdemands its inputs one at a time: only the current input is marked needed, advancing when that one finishes. AScatterByPartitionTransformhas the opposite requirement: it cannot take its next chunk until every output has accepted a share of the current one.Put one above the other and they deadlock. The lanes feeding the
Concat's later inputs are never demanded, so the scatter cannot hand over those shares and parks inPortFull, where it can neither pull nor finish; the lane theConcatis waiting on is fed by the same scatter, so it never finishes either.PipelineExecutorthen throwsPipeline stuckfor a valid query, aborting a debug or sanitizer build.ReadFromMergenarrows its streams, so aMergetable ormerge()over a view whose body holds a sharded join reaches this with no unusual setting;max_streams_for_union_stepreaches it throughUnionStep.narrowPipenow returns early when any processor in the pipe answers a newIProcessor::requiresAllOutputsPushable(), overridden by the three processors carrying that contract:ScatterByPartitionTransform,CopyTransformandForkProcessor.The guard is per pipe, not per port, so a pipe holding such a fan-out is left wide even where the fan-out sits under a
ResizeProcessorand could not wedge. Separating those cases would turnResizeProcessordemanding all of its inputs into a deadlock-safety guarantee instead of an implementation detail. Narrowing bounds open sources and memory and is never a correctness requirement; both call sites already suppress it conditionally.The new test aborts 10/10 without the fix and passes 10/10 with it, reverting only the guard returns it to red, and a negative control asserts a pipe with no fan-out is still narrowed.
Found by CI on #121125,
Stress test (amd_debug)@d8d2fdd31141bcfecd558d690da6d35f21c98c31.Workflow [PR]
Sync PR [sync-upstream/pr/121227]
Version info
26.10.1.1113-master(included in26.10and later)