Dandandan opened a new pull request, #21328: URL: https://github.com/apache/datafusion/pull/21328
## Which issue does this PR close? N/A - performance improvement ## Rationale for this change `SortPreservingMergeExec::execute()` eagerly executes all input partitions and spawns buffered tasks immediately, even before any batch is polled from the output stream. This wastes resources when streams are created but never consumed (e.g., query cancelled before first poll), and creates an unnecessary burst of concurrent tasks. ## What changes are included in this PR? Introduces a `LazySortPreservingMergeStream` that defers executing input partitions, spawning buffered tasks, and building the streaming merge until the first `poll_next()` call. The single-partition and zero-partition paths are unchanged. ## How are these changes tested? All existing tests pass (17/17), covering: - Multi-partition merge with various overlap patterns - Drop cancellation - Fetch limits - Congestion handling - Stable sort / round-robin tie breaking - Metrics 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
