Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions datafusion/physical-plan/src/sorts/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,18 +223,16 @@ impl<C: CursorValues> SortPreservingMergeStream<C> {

assert_eq!(uninitiated_partitions.len(), 0);

let elapsed_compute = self.metrics.elapsed_compute().clone();
let mut timer = elapsed_compute.timer();

// If there are no more uninitiated partitions, set up the loser tree and continue
// to the next phase.

// Claim the memory for the uninitiated partitions
drop(uninitiated_partitions);
self.init_loser_tree();

// NB timer records time taken on drop, so there are no
// calls to `timer.done()` below.
let elapsed_compute = self.metrics.elapsed_compute().clone();
let mut timer = elapsed_compute.timer();

loop {
let stream_idx = self.loser_tree[0];
if !self.advance_cursors(stream_idx) {
Expand Down Expand Up @@ -269,8 +267,6 @@ impl<C: CursorValues> SortPreservingMergeStream<C> {
self.update_loser_tree();
}

drop(timer);

// When `build_record_batch()` hits an i32 offset overflow (e.g.
// combined string offsets exceed 2 GB), it emits a partial batch
// and keeps the remaining rows in `self.in_progress.indices`.
Expand All @@ -279,7 +275,9 @@ impl<C: CursorValues> SortPreservingMergeStream<C> {
// Repeated overflows are fine — each poll emits another partial
// batch until `in_progress` is fully drained.
while let Some(batch) = self.emit_in_progress_batch()? {
drop(timer);
emitter.emit(batch).await;
timer = elapsed_compute.timer();
}
Ok(())
})
Expand Down
Loading