-
Notifications
You must be signed in to change notification settings - Fork 2k
Defer task spawning in SortPreservingMergeExec to first poll #21329
Description
Is your feature request related to a problem or challenge?
SortPreservingMergeExec::execute() eagerly calls execute() on all input partitions and spawns buffered tasks immediately, before the output stream is ever polled. This means resources are allocated and work
begins even if the stream is never consumed (e.g. query cancelled before first poll), and creates an unnecessary burst of concurrent tasks when many SortPreservingMergeExec nodes exist in a plan.
Describe the solution you'd like
Defer the spawning of input partition tasks and construction of the streaming merge to the first poll_next() call on the output stream, rather than doing it eagerly in execute(). This can be done with a
wrapper stream that holds the initialization state and transitions from Pending to Running on first poll. The single-partition and zero-partition fast paths can remain unchanged.
Describe alternatives you've considered
No response
Additional context
No response