Repository navigation
Serialize the GROUP BY top-K parameters in the query plan - #116163
Conversation
`AggregatingStep::serialize` did not carry `params.top_k`, so the optimization was gated off entirely under `serialize_query_plan`: the plan-level pass and the shard-side Planner hook both bailed, and the followers aggregated without the heap. Carry the parameters in the `Aggregating` step payload under a new flag bit, gated on query plan serialization version 10 (`DBMS_MIN_QUERY_PLAN_SERIALIZATION_VERSION_WITH_GROUP_BY_TOP_K`). Towards an older peer the parameters are omitted rather than rejected: the peer aggregates without the heap and returns partial states for all its groups, which the initiator's merge, sort and limit handle correctly - the safe direction. The deserializer validates the payload (`k` within the cap, key coverage, directions). Remove the `serialize_query_plan` gates from `tryOptimizeGroupByTopK` and `applyTopKPushdownToPartialAggregation`. The shipped plan is a fresh Planner product built at `WithMergeableState` (`createRemotePlanForParallelReplicas`, `createLocalPlan` for `Distributed`), so the hook annotates it and serialization delivers it to the followers. Followers re-optimize deserialized plans, so the plan-level pass now also rejects non-final aggregation explicitly: synthesizing a sort over partial states would truncate each follower's group set independently, with no initiator-side sort to discard the resulting incomplete groups. Integration coverage: new `test_remote_partial_aggregation_serialized_heap_engaged` proves via `AggregationTopKRowsSkipped` on the secondary queries that the heap runs on the followers under `serialize_query_plan = 1`; the EXPLAIN expectations now require the `Top-K` annotation whenever the optimization is on, regardless of `serialize_query_plan`. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [681c8f3] Summary: ✅
AI ReviewSummaryThis PR serializes the Findings
Final Verdict
LLVM Coverage ReportMeasured on commit 681c8f3.
Changed lines: Changed C/C++ lines covered: 72/77 (93.51%) · Uncovered code |
Build profile diff (arm_release)Commit See the job log for details. |
|
I want to review this PR. |
Master moved to per-step serialization versions (#119535) and documented that a change to a step's bytes must bump the step's own version rather than the global `DBMS_QUERY_PLAN_SERIALIZATION_VERSION` (#123241). Flag bit 128 of `AggregatingStep` is now taken by `only_merge`. Resolve accordingly: drop the global version bump and the bit-128 top-K flag, and carry the top-K parameters as a trailing presence byte plus payload in version 1 of the `Aggregating` step, introduced at plan version 20 (the 26.10 value). Towards a peer that reads step version 0 the parameters are omitted, as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ry_plan` `preferGroupByTopKOverKeptKeysCutoff`, added on master, refused the heap under `serialize_query_plan` because the heap used to be disabled for a serialized plan. This PR lifts that restriction (`AggregatingStep` carries the top-K parameters since `Aggregating` step version 1), so the gate would now arm the kept-keys cutoff and take the heap away from a query it applies to. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…trip gtest Cover `serialize -> deserialize -> serialize` of the `GROUP BY` top-K parameters for a multi-key mixed-direction case and a prefix-of-keys case, the omission of the parameters towards a peer below `DBMS_MIN_QUERY_PLAN_SERIALIZATION_VERSION_WITH_GROUP_BY_TOP_K`, and the rejection of more ranked columns than `GROUP BY` keys. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: The other failures on 9aaa67f are unrelated to this PR and already handled. The |
|
The fix is in progress: #123790 (it includes the change from my #123774, closed in its favor). In its own run on The failing run on |
Related: #96630
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Allow using fused
GROUP BYtop-K with serialized query plan.Workflow [PR]
Sync PR [sync-upstream/pr/116163]
Version info
26.10.1.1645-master(included in26.10and later)