feat: add spill-backed sorting and aggregation#377
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #377 +/- ##
==========================================
+ Coverage 92.85% 92.91% +0.05%
==========================================
Files 249 253 +4
Lines 41844 43141 +1297
==========================================
+ Hits 38856 40084 +1228
- Misses 2988 3057 +69
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 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.
What problem does this PR solve?
Sort and aggregation currently need to keep their working rows in memory, and equi-join implementation selection always prefers HashJoin. This makes large
ORDER BY,GROUP BY, andDISTINCTworkloads more memory-sensitive, and leaves no SQL-level escape hatch for forcing a bounded-memory aggregate or nested-loop join plan.Issue link: N/A
What is changed and how it works?
spillfeature with a spill-file backedSpillVecand codec support for temporary executor rows.ExternalSortwhen thespillfeature is enabled, including sorted segments and merge passes.StreamAggregateand generalizes ordered-input optimization soDISTINCTand grouped aggregation can reuse existing ordering.FORCE_AGG_SPILLoptimizer hint, routing grouped aggregates and distinct aggregates through ordered stream execution and inserting a Sort only when the input is not already ordered.FORCE_NEST_LOOP_JOINoptimizer hint to override equi-join HashJoin selection when needed.Code changes
Check List
Tests
The coverage includes
SpillVecand codec behavior, external sort segment/merge correctness, stream aggregate and distinct planning/results, forced aggregate spill planning/results, and forced nested-loop join Explain coverage.Side effects
Note for reviewer
The spill-backed sort path is gated by the
spillfeature and remains unavailable for wasm.FORCE_AGG_SPILLfirst reuses existing ordered input when possible, so it only adds an explicit Sort for unordered aggregate inputs.