@@ -435,23 +435,12 @@ impl ExternalSorter {
435
435
// We'll gradually collect the sorted stream into self.in_mem_batches, or directly
436
436
// write sorted batches to disk when the memory is insufficient.
437
437
let mut spill_writer: Option < IPCWriter > = None ;
438
- // Leave at least 1/3 of spill reservation for sort/merge the next batch. Here the
439
- // 1/3 is simply an arbitrary chosen number.
440
- let sort_merge_minimum_overhead = self . sort_spill_reservation_bytes / 3 ;
441
438
while let Some ( batch) = sorted_stream. next ( ) . await {
442
439
let batch = batch?;
443
440
match & mut spill_writer {
444
441
None => {
445
442
let sorted_size = get_reserved_byte_for_record_batch ( & batch) ;
446
-
447
- // We reserve more memory to ensure that we'll have enough memory for
448
- // `SortPreservingMergeStream` after consuming this batch, otherwise we'll
449
- // start spilling everything to disk.
450
- if self
451
- . reservation
452
- . try_grow ( sorted_size + sort_merge_minimum_overhead)
453
- . is_err ( )
454
- {
443
+ if self . reservation . try_grow ( sorted_size) . is_err ( ) {
455
444
// Directly write in_mem_batches as well as all the remaining batches in
456
445
// sorted_stream to disk. Further batches fetched from `sorted_stream` will
457
446
// be handled by the `Some(writer)` matching arm.
@@ -469,9 +458,6 @@ impl ExternalSorter {
469
458
self . spills . push ( spill_file) ;
470
459
} else {
471
460
self . in_mem_batches . push ( batch) ;
472
-
473
- // Gives back memory for merging the next batch.
474
- self . reservation . shrink ( sort_merge_minimum_overhead) ;
475
461
}
476
462
}
477
463
Some ( writer) => {
0 commit comments