perf: Optimize prefix-group processing in PartialSortExec - #24979
perf: Optimize prefix-group processing in PartialSortExec#24979lyne7-sc wants to merge 3 commits into
PartialSortExec#24979Conversation
PartialSortExec
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #24979 +/- ##
==========================================
+ Coverage 81.64% 81.67% +0.03%
==========================================
Files 1123 1126 +3
Lines 410248 414772 +4524
Branches 410248 414772 +4524
==========================================
+ Hits 334940 338770 +3830
- Misses 55617 56082 +465
- Partials 19691 19920 +229 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ryux1
left a comment
There was a problem hiding this comment.
Traced the stream state across continued prefixes, batch-boundary changes, multiple completed prefixes, end-of-input, and fetch exhaustion. The logical prefix offsets and batch-local fragment mapping are consistent; first-occurrence prefix order is preserved, suffix ordering is applied independently per completed group, and fetch is consumed across groups before the next poll closes/releases the input. The explicit zero-column materialization also preserves row counts. The added SQL cases cover the important cross-batch paths, and the reported CI matrix is green.
Which issue does this PR close?
Rationale for this change
PartialSortStreamconcatenates each incoming batch with the buffered incomplete prefix before looking for a completed prefix boundary.When one prefix spans multiple batches, this repeatedly copies rows accumulated from earlier batches. When a batch contains multiple completed prefix groups, the completed region is also sorted using the full ordering even though the prefix ordering is already satisfied.
This adds unnecessary copying and sorting work, especially for wide batches and workloads containing multiple prefix groups per batch.
What changes are included in this PR?
RecordBatchslices instead of concatenating it with every incoming batch.What is the testing strategy for this PR?
The implementation is covered by the existing
PartialSortExecunit tests and the additional SQL logic test cases ingroup_by.slt.Are there any user-facing changes?
No. This is an internal performance improvement.
Benchmark