refactor(hash-aggr): Support spilling for ordered aggregation#23657
Open
2010YOUY01 wants to merge 4 commits into
Open
refactor(hash-aggr): Support spilling for ordered aggregation#236572010YOUY01 wants to merge 4 commits into
2010YOUY01 wants to merge 4 commits into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #23657 +/- ##
==========================================
- Coverage 80.66% 80.66% -0.01%
==========================================
Files 1086 1086
Lines 366673 367100 +427
Branches 366673 367100 +427
==========================================
+ Hits 295786 296119 +333
- Misses 53263 53333 +70
- Partials 17624 17648 +24 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Part of #22710
Rationale for this change
This PR implements larger-than-memory execution for ordered partial and ordered final aggregation. These two modes are implemented first because:
The high-level plan for two-stage ordered hash aggregation is:
Group keys are fully ordered (input ordered by
a, b; query usesGROUP BY a, b)Execution must use bounded memory because only one group is active at any given time. Therefore, the implementation simply returns an execution error if a memory reservation fails.
Group keys are partially ordered (input ordered by
a; query usesGROUP BY a, b)At any given time, we must hold all groups for a particular value of
ain memory, so it is possible to run out of memory. This is handled as follows:If the partial aggregate runs out of memory, it directly materializes the accumulated groups as aggregate states and emits them early to the final stage.
The final aggregate continues aggregating until its memory budget is reached, then:
OrderedFinalAggregateStreamusing the sort-preserving merge stream as its input. The new stream's group keys are fully ordered, whereas those of the original stream were only partially ordered. It then evaluates this ordered stream to produce the final result.Design Tradeoffs
Note that the same implementation is currently shared by two execution paths, controlled by flags: aggregation with fully ordered group keys and aggregation with partially ordered group keys. This is not an ideal pattern. However:
What changes are included in this PR?
The core changes are in
ordered_partial_stream.rsandordered_final_stream.rs, for the above algorithm. See code comments for implementation details.Are these changes tested?
After implementing this change, I checked the coverage using
cargo llvm-covand found that this feature was supported by the original implementation but was not covered by either regular tests or fuzz tests. This is a bit of a horror story.I think the old implementation is heavily multiplexed, so its overall line coverage is probably good. However, spilling for ordered aggregation follows a specific execution path that was never exercised.
Therefore, this PR adds
slttest coverage. I also think we need more fuzzing cases (filed #23658)Are there any user-facing changes?