Repository navigation
Conversation
…sed parallel replicas The trivial `GROUP BY ... LIMIT` optimization arms a kept-keys cutoff (`max_rows_to_group_by = LIMIT`, `ANY`, `shared_kept_keys_for_overflow_any`) when the aggregation does both stages, which a plan-based parallel-replicas query does at planning time. `ApplyParallelReplicasVisitor` later splits the `AggregatingStep` into a per-replica partial aggregation plus `MergingAggregated`, cloning the step with the cutoff. The local replica runs the unserialized clone and keeps at most `LIMIT` keys of its share, while the remote replicas get the serialized plan, where `serializeSettings` already writes `max_rows_to_group_by = 0`. The initiator then merges a truncated local state with full remote states, and a key the local replica dropped comes out with only the remote replicas' rows. Drop the cutoff from the partial step in the visitor, so every replica runs the exact partial aggregation the remote ones already run. The merge step keeps its params; its own cap is applied to keys it receives, so every key it outputs is exact. The serialized partial step is unchanged. The test needs a table of several coordinator segments (~10M rows): with one 128-mark segment the local replica reads everything and the result is exact. The `slowdown_parallel_replicas_local_plan_read` fail point makes the remote replicas take part, hence `no-parallel`. Closes ClickHouse#122607 Co-Authored-By: Claude Opus 5.5 <[email protected]>
`MergingAggregated` is created when `ApplyParallelReplicasVisitor` splits the aggregation, before `ConvertToDistributedVisitor` decides whether to build the parallel-replicas plan. If that conversion declines, the split stays a single-node pass-through and the test would return exact counts on any binary while the old shape check still printed 1. Also require `ReadFromParallelReplicas` in the plan, as `04409_pr_plan_based` and `04837_pr_plan_based_aggregation_in_order` do. 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; 2 rounds, 1 finding) plus my own cold reviews (nits only).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-11:20261015-213700 |
|
Workflow [PR], commit [fa609a4] Summary: ✅
AI ReviewSummaryThe PR fixes undercounted aggregates with Missing context / blind spots
Final Verdict✅ Approve |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261015-212300 |
|
cc @devcrafter @nickitat, could you review this? With |
CI finish ledger - 7f93060Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261016-060012 |
…keys-cutoff-122607 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units57 translation units recompiled, 663 s compile time in total, 57 of them have a recent master baseline. |
Closes: #122607
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
With
parallel_replicas_plan_based = 1,SELECT k, count() FROM t GROUP BY k LIMIT nno longer returns undercounted aggregates when the trivialGROUP BY ... LIMIToptimization uses its kept-keys cutoff.Description
With
parallel_replicas_plan_based = 1,SELECT k, count() FROM t GROUP BY k LIMIT ncould return too-small aggregates when the kept-keys cutoff of the trivialGROUP BY ... LIMIToptimization applies (LIMIT abovequery_plan_max_limit_for_top_k_optimization, or the top-K heap disabled). The cutoff with aggregate functions came in with #114690 (26.10); the setting is experimental, so no changelog entry.Root cause: the planner arms the cutoff because, at planning time, the aggregation sees every row.
ApplyParallelReplicasVisitorthen splits it into a per-replica partial aggregation plusMergingAggregated, cloning the step with the cutoff. The local replica runs the unserialized clone and keeps at mostnkeys of its share. The remote replicas get the serialized plan, whereAggregatingStep::serializeSettingsalready drops the cutoff. A key the local replica dropped comes out of the merge with only the remote replicas' rows.Change: the visitor drops the cutoff from the partial step it creates (
AggregatingStep::dropSharedKeptKeysCutoff), so every replica runs the same exact partial aggregation that the remote ones already run: the local replica now keeps every key of its share, as the remote ones do. The merge step is unchanged. The serialized plan is byte-identical to before.Validation: on master the new test fails 20/20 under random settings (local disk and s3). With the fix it passes 50/50, plus 40/40 with DBReplicated, 40/40 in the ParallelReplicas lane and 20/20 on s3. A 10M-row table is needed: below one 128-mark coordinator segment the local replica reads the whole table and the result is exact. The
slowdown_parallel_replicas_local_plan_readfail point (henceno-parallel) makes sure the remote replicas also get marks.Workflow [PR]
Sync PR [sync-upstream/pr/126139]