Repository navigation
Conversation
…keys Since ClickHouse#126249 a `max_rows_to_group_by` + `group_by_overflow_mode = 'any'` stream keeps the keys it admitted across external-aggregation spills: every flush captures them and `reseedKeptKeysAfterSpill` merges them back into the emptied table through `mergeOnBlock` with a cleared `no_more_keys`. `mergeOnBlock` then runs `checkLimits` on that cleared flag. Once the stream has crossed the limit the seed holds more than `max_rows_to_group_by` keys, so `checkLimits` takes the `any` branch again and increments `OverflowAny` once per spill; the flag it sets is discarded by the caller. Results are correct, only the profile event over-counts (`1 + number of spills`), which made `02385_profile_events_overflow` fail whenever the random settings drew `group_by_two_level_threshold_bytes = 1` and a small `max_bytes_before_external_group_by`. Before ClickHouse#126249 only the kept-keys cutoff of `GROUP BY ... LIMIT` re-seeded, with a seed of exactly `max_rows_to_group_by` keys, so the branch never fired there (the deleted `chassert(!reseed_no_more_keys)` encoded that). `kept_keys_rebuild_in_progress` already marks the merges that only put back keys the table held (the re-seed and `rebuildVariantsToKeptKeys`), and `mergeOnBlock` already skips the spill for them. It now also passes `checkLimits` an already-set local flag for them, which skips the overflow branch (the only place `OverflowAny` is counted) and keeps the memory check. Both setters run only in `any` mode, so no `throw`/`break` is skipped. The stream's own flag still decides admission. The `chassert` that the first rebuild merge leaves the flag clear is now true by construction; removed. Reverting ClickHouse#126249 would also stop the failure but brings back the wrong results it fixed. 05401_external_aggregation_overflow_any_keeps_kept_keys gets one more check: `OverflowAny` is 1 while the re-seed ran. It fails on master in 50/50 randomized runs (`3`) and passes with the fix. Related: ClickHouse#131789 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the mergeOnBlock checkLimits comment to one line; the field doc of kept_keys_rebuild_in_progress carries the reason. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-11:20261116-210100 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261116-194600 |
|
Workflow [PR], commit [55761f2] Summary: ❌
AI ReviewSummaryThe change prevents kept-key rebuilds and spill reseeds from counting Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units8 translation units recompiled, 94 s compile time in total, 8 of them have a recent master baseline. |
Related: #131789 (comment)
Related: #126249
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Description
02385_profile_events_overflowfails when the random settings drawgroup_by_two_level_threshold_bytes = 1and a smallmax_bytes_before_external_group_by:OverflowAnygrows by 3 instead of 1 (CI report). No issue is open for it.Since #126249, a
max_rows_to_group_by+group_by_overflow_mode = 'any'stream keeps its admitted keys across external-aggregation spills: after each flushreseedKeptKeysAfterSpillmerges them back throughmergeOnBlockwith a clearedno_more_keys. Once the stream has crossed the limit, the seed holds more thanmax_rows_to_group_bykeys, socheckLimitstakes theanybranch again and countsOverflowAnyonce per spill. The results are correct; only the profile event over-counts. Master only, not in any release.mergeOnBlockalready recognizes these merges bykept_keys_rebuild_in_progress(set by the re-seed and by the kept-keys rebuild ofGROUP BY ... LIMIT) and skips the spill for them. It now also givescheckLimitsan already-set flag for them, so the overflow branch is skipped and the memory check still runs. Admission is still decided by the stream's own flag. ThechassertinrebuildVariantsToKeptKeysthat this flag stays clear is now always true and is removed.Validation:
05401_external_aggregation_overflow_any_keeps_kept_keysgets one more check (OverflowAnyis 1 and the re-seed ran): 50/50 runs fail on master with3, 50/50 pass with the fix.02385with the CI settings forced: 20/20 fail on master, 20/20 pass with the fix.Reverting #126249 would also stop the failure, but would bring back the wrong results it fixed. The draft #129750 removes the re-seed altogether; this change keeps the counter right until then.
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/132141]