Repository navigation
Drop stale totals and extremes ports in MergingAggregatedStep - #114027
PedroTadim merged 7 commits into
Conversation
MergingAggregatedStep::transformPipeline inherited whatever totals and extremes ports the pipeline it was handed already had, and then attached its merging transforms to them. addMergingAggregatedMemoryEfficientTransform uses the StreamType-less Pipe::addSimpleTransform overload, so Pipe::addSimpleTransform applies the getter to totals_port and extremes_port as well as to the main ports. The resulting MergingAggregatedBucketTransform has an empty input header by construction, because it is designed to consume GroupingAggregatedTransform's empty, ChunksToMerge-bearing chunks. The totals port never passes through GroupingAggregatedTransform, so it still carries the real aggregate-state header and connect fails on the column count: Block structure mismatch in function connect between Limit and MergingAggregatedBucketTransform stream: different number of columns On the branches that do not attach that transform to the special ports, the stale port instead survives into TotalsHavingStep, which requires it to be null, giving "Totals having transform was already added to pipeline". Do what AggregatingStep, the other half of two-stage aggregation, already does at AggregatingStep.cpp:398-399: forget the current totals and extremes, since the step is about to invalidate them and TotalsHavingStep recalculates them afterwards. One call before the branch point covers the memory-efficient, memory-bound and non-memory-efficient branches, the extremes stream, and all five MergingAggregatedStep construction sites. The other caller of addMergingAggregatedMemoryEfficientTransform, the external-aggregation temp-file merge, builds its pipes from SourceFromNativeStream only, so both ports are null there and the drop is a no-op. Found by the AST fuzzer over a merge() spanning 58 tables. Reduced to three tables and a single SELECT; the plain SELECT fails too, so this is not limited to EXPLAIN. The only load-bearing setting of the fuzzer query is inject_random_order_for_select_without_order_by.
The first version of 04850 never reached the code path it exists for. Pipe::uniteTotals only builds its Concat -> LimitTransform pair when more than one pipe carries a totals port (Pipe.cpp:77-105), and a Distributed child planned at WithMergeableState carries none, so a fixture of one view plus one Distributed left a single port that uniteTotals returned unchanged. With one merge thread, addMergingAggregatedMemoryEfficientTransform also returns early via addTransform and never calls addSimpleTransform. The test therefore reddened on the sibling symptom, "Totals having transform was already added to pipeline", and never on the reported one. A second view child and several merge threads produce the reported message verbatim: Block structure mismatch in function connect between Limit and MergingAggregatedBucketTransform stream: different number of columns The build-time arms use EXPLAIN PIPELINE, which constructs the pipeline without running it. That is enough, because connect runs during construction, and it keeps the arms clear of two unrelated pre-existing runtime errors that this shape also trips. Each arm now asserts which merge branch it reached by naming the transform that identifies it, so a later plan change cannot move an arm onto a branch it does not mean to cover. The memory-bound and extremes arms are gone: instrumenting the step showed memoryBoundMergingWillBeUsed() and the extremes port are never reached in any shape that arrives with a totals port, so those arms asserted nothing while claiming coverage. Values are asserted separately, on a shape that needs no development-only setting, against a hand-derivable ground truth: three children of two rows give 90, and per key 30 and 60. The previous reference pinned 30, which was the output of an unrelated pre-existing defect where inject_random_order_for_select_without_order_by over merge() loses one child's rows. The equality oracle it came with compared two identically degraded executions and could not fail; it is replaced by literals plus a UNION ALL control that cannot share a Merge-specific degradation.
Both memory-efficient sub-branches construct MergingAggregatedBucketTransform, so filtering EXPLAIN PIPELINE on that name alone told them apart from nothing: the several-thread arm and the single-thread arm returned 1 for the same reason. A later plan change moving the several-thread arm onto the early-return path would have kept the test green while losing all coverage of the abort it exists to catch. The discriminator is the multiplicity suffix. getProcessorDescriptionLine appends " x N" when a group has more than one processor, and doDescribePipeline groups consecutive same-named processors, so the resize-then-addSimpleTransform path prints one transform per merge thread while the addTransform early return prints a bare one. Master already asserts this shape in 01551_mergetree_read_in_order_spread.reference. The several-thread arm now requires the exact count, which is pinned by aggregation_memory_efficient_merge_threads in the same query and therefore also confirms the resize honoured the setting; the single-thread arm requires the transform present and the suffix absent. Verified each predicate reddens on the mutation that matters: swapping either arm's merge_threads flips its flag. Two controls, because these oracles are count-shaped and a non-matching pattern yields a plausible zero rather than an error: the old substring predicate still returns 1 under the first mutation, and an ASCII x spelling of the sign matches nothing against output containing the real U+00D7. Co-Authored-By: Claude Fable 5 <[email protected]>
Internal second-model review (3 rounds, clean on round 3)An independent reviewer and a second model reviewed this change cold each round. Round 3 found ❌ Blockers: none.
💡 Noted, deliberately not addressed here Two pre-existing defects were found while reproducing this one, each proven independent by a shape Reachability, since it decides the changelog category: two Session id: cron:clickhouse-review-slot-9:20260809-100002 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20260809-094000 |
|
cc @davenger @nihalzp, could you review this? MergingAggregatedStep inherited the pipeline totals and extremes ports and then attached its merging transforms to them, and MergingAggregatedBucketTransform has an empty input header while those ports still carry the aggregate-state header, so connect failed on the column count. The fix drops those ports at the step that invalidates them, which is what the sibling AggregatingStep already does. |
|
Workflow [PR], commit [d5044f4] Summary: ❌
AI ReviewSummaryDrops inherited totals and extremes ports before Final Verdict✅ No review findings. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 5/5 (100.00%) · Uncovered code |
CI finish ledger — c2cf40aEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
None of these are caused by this PR: this PR only drops stale totals/extremes ports in Session id: cron:our-pr-ci-monitor:20260809-220000 |
…ted-totals-extremes-local
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units7 translation units recompiled, 11 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - 99c09b1Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
All three carry the identical check annotation, "The self-hosted runner lost communication with Two things I checked rather than assumed: The reporting half of this is already fixed and is working here. My merged #114921 is an The three reds are not the Negative control on the annotation: across 12 other recent Session id: cron:our-pr-ci-monitor:20260819-233000 |
…ted-totals-extremes-local
|
Fixing PR for the runner-reclaim mid- Scope note, because it matters for this head: that fix does not recover this run. The hourly The separate operational action here is a manual re-run of the three failed jobs. Two of them ( |
|
@nihalzp this PR is very small and seems ok to merge? |
…ted-totals-extremes-local
CI finish ledger - f929eb3Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Neither is a code failure on this diff, which is three lines in
One thing worth separating out, since it is not in the table: every non-green CIDB row at this The three reds I ledgered at the earlier head Session id: cron:our-pr-ci-monitor:20260820-233008 |
CI finish ledger d5044f4Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260825-170000 |
66b1132
retry_infra_failures.yml classifies each failed job as infrastructure-vs-real and re-runs the workflow when all of them are infrastructure. The classifier had no arm for a "Run" step whose conclusion is null, so it scored that job a real failure; because the run-level gate requires every verdict to be true, one such job suppressed the retry for the whole run. A null conclusion means GitHub finalized the job while its main step had never reported (completed_at is also null). That is the same "no verdict produced" class the adjacent length == 0 and "skipped" arms already treat as infrastructure. A test that actually ran and failed reports conclusion="failure" with both timestamps set, so this arm cannot absorb real failures. Found on ClickHouse#114027 head 99c09b1, where AST fuzzer (amd_debug, targeted, old_compatibility) was killed mid-Run on runner i-00c834ca4e798946f, with GitHub's "The self-hosted runner lost communication with the server" annotation. That job and two others reported failure having run zero tests and published zero CIDB rows. Why the runner went away is not established: the job logs are purged and its praktika report was never uploaded, so nothing here asserts a mechanism for the death. Validated against real captured job payloads, with the jq program extracted verbatim from the file in both arms so they cannot diverge by transcription. Run 32270257975 (171 jobs, captured paginated and asserted against total_count): verdicts false/true/true -> should_rerun=false before, and true/true/true -> should_rerun=true after, with the false attributable to exactly the killed job. Over 60 recent failed pull_request.yml runs (10264 jobs, 158 failed, 0 null-Run instances) classification is identical before and after, and a 17-case matrix across the whole step-conclusion domain changes exactly one case, the intended one; "cancelled" is deliberately left alone. The state is rare: zero occurrences in those 60 runs. This also does not recover the run that prompted it, which is attempt=3 while the workflow selects .attempt == 1 by design; widening that anti-loop bound is a separate question with a different risk profile. MAX_RERUNS, the attempt gate and the 6 hour cutoff are unchanged, as is the job filter feeding the classifier. Co-Authored-By: Claude Fable 5 <[email protected]>
Related: #113708
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Not required. The only shape found to reach this logical error needs
inject_random_order_for_select_without_order_by, documented as only useful for testing and development, so no released configuration is known to be affected. It is fuzzer-reachable (BuzzHouse randomizes it), which is how the abort was found.Description
Found 2026-08-08 by
AST fuzzer (amd_debug)(STID 0993-250f, report) on PR 112384 as a bystander:Logical error: Block structure mismatch in function connect between Limit and MergingAggregatedBucketTransform. It aborts inPort.cpp:22connectfromMergingAggregatedMemoryEfficientTransform.cpp:577, so at pipeline construction, not execution.MergingAggregatedStep::transformPipelineinherited the pipeline's totals and extremes ports, then attached its merging transforms to them.addMergingAggregatedMemoryEfficientTransformuses theStreamType-lessPipe::addSimpleTransformoverload, so the getter also runs ontotals_port. The transform it creates has an empty input header, while that port still carries the aggregate-state header, hence the mismatch. Where the transform is not attached to those ports, the stale port survives intoTotalsHavingStep, which requires it to be null.The fix mirrors
AggregatingStep.cpp:398-399, the other half of two-stage aggregation: drop the current totals and extremes, which this step invalidates and are recalculated afterwards. One call before the branch point covers all three merge branches, the extremes stream and all five construction sites. The other caller needs no drop: it builds pipes fromSourceFromNativeStream, so neither port exists.Reachability decides the category: two
Mergechildren must reach the step still carrying a totals port, and the setting named above is the only producer found among candidates measured with an instrumentedhasTotals. The guard is worth adding anyway, since the state is constructible today.The test asserts the build-time shapes and each arm's merge branch with
EXPLAIN PIPELINE, plus values against a hand-derivable ground truth.Two unrelated defects, identical on both sides of this change:
Chunk info was not set for chunk in GroupingAggregatedTransform, owned by #113266, and the same setting overmerge()loses a child's rows. An earlier revision of this line attributed the first toMaterializingTransformdropping chunk info; that is wrong, since it only callsdetachColumns/setColumnsand theISimpleTransformdefault swapschunk_infosthrough.Issue 113708 reports this guard firing over
merge()through a set-operation plan with noMergingAggregatedStep; that did not reproduce, so this PR does not close it.Workflow [PR]
Sync PR [sync-upstream/pr/114027]
Version info
26.9.1.145(included in26.9and later)