QinXi-ai commented on code in PR #25988:
URL: https://github.com/apache/datafusion/pull/25988#discussion_r4505364483
##########
datafusion/optimizer/src/single_distinct_to_groupby.rs:
##########
@@ -154,12 +158,47 @@ 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.
+ // Even one target partition can have multiple input partitions (e.g. UNION
+ // ALL or an existing partitioned table), requiring Partial/Final state
merging.
+ // This is opt-in: the rule cannot see memory limits or cost the input, and
+ // native DISTINCT must fit each group's distinct values in memory.
+ if use_native_grouped_distinct
+ && distinct_aggs.len() == aggregate_count
+ // An unknown answer must preserve the existing rewrite.
+ && distinct_groups_support(&distinct_aggs, input_schema)?
+ .iter()
+ .all(|support| *support == Some(true))
Review Comment:
Added both EXPLAINs in 764869ea, before the global aggregate case. They pin
the rewrite for mixed aggregates and unknown DISTINCT support with the flag on.
--
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]