Repository navigation
Sort pushdown: let an Exact answer split into more partitions - #27987
Draft
zhuqi-lucas wants to merge 1 commit into
Draft
zhuqi-lucas wants to merge 1 commit into
zhuqi-lucas wants to merge 1 commit into
Conversation
A source that can only serve an ordering by splitting into more sorted partitions may now answer Exact with more partitions. PushdownSort turns a single-partition sort above it into a SortPreservingMergeExec with the sort's fetch, sharing the buffer budget across the partitions. A per-partition sort, or an Inexact answer that changes the partitioning, is left alone.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
A source can sometimes satisfy an ordering only by splitting into more partitions, for example one file per partition when the files of a group are each sorted but overlap. Today
try_pushdown_sorthas no way to say that: in the standaloneSortExecpath,PushdownSortremoves the sort onExactwithout checking the partition count, so a source that split would leave several sorted streams with no merge above them.What changes are included in this PR?
Steps 1 and 2 of the issue:
try_pushdown_sortcontract now allows anExactanswer with more partitions than the node it replaces, as long as every partition is in the requested order. AnInexactanswer must keep the partitioning.SortExecpath, when anExactanswer has a different partition count:SortPreservingMergeExecwith the sort's fetch, over aBufferExec, with the fetch also pushed into every partition;preserve_partitioningis left alone, since its parent relies on the partitioning.Inexactanswer that changes the partition count is ignored.For example, a single-partition scan that splits into three sorted partitions:
becomes
The
BufferExechere sharessort_pushdown_buffer_capacityacross the partitions instead of giving each partition all of it. The source picks the partition count, which can be large, and when the partitions don't overlap, every partition after the one being merged keeps reading until its buffer is full. Each partition still buffers at least one batch.Step 3, letting
FileScanConfigsplit overlapping groups itself, is left for a follow-up.What is the testing strategy for this PR?
Five plan tests in
pushdown_sort.rs, using aTestScanoption that splits into more partitions on pushdown:Exactwith more partitions under a single-partition sort, with and without a fetch: the sort becomes a merge.Exactwith more partitions under a per-partition sort with a merge above: the existing merge pattern handles it.Exactwith more partitions under a per-partition sort without a merge: unchanged.Inexactwith more partitions: unchanged.Without the change, four of them fail.
Are there any user-facing changes?
The
try_pushdown_sortdocs now allowExactwith more partitions. No API changes; existing sources keep their behavior.