Defer task spawning in SortPreservingMergeExec to first poll
- Dominant language
- Rust
- Stars
- 9.3k
- Forks
- 2.4k
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 344
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_
Contributor guide
Research direction
Start at SortPreservingMergeExec::execute and trace how input partition tasks and the streaming merge are created before the output stream is polled. Verify the zero- and single-partition fast paths, then confirm that multi-partition work and merge construction begin on the first poll_next call and not before.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- data-engineering
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100