-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat: support SELECT DISTINCT id FROM t ORDER BY id LIMIT n query use GroupedTopKAggregateStream
#19653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
… GroupedTopKAggregateStream
| let mut cols = self.priority_map.emit()?; | ||
| // For DISTINCT case (no aggregate expressions), only use the group key column | ||
| // since the schema only has one field and key/value are the same | ||
| if self.aggregate_arguments.is_empty() { | ||
| cols.truncate(1); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can further improve this part, because for the query
select distinct id from t order by id limit 10it do not have any aggregate, so we only need mantain the topk heap, and skip the group keys
kosiew
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
| let batches = collect(plan, ctx.task_ctx()).await?; | ||
| assert_eq!(batches.len(), 1); | ||
| let batch = batches.first().unwrap(); | ||
| assert_eq!(batch.num_rows(), 10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LIMIT
instead of
10
|
Thanks for your reviews @kosiew, already apply suggestion |
Which issue does this PR close?
close #19638
Rationale for this change
see issue #19638
What changes are included in this PR?
LimitOptionsstruct limit field with bothlimitand optionaldescendingordering directionTopKAggregationoptimizer rule to DISTINCT queries by recognizingGROUP BYqueries without aggregates and setting thedescendingflag based on ordering directionGroupedTopKAggregateStreamto handle DISTINCT by using group key as both priority queue key and value for DISTINCT operationsdescendingfield toAggLimitmessage for serialization/deserializationbenchmark result
Are these changes tested?
yes, add test case in aggregates_topk.slt
Are there any user-facing changes?
no