Commit 3f0b342
feat: Improve sort memory resilience (#19494)
## 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 #19493 .
## 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.
-->
Greatly reduces the memory requested by ExternalSorter to perform sorts,
adds much more granularity to the reservations, and Tries to do this
with minimal overhead by merging the splitting and sorting processes.
## 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.
-->
The sort stream will calculate the indices once, but the take will be
done in batches, so we create batch_size sized RecordBatches, whose
get_record_batch_size results return info that is very close to their
sliced sizes(if not completely the same), this means there is no need
for the precaution of reserving a huge amount of memory in order to do
the merge sort, meaning we can merge more streams at the same time, and
so on and so forth.
## Are these changes tested?
<!--
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
If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->
Yes
## 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.
-->
There is a new sort_batch_chunked function, which returns a Vec of
RecordBatch, based on the provided batch_size.
Some docs are updated.
---------
Co-authored-by: Raz Luvaton <[email protected]>1 parent 43567b4 commit 3f0b342
File tree
5 files changed
+586
-85
lines changed- datafusion/physical-plan/src
- aggregates
- sorts
- spill
5 files changed
+586
-85
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1198 | 1198 | | |
1199 | 1199 | | |
1200 | 1200 | | |
1201 | | - | |
| 1201 | + | |
1202 | 1202 | | |
1203 | 1203 | | |
1204 | 1204 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| |||
360 | 360 | | |
361 | 361 | | |
362 | 362 | | |
363 | | - | |
364 | | - | |
365 | | - | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
366 | 370 | | |
367 | 371 | | |
368 | 372 | | |
| |||
0 commit comments