alamb commented on code in PR #16319: URL: https://github.com/apache/datafusion/pull/16319#discussion_r2134861645
########## datafusion/physical-plan/src/sorts/sort.rs: ########## @@ -1126,14 +1127,20 @@ impl ExecutionPlan for SortExec { Ok(Box::pin(RecordBatchStreamAdapter::new( self.schema(), futures::stream::once(async move { - while let Some(batch) = input.next().await { - let batch = batch?; - topk.insert_batch(batch)?; - if topk.finished { - break; + // Spawn a task the first time the stream is polled for the sort phase. + // This ensures the consumer of the sort does not poll unnecessarily + // while the sort is ongoing Review Comment: I may not fully understand this change, but I believe it will start generating input as soon as `execute` is called, rather than waiting for the first poll... Another potential problem is that it will disconnect the production of batches from the consumption of them -- in other words by design I think it will potentially produce batches on a different thread than consumes them -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org