Fix/aggregate output ordering streaming#33
Merged
Conversation
…preservation Two fixes for suboptimal blocking plans on GROUP BY ... ORDER BY ... LIMIT N over multi-partition data: 1. AggregateExec compute_properties: re-derive output ordering from input_order_mode using get_expr_properties (bottom-up monotonicity evaluation), since eq_properties.project() fails when leading ordering terms can't be projected through the group-by mapping. 2. EnforceDistribution: preserve SortPreservingMergeExec when it enables the parent to switch from blocking (Final emission) to streaming execution, even when order_preserving_variants_desirable is false. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
af6bd15 to
e3c3667
Compare
xudong963
commented
Mar 5, 2026
| 02)--TableScan: multiple_ordered_table_with_pk projection=[b, c, d] | ||
| physical_plan | ||
| 01)AggregateExec: mode=FinalPartitioned, gby=[c@0 as c, b@1 as b], aggr=[sum(multiple_ordered_table_with_pk.d)], ordering_mode=PartiallySorted([0]) | ||
| 02)--SortExec: expr=[c@0 ASC NULLS LAST], preserve_partitioning=[true] |
Collaborator
Author
There was a problem hiding this comment.
Old plan:
AggregateExec(Final, PartiallySorted([0])) ← requires input sorted by c
SortExec(c ASC) ← re-sort
CoalesceBatchesExec
RepartitionExec(Hash) ← destroys sort order
AggregateExec(Partial, PartiallySorted([0])) ← output sorted by c
New plan:
AggregateExec(Final, PartiallySorted([0])) ← requires input sorted by c
CoalesceBatchesExec
RepartitionExec(Hash, preserve_order=true) ← preserves sort order
AggregateExec(Partial, PartiallySorted([0])) ← output sorted by c
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.
No description provided.