QinXi-ai commented on code in PR #25988:
URL: https://github.com/apache/datafusion/pull/25988#discussion_r4500465393


##########
datafusion/optimizer/src/single_distinct_to_groupby.rs:
##########
@@ -154,12 +155,41 @@ fn is_single_distinct_agg(
     if aggregate_count != aggr_expr.len() || fields_set.len() != 1 {
         return Ok(false);
     }
+    // With one target partition, a native GroupsAccumulator avoids building an
+    // extra aggregate with a row per (group, distinct value) pair. With 
multiple
+    // partitions, the rewrite also distributes deduplication by both keys;
+    // keeping DISTINCT instead repartitions lists of values by group and 
merges
+    // them in the final accumulator. That can concentrate work on a few 
groups.
+    // Native accumulator support alone does not establish that this is 
cheaper.
+    if use_native_grouped_distinct
+        && distinct_aggs.len() == aggregate_count
+        && all_have_groups_accumulators(&distinct_aggs, input_schema)?
+    {
+        return Ok(false);
+    }
     if has_count_rollup && !rewrite_pays_for_count(&distinct_aggs, 
input_schema)? {
         return Ok(false);
     }
     Ok(true)
 }
 
+fn all_have_groups_accumulators(

Review Comment:
   Done, both checks now share the type lookup through 
`distinct_groups_support`. I also added the opt-in exception to the rule's doc 
comment.



-- 
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]

Reply via email to