Skip to content

Do not push a bucket while any input is still at it in GroupingAggregatedTransform - #115487

Merged
nihalzp merged 6 commits into
masterfrom
fix-bucket-pushed-twice-in-memory-efficient-merging
Aug 21, 2026
Merged

nihalzp merged 6 commits into
masterfrom
fix-bucket-pushed-twice-in-memory-efficient-merging

Conversation

@nickitat

@nickitat nickitat commented Aug 19, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix GroupingAggregatedTransform producing duplicate chunks for the same bucket.


Following up: #112794


Workflow [PR]
Sync PR [sync-upstream/pr/115487]

Version info

  • Backported to: 26.7.7.17, 26.6.4.62

nickitat and others added 4 commits August 19, 2026 15:11
`GroupingAggregatedTransform` pushes a delayed bucket as soon as no input
reports it as delayed any more and every input has read it. Reading it is
not enough: an input whose last chunk is of this bucket can send more
chunks of the same bucket, the producer converts the aggregation variants
of a bucket one by one. Those chunks arrive after the bucket is pushed,
they are put into `chunks_map` again, and the bucket is merged and pushed
a second time, which returns the keys of the bucket twice.

The in order push next to it never had this: it pushes the buckets before
`current_bucket`, and `current_bucket` only moves on when every input has
read a bucket after it. Require the same here, every input has to be
strictly past the bucket.

`Bucket N is pushed twice` fires in the builds with the assertions, and
the rows are silently duplicated in the release ones. Reproduced by
`04605_pr_plan_based_count_distinct_serialized` in the stress and in the
stateless runs with the distributed plan, where the merging of the plan
based parallel replicas became memory efficient.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BAZjq1jL3wNACqVQzocPoT
A delayed bucket has to be pushed once even when no input ever reads a
bucket after it, and a delayed bucket below the highest one still has to
be pushed before the inputs finish. The driver of the test is shared by
the cases now.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BAZjq1jL3wNACqVQzocPoT
Whatever the producers postpone and in whatever order their chunks
arrive, every bucket has to be pushed exactly once and the transform has
to finish. Being stricter about when a delayed bucket can be pushed may
only postpone a push: the in order push and the drain of the finished
inputs still take every bucket.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BAZjq1jL3wNACqVQzocPoT
@clickhouse-gh

clickhouse-gh Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b9f4b26]

Summary: ✅


AI Review

Summary

This PR tightens GroupingAggregatedTransform so a delayed bucket is released only after every live input has moved past it, and it adds focused regression coverage for the duplicate-push case plus the finished-input corner case. I reviewed the current diff and the existing review threads against the current code and did not find a remaining correctness issue to raise.

Final Verdict

✅ No new findings.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.90% 86.90% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 79.20% 79.20% +0.00%

Changed lines: Changed C/C++ lines covered: 181/184 (98.37%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 19, 2026
An input which has finished cannot send more chunks of a bucket, so it
does not have to be past the bucket for the bucket to be pushed. Taking
it into account kept a bucket until the end of the query when a source
ended right on it, although every input which can still send something
had moved past it. An input port reports itself finished only when it has
no data left on it, so nothing of the bucket is lost.

Reported by review of #115264.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BAZjq1jL3wNACqVQzocPoT
`GroupingAggregatedTransform::prepare` takes the ports whose edge has
changed, `ExecutingGraph::updateNode` collects them from the changed
edges alone. The driver of the test reported every input on every call,
so the transform saw a waiting port without data and dropped it from the
waiting set, although the real executor stays in `NeedData` until that
port really changes. The reproduction relied on that: it pushed the
bucket in a state which does not happen in a pipeline.

Report only the ports which were really given a chunk or finished. The
reproduction is a producer which postponed buckets 6 and 7 and resolves
them in order now, and never sends anything above 7, so `current_bucket`
stays behind the bucket which is pushed.

Reported by review of #115264.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BAZjq1jL3wNACqVQzocPoT
@clickhouse-gh

clickhouse-gh Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing b9f4b2625 with master f2f01c939 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 703.81 MiB 700.77 MiB -3.04 MiB (-0.43%)

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 units

13 translation units recompiled, 60 s compile time in total, 13 of them have a recent master baseline.

Job report

@nickitat
nickitat marked this pull request as ready for review August 20, 2026 11:20
@nickitat nickitat added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Aug 21, 2026
@nihalzp nihalzp self-assigned this Aug 21, 2026
@nihalzp
nihalzp added this pull request to the merge queue Aug 21, 2026
Merged via the queue into master with commit ef6a178 Aug 21, 2026
517 of 519 checks passed
@nihalzp
nihalzp deleted the fix-bucket-pushed-twice-in-memory-efficient-merging branch August 21, 2026 12:52
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Aug 21, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 21, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

@nickitat the 26.7 backport #115782 does not build. On its current head 3e222758 it fails
Build (amd_debug), Build (amd_tsan), Build (arm_darwin) and Build (amd_asan_ubsan) with:

src/Processors/tests/gtest_grouping_aggregated_transform_bucket_pushed_once.cpp:52:24: error: no matching constructor for initialization of 'Aggregator::Params'
src/Interpreters/Aggregator.h:177:9: note: candidate constructor not viable: requires 7 arguments, but 8 were provided

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115782&sha=3e222758ba6a455ca24fc5426268ec14cb299769&name_0=BackportPR&name_1=Build%20%28amd_asan_ubsan%29

26.7 has the 7 parameter short Aggregator::Params constructor; master and 26.8 have an 8 parameter
one whose extra argument is enable_packed_string_keys_, added by #112089. That PR is on 26.8 but not
on 26.7, 26.6 or 26.3.

Only the new gtest needs it: argument 8 at line 60, the file's only Aggregator::Params
construction. The two MergingAggregatedMemoryEfficientTransform hunks reference nothing 26.7 lacks
(num_inputs, last_bucket_number, index_to_input with the identical type,
forgetOutOfOrderBucketsOfInput, getDelayedBucketsBefore, chunks_map, pushData,
inputs_delayed_that_bucket, and the predicate the fix replaces), and
enable_producing_buckets_out_of_order_in_aggregation with out_of_order_buckets already exist
there. I also resolved every other type and member the 380 line test uses against 26.7; that one
argument is the only gap.

So dropping that argument on the backport branch is the small option. Labelling #112089
v26.7-must-backport is the other, but it is a 46 file pr-improvement that adds a user-facing
setting.

The 26.6 and 26.3 cherry-picks #115781 and #115779 are still unresolved and both branches carry the
7 parameter constructor, so they will fail the same way.

I do not hand-author or hand-resolve release-branch ports, so I am leaving this with you.

Copilot AI added a commit that referenced this pull request Aug 31, 2026
… code

The cherry-pick branch had master-only content (forgetOutOfOrderBucketsOfInput,
getDelayedBucketsBefore, pushed_buckets, out_of_order_buckets in ChunksToMerge, etc.)
that conflicts with the 26.6 backport branch. This commit brings the files to the
correct state: the backport branch version plus only the everyLiveInputIsPastBucket
fix from PR #115487.

Co-authored-by: nickitat <[email protected]>
Copilot AI added a commit that referenced this pull request Aug 31, 2026
The previous conflict resolution inadvertently introduced conflict markers
into unrelated files via a failed merge test. This commit:
- Restores all unrelated files to the cherry-pick branch state (no conflict markers)
- Keeps the correctly resolved cpp/h files: backport branch content + everyLiveInputIsPastBucket

The two source files now differ from the backport branch by exactly the
cherry-pick additions from PR #115487:
- everyLiveInputIsPastBucket function + updated condition in the cpp
- everyLiveInputIsPastBucket declaration in the h

Co-authored-by: nickitat <[email protected]>
nickitat added a commit that referenced this pull request Aug 31, 2026
Cherry pick #115487 to 26.6: Do not push a bucket while any input is still at it in `GroupingAggregatedTransform`
robot-clickhouse added a commit that referenced this pull request Aug 31, 2026
…ll at it in `GroupingAggregatedTransform`
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 31, 2026
clickhouse-gh Bot added a commit that referenced this pull request Aug 31, 2026
Backport #115487 to 26.6: Do not push a bucket while any input is still at it in `GroupingAggregatedTransform`
clickhouse-gh Bot added a commit that referenced this pull request Sep 3, 2026
Backport #115487 to 26.7: Do not push a bucket while any input is still at it in `GroupingAggregatedTransform`
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 4, 2026
…put is still at it in `GroupingAggregatedTransform`
@blau-ai blau-ai mentioned this pull request Oct 8, 2026
20 of 30 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants