Skip to content

Defer task spawning in SortPreservingMergeExec to first poll #21329

@Dandandan

Description

@Dandandan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions