lyne7-sc opened a new pull request, #24979: URL: https://github.com/apache/datafusion/pull/24979
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes #. ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. Please explain the problem you are trying to solve in terms of the user-visible behavior, rather than the implementation. For example, "The code in `foo.rs` doesn't handle nulls" is a symptom of the implementation. "COUNT(DISTINCT) returns wrong results when the column contains nulls" is the user-visible problem. --> `PartialSortStream` concatenates 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? <!-- There is no need to duplicate the description in the issue here, but it is sometimes worth providing a summary of the individual changes in this PR. --> - Keep the unfinished trailing prefix as a list of `RecordBatch` slices instead of concatenating it with every incoming batch. - Detect completed prefix groups within each batch and compare prefix expression results directly across batch boundaries. - Sort completed groups only by the remaining suffix ordering. - Concatenate a single completed prefix at most once. - For multiple completed prefixes, evaluate suffix expressions once per source batch and materialize the final output with one interleave operation. - Preserve fetch handling, input release, empty-batch handling, and zero-column batch semantics. ## What is the testing strategy for this PR? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code Briefly describe how this PR is tested, and point to the specific tests you added. For example: 'This new feature is covered by the `sqllogictest` cases added in `foo.slt`'. If this PR does not add tests, explain why. For example, if the change is already covered by existing tests, please mention it. You should also check the `codecov` bot reply on this PR to confirm the changed code is exercised. --> The implementation is covered by the existing `PartialSortExec` unit tests and the additional SQL logic test cases in `group_by.slt`. ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. If there are any breaking changes to public APIs, please add the `api change` label. --> No. This is an internal performance improvement. ## Benchmark ``` group main optimized ----- ---- --------- partial_sort/rows_per_prefix/100 3.10 12.1±0.13ms ? ?/sec 1.00 3.9±0.05ms ? ?/sec partial_sort/rows_per_prefix/1000 4.17 13.2±0.07ms ? ?/sec 1.00 3.2±0.14ms ? ?/sec partial_sort/rows_per_prefix/10000 1.30 2.8±0.02ms ? ?/sec 1.00 2.1±0.07ms ? ?/sec partial_sort/rows_per_prefix/20000 1.41 3.0±0.22ms ? ?/sec 1.00 2.1±0.15ms ? ?/sec partial_sort/rows_per_prefix/5000 3.85 12.4±0.27ms ? ?/sec 1.00 3.2±0.03ms ? ?/sec partial_sort/rows_per_prefix/8192 1.56 2.8±0.05ms ? ?/sec 1.00 1780.8±34.70µs ? ?/sec ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
