haohuaijin commented on code in PR #19653:
URL: https://github.com/apache/datafusion/pull/19653#discussion_r2678442853
##########
datafusion/physical-plan/src/aggregates/topk_stream.rs:
##########
@@ -192,9 +211,15 @@ impl Stream for GroupedTopKAggregateStream {
}
let batch = {
let _timer = emitting_time.timer();
- let cols = self.priority_map.emit()?;
+ 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);
+ }
Review Comment:
we can further improve this part, because for the query
```sql
select distinct id from t order by id limit 10
```
it do not have any aggregate, so we only need mantain the topk heap, and
skip the group keys
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]