Repository navigation
fix(agg): honor ordered percentile spill with allocation account - #29035
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
GPT-6 medium deep review at exact head f6f4737.
I reviewed all 7 changed files and the accounted ordered-percentile spill lifecycle.
- Installing an allocation account no longer disables terminal ordered-spill configuration. Accounted producers now use the same spill path while retaining the generic grouped-spill boundary.
- FlushWithContext handles cancellation before work, drains accounted state into ordered runs, and computes percentile ranks from spilled values without reconstructing all retained values at once. Resident and spilled paths share the same rank/interpolation logic for continuous and discrete percentiles, including Decimal128.
- Accounted scratch values and sort work are released on success, cancellation, allocation failure, and malformed state. Published run descriptors are preserved when a spill write/compaction fails, and compaction no longer destroys the existing run list before a replacement is ready.
- Merge, BatchMerge, PreflightBatchMerge, and SaveSpillIntermediateRows reject spilled ordered partials instead of serializing or combining an unsupported local-run state. The terminal MergeGroup handoff configures ordered spill only for the incoming H0 path.
- Tests cover resident/spilled equivalence, ascending/descending and endpoint percentiles, NULL/all-NULL input, allocation-accounted H0/H8/HStr merge modes, cancellation, allocation failure, failed compaction, and public BVT spill metrics.
Required CI is green, including Ubuntu UT/race, SCA, coverage, shared build, compose/standalone BVT, and CI Required. The PR is mergeable without conflict and only behind the base branch.
No evidence-backed P0/P1/P2 blocker found. Approving this exact head.
Merge Queue Status
This pull request spent 1 minute 47 seconds in the queue, with no time running CI. Waiting for any of
All conditions
ReasonPull request #29035 has been dequeued Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
HintYou should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it. Tick the box to put this pull request back in the merge queue (same as
|
…rixorigin#29035) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#28944 ## What this PR does / why we need it: Ordered-set percentile executors disabled their local spill configuration when Group installed an allocation account. Their spill watermark inspected only legacy vectors, while actual values lived in the accounted saved-argument arena. H0 also bypasses generic hash spill, so large percentile queries retained all inputs and materialized them again at Flush. This change preserves spill configuration and drains occupied accounted arenas into sorted local runs. Scratch remains allocation-accounted and is sorted in place. Shared resident arenas/counts are reset only after all groups have been written successfully; failed drains restore published run descriptors. Flush drains the tail and selects rank endpoints from the runs, preserving continuous interpolation, discrete ranks, direction, NULL handling and the existing floating-point total order. Local runs remain terminal state, not partial wire state. MergeGroup configures them for incoming H0 partials or the existing final grouped reload pass, not intermediate grouped destinations that may still enter generic hash spill. Defensive merge/serialization guards reject spilled partials. Existing percentile partial encoding is unchanged. Run compaction now leaves published descriptors intact on failed I/O. Validation on macOS arm64 / Go 1.26.5 with rebuilt native CGo dependencies: - Full `pkg/sql/colexec/aggexec` and `pkg/sql/colexec/group` unit suites passed, including accounted H0, grouped H8/HStr pressure, terminal hot-group reload, repeated drains/compaction, tail/NULLs, transport and lifecycle cleanup. - Failure/counterexample coverage includes create/write/read/cancellation failures, failed-drain retry without duplicate rows, failed compaction, scratch/reset allocation rejection, configuration order, FLOAT32/64 NaN ordering, Decimal128 interpolation, direction and endpoint controls. - New SQL BVT passed all 21 checks through mo-tester: low-threshold/resident result comparison, positive Explain spill rows/bytes, parallel input, DESC, endpoints and all-NULL input. - Original 10,000,000-row BIGINT reproduction passed on a fresh local 3-CN cluster with `agg_spill_mem=2097152`. The AP multicn plan returned `9500000.05 / 9500000` and reported Aggregate `MemorySize=4.52 MiB`, `SpillRows=20000000`, `SpillSize=152.59 MiB` (two aggregate executors). This is current-code local validation, not a rerun of the historical TKE environment or a cross-host timing benchmark. The spill setting triggers on occupied retained state; it is not a strict total-query memory ceiling. Arena allocation floors, one incoming work unit and sorting scratch can exceed the trigger. This bounds accumulated destination history but does not bound decoding an arbitrarily large incoming partial. External sorting adds disk I/O; distributed CI is pending. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…rixorigin#29035) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#28944 ## What this PR does / why we need it: Ordered-set percentile executors disabled their local spill configuration when Group installed an allocation account. Their spill watermark inspected only legacy vectors, while actual values lived in the accounted saved-argument arena. H0 also bypasses generic hash spill, so large percentile queries retained all inputs and materialized them again at Flush. This change preserves spill configuration and drains occupied accounted arenas into sorted local runs. Scratch remains allocation-accounted and is sorted in place. Shared resident arenas/counts are reset only after all groups have been written successfully; failed drains restore published run descriptors. Flush drains the tail and selects rank endpoints from the runs, preserving continuous interpolation, discrete ranks, direction, NULL handling and the existing floating-point total order. Local runs remain terminal state, not partial wire state. MergeGroup configures them for incoming H0 partials or the existing final grouped reload pass, not intermediate grouped destinations that may still enter generic hash spill. Defensive merge/serialization guards reject spilled partials. Existing percentile partial encoding is unchanged. Run compaction now leaves published descriptors intact on failed I/O. Validation on macOS arm64 / Go 1.26.5 with rebuilt native CGo dependencies: - Full `pkg/sql/colexec/aggexec` and `pkg/sql/colexec/group` unit suites passed, including accounted H0, grouped H8/HStr pressure, terminal hot-group reload, repeated drains/compaction, tail/NULLs, transport and lifecycle cleanup. - Failure/counterexample coverage includes create/write/read/cancellation failures, failed-drain retry without duplicate rows, failed compaction, scratch/reset allocation rejection, configuration order, FLOAT32/64 NaN ordering, Decimal128 interpolation, direction and endpoint controls. - New SQL BVT passed all 21 checks through mo-tester: low-threshold/resident result comparison, positive Explain spill rows/bytes, parallel input, DESC, endpoints and all-NULL input. - Original 10,000,000-row BIGINT reproduction passed on a fresh local 3-CN cluster with `agg_spill_mem=2097152`. The AP multicn plan returned `9500000.05 / 9500000` and reported Aggregate `MemorySize=4.52 MiB`, `SpillRows=20000000`, `SpillSize=152.59 MiB` (two aggregate executors). This is current-code local validation, not a rerun of the historical TKE environment or a cross-host timing benchmark. The spill setting triggers on occupied retained state; it is not a strict total-query memory ceiling. Arena allocation floors, one incoming work unit and sorting scratch can exceed the trigger. This bounds accumulated destination history but does not bound decoding an arbitrarily large incoming partial. External sorting adds disk I/O; distributed CI is pending. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #28944
What this PR does / why we need it:
Ordered-set percentile executors disabled their local spill configuration when Group installed an allocation account. Their spill watermark inspected only legacy vectors, while actual values lived in the accounted saved-argument arena. H0 also bypasses generic hash spill, so large percentile queries retained all inputs and materialized them again at Flush.
This change preserves spill configuration and drains occupied accounted arenas into sorted local runs. Scratch remains allocation-accounted and is sorted in place. Shared resident arenas/counts are reset only after all groups have been written successfully; failed drains restore published run descriptors. Flush drains the tail and selects rank endpoints from the runs, preserving continuous interpolation, discrete ranks, direction, NULL handling and the existing floating-point total order.
Local runs remain terminal state, not partial wire state. MergeGroup configures them for incoming H0 partials or the existing final grouped reload pass, not intermediate grouped destinations that may still enter generic hash spill. Defensive merge/serialization guards reject spilled partials. Existing percentile partial encoding is unchanged. Run compaction now leaves published descriptors intact on failed I/O.
Validation on macOS arm64 / Go 1.26.5 with rebuilt native CGo dependencies:
pkg/sql/colexec/aggexecandpkg/sql/colexec/groupunit suites passed, including accounted H0, grouped H8/HStr pressure, terminal hot-group reload, repeated drains/compaction, tail/NULLs, transport and lifecycle cleanup.agg_spill_mem=2097152. The AP multicn plan returned9500000.05 / 9500000and reported AggregateMemorySize=4.52 MiB,SpillRows=20000000,SpillSize=152.59 MiB(two aggregate executors). This is current-code local validation, not a rerun of the historical TKE environment or a cross-host timing benchmark.The spill setting triggers on occupied retained state; it is not a strict total-query memory ceiling. Arena allocation floors, one incoming work unit and sorting scratch can exceed the trigger. This bounds accumulated destination history but does not bound decoding an arbitrarily large incoming partial. External sorting adds disk I/O; distributed CI is pending.