Dandandan opened a new pull request, #23202:
URL: https://github.com/apache/datafusion/pull/23202

   ## Rationale for this change
   
   When a sort exceeds `sort_in_place_threshold_bytes`, `ExternalSorter` sorts 
each buffered batch individually and merges them all. With many small input 
batches this gives a very high merge fan-in (hundreds/thousands of one-batch 
runs). For single-column sorts the per-stream cursor/merge overhead dominates, 
making this much slower than sorting a few larger runs.
   
   ## What changes are included in this PR?
   
   For **single-column** sorts, coalesce the buffered batches into a small 
number of larger runs (each bounded by `sort_in_place_threshold_bytes`, the 
same limit the in-place concat path already uses) before sorting and merging. 
Multi-column keys are left unchanged — their row-format merge of many small 
sorted runs beats a few large lexicographic sorts. Coalescing is disabled on 
the (memory-constrained) spill path.
   
   `benches/sort.rs`: single-column cases **1.4×–2.4× faster** (i64/f64 ~2×, 
utf8/utf8view ~1.6–1.9×, dictionary up to 2.4×) at 100k and 1M rows; 
multi-column cases unchanged.
   
   ## Are these changes tested?
   
   Yes — existing `sorts::` tests pass, plus a new 
`test_in_mem_sort_coalesced_runs` verifying the coalesced multi-run merge 
produces a correct total order (incl. NULLs).
   
   ## Are there any user-facing changes?
   
   No (internal performance change only).


-- 
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]

Reply via email to