brancz opened a new pull request, #27724: URL: https://github.com/apache/datafusion/pull/27724
## 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. --> - Extension to #26940. ## Rationale for this change ## Rationale for this change When a sort runs out of memory, it spills its buffered batches to disk. Before writing anything, the spill merges all buffered sorted runs into one file, and the row-format merge converts the sort keys of every run's first batch at once. Dictionary keys, including run-end-encoded and struct-wrapped ones, are decoded into their values in the row format, so these keys can be many times larger than the buffered data. The spill then fails with `ResourcesExhausted` before it has released any input, so a sort that should spill fails instead. #27043 avoided the merge for selected spills by predicting which keys might expand. Predictions miss some cases, such as nested dictionaries, and also catch cases that would have fit, such as short strings or low-expansion dictionaries. Those spills then pay for extra spill files, extra disk usage and lost parallel preparation. ## What changes are included in this PR? Convert the keys of each run's first batch one run at a time instead. When the pool refuses a run, merge and spill the runs added so far, which releases their memory, then continue with the refused run. A run whose keys do not fit alone is spilled unmerged. When all keys fit, the spill writes one file as before, so sorts that succeeded on main write the same spill files. ## What is the testing strategy for this PR? Unit tests. ## Are there any user-facing changes? No, just enhanced spill behavior. @alamb @kosiew -- 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]
