Skip to content

Commit 41e7378

Browse files
authored
minor: SortExec measure elapsed_compute time when sorting (#12099)
* minor: SortExec measure elapsed_compute time when sorting Whilst investigating query execution performance I noticed that some SortExec nodes were reporting suspiciously short elapsed_compute times. It appears that the SortExec node wasn't running the elapsed_compute timer when it doing the actual sorting operation. * fix: apply review suggestions
1 parent 502ce4b commit 41e7378

File tree

1 file changed

+8
-0
lines changed
  • datafusion/physical-plan/src/sorts

1 file changed

+8
-0
lines changed

datafusion/physical-plan/src/sorts/sort.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,12 @@ impl ExternalSorter {
499499
metrics: BaselineMetrics,
500500
) -> Result<SendableRecordBatchStream> {
501501
assert_ne!(self.in_mem_batches.len(), 0);
502+
503+
// The elapsed compute timer is updated when the value is dropped.
504+
// There is no need for an explicit call to drop.
505+
let elapsed_compute = metrics.elapsed_compute().clone();
506+
let _timer = elapsed_compute.timer();
507+
502508
if self.in_mem_batches.len() == 1 {
503509
let batch = self.in_mem_batches.remove(0);
504510
let reservation = self.reservation.take();
@@ -552,7 +558,9 @@ impl ExternalSorter {
552558
let fetch = self.fetch;
553559
let expressions = Arc::clone(&self.expr);
554560
let stream = futures::stream::once(futures::future::lazy(move |_| {
561+
let timer = metrics.elapsed_compute().timer();
555562
let sorted = sort_batch(&batch, &expressions, fetch)?;
563+
timer.done();
556564
metrics.record_output(sorted.num_rows());
557565
drop(batch);
558566
drop(reservation);

0 commit comments

Comments
 (0)