Skip to content

Fix/aggregate output ordering streaming#33

Merged
xudong963 merged 9 commits intobranch-51from
fix/aggregate-output-ordering-streaming
Mar 5, 2026
Merged

Fix/aggregate output ordering streaming#33
xudong963 merged 9 commits intobranch-51from
fix/aggregate-output-ordering-streaming

Conversation

@xudong963
Copy link
Collaborator

No description provided.

xudong963 and others added 5 commits March 3, 2026 10:33
…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>
@xudong963 xudong963 force-pushed the fix/aggregate-output-ordering-streaming branch from af6bd15 to e3c3667 Compare March 5, 2026 09:01
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]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@xudong963 xudong963 merged commit 3f7b02d into branch-51 Mar 5, 2026
58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant