Skip to content

Conversation

@haohuaijin
Copy link
Contributor

Which issue does this PR close?

close #19638

Rationale for this change

see issue #19638

What changes are included in this PR?

  1. Introduced LimitOptions struct limit field with both limit and optional descending ordering direction
  2. Extended TopKAggregation optimizer rule to DISTINCT queries by recognizing GROUP BY queries without aggregates and setting the descending flag based on ordering direction
  3. Enhanced GroupedTopKAggregateStream to handle DISTINCT by using group key as both priority queue key and value for DISTINCT operations
  4. Updated Proto definitions to add optional descending field to AggLimit message for serialization/deserialization

benchmark result

image

Are these changes tested?

yes, add test case in aggregates_topk.slt

Are there any user-facing changes?

no

@github-actions github-actions bot added logical-expr Logical plan and expressions optimizer Optimizer rules core Core DataFusion crate sqllogictest SQL Logic Tests (.slt) proto Related to proto crate physical-plan Changes to the physical-plan crate labels Jan 5, 2026
@github-actions github-actions bot removed the logical-expr Logical plan and expressions label Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate optimizer Optimizer rules physical-plan Changes to the physical-plan crate proto Related to proto crate sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support DISTINCT ORDER BY LIMIT query use GroupedTopKAggregateStream

1 participant