perf: Optimize prefix-group processing in PartialSortExec - #24979
perf: Optimize prefix-group processing in PartialSortExec#24979lyne7-sc wants to merge 6 commits into
PartialSortExec#24979Conversation
PartialSortExec
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #24979 +/- ##
========================================
Coverage 81.91% 81.91%
========================================
Files 1134 1134
Lines 425631 425938 +307
Branches 425631 425938 +307
========================================
+ Hits 348647 348923 +276
- Misses 56304 56322 +18
- Partials 20680 20693 +13 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
kosiew
left a comment
There was a problem hiding this comment.
Thanks for working on this. The new prefix-group processing looks like a solid improvement, especially avoiding repeated concatenation for prefixes that span batches and limiting sorting work to the suffix keys.
I have one non-blocking suggestion around coverage for special prefix values. Otherwise, this looks good to me.
| evaluate_partition_ranges(batch.num_rows(), &common_prefix_sort_keys) | ||
| } | ||
|
|
||
| fn prefix_changed_at_batch_boundary( |
There was a problem hiding this comment.
Could we add a cross-batch regression test where the prefix key contains repeated NULL and NaN values, including nulls_first and descending sort options? It would be useful to compare the result against SortExec as well. prefix_changed_at_batch_boundary now determines boundary equality independently using make_comparator, while the in-batch groups come from evaluate_partition_ranges, so a test like this would help make sure both paths stay consistent for these special values.
There was a problem hiding this comment.
Thanks for the suggestion! Added a cross-batch test with repeated NULL and NaN prefixes, covering ascending/descending order and NULLS FIRST/LAST, and comparing the results against SortExec.
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