Repository navigation
Keep the bucket-order promise of a shard aggregation in the Cascades optimizer - #119814
alexey-milovidov merged 8 commits into
Conversation
…optimizer A shard of a plain distributed query plans its aggregation to the `WithMergeableState` stage, and with `distributed_aggregation_memory_efficient` or `enable_memory_bound_merging_of_aggregation_results` that `AggregatingStep` promises the initiator's merge to deliver its two-level buckets in order. The initiator reads each shard as one stream. With `enable_cascades_optimizer` (the stress test turns it on) the Cascades `AggregationImplementation` rule offered the non-final aggregation only at the full node count, and the `DistributionEnforcer` gathered the instances straight into that stream. Each instance orders only its own share, so the initiator saw a bucket twice and failed with `Logical error: 'GroupingAggregatedTransform pushed bucket 3 twice'` (test 04878 under the stress runner's client options). Now a non-final aggregation that promises bucket order, and is not the partial half of a two-stage split, runs on a single node, and `TwoStageAggregationTransformation` splits such a step too, with a non-final merge that restores the bucket order over the gathered partials - the same demotion the rule-based rewrite got in #116446. The partial half of a split is marked on its `GroupExpression`, so it keeps its multi-node variants and is not split again. An aggregation in order stays on a single node, as in the rule-based planner. Test 05210 pins the plan shape and the results under the Cascades optimizer. Test 04878 reads the plan of the rule-based rewrite, so it now turns the Cascades optimizer off explicitly. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=64bddd33323e3583dec578d27135bbb6e5359675&name_0=MasterCI&name_1=Stress%20test%20%28arm_release%29 Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Workflow [PR], commit [bc3814d] Summary: ✅
AI ReviewSummaryThis PR teaches the Cascades distributed-aggregation rules to preserve the bucket-order contract for shard-side non-final aggregations, and it backs that up with focused stateless coverage for the affected setting combinations and execution modes. I re-checked the current diff against the existing review threads and the surrounding planner code, and I did not find a remaining correctness, safety, or evidence gap. Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit bc3814d.
Changed lines: Changed C/C++ lines covered: 44/44 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units30 translation units recompiled, 161 s compile time in total, 30 of them have a recent master baseline. |
The flaky check runs `nproc - 1` copies of a changed test at once with the thread fuzzer on, and each query here spawns nine server-side pipelines, so `max_threads = 16` reached 185s against the 180s per-test limit. Four threads still flush a producer's two-level states in parallel, and the producers the merge interleaves come from `distributed_plan_workers_num` regardless. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119814&sha=7b236cf379b03e629816446892c9d2fd401aab95&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20flaky%20check%29 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Algunenano
left a comment
There was a problem hiding this comment.
The explanation makes sense to me, but I think it's better if @davenger has a look at the recent changes including this PR
`split_for_bucket_order` already implied `!getFinal()`; scope it inside the non-final branch instead of repeating the condition. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…partial-aggregation-bucket-order
…partial-aggregation-bucket-order
|
🕵 Merged |
|
Could this PR get
No master run has hit it since this PR merged, and 26.10 already includes it. Cherry-picked onto the 26.9 tip |
|
Backporting to fix CI |
Backport #119814 to 26.9: Keep the bucket-order promise of a shard aggregation in the Cascades optimizer
…gregation in the Cascades optimizer
Related: #115986
Related: #116446
A shard of a plain distributed query plans its aggregation to the
WithMergeableStatestage, and withdistributed_aggregation_memory_efficientorenable_memory_bound_merging_of_aggregation_results(both on by default) thatAggregatingSteppromises the initiator's merge to deliver its two-level buckets in order. The initiator reads each shard as one stream. Withenable_cascades_optimizerthe CascadesAggregationImplementationrule offered the non-final aggregation only at the full node count, and theDistributionEnforcergathered the instances straight into that stream. Each instance orders only its own share, so the initiator saw a bucket twice and failed withLogical error: 'GroupingAggregatedTransform pushed bucket 3 twice'.The stress test runs its queries with
enable_cascades_optimizer = 1, which is how test 04878 (added by #116446 for the rule-based rewrite) hit this on master: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=64bddd33323e3583dec578d27135bbb6e5359675&name_0=MasterCI&name_1=Stress%20test%20%28arm_release%29Now a non-final aggregation that promises bucket order, and is not the partial half of a two-stage split, runs on a single node, and
TwoStageAggregationTransformationsplits such a step too, with a non-final merge that restores the bucket order over the gathered partials - the same demotion the rule-based rewrite got in #116446. The partial half of a split is marked on itsGroupExpression, so it keeps its multi-node variants and is not split again. An aggregation in order stays on a single node, as in the rule-based planner. A shard plan without the promise is unchanged.Test 05210 pins the plan shape and the results under the Cascades optimizer. Test 04878 reads the plan of the rule-based rewrite, so it now turns the Cascades optimizer off explicitly.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix the logical error
GroupingAggregatedTransform pushed bucket N twiceon the initiator of a distributed query whose shards planned their aggregation with the experimentalenable_cascades_optimizer: a shard's partial aggregation that must deliver its buckets in order no longer runs on several nodes gathered into one stream, it is split into a partial aggregation and a merge instead.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/119814]
Version info
26.10.1.650-master(included in26.10and later)26.9.26.29