Dandandan commented on code in PR #21654:
URL: https://github.com/apache/datafusion/pull/21654#discussion_r3089029785
##########
datafusion/physical-plan/src/aggregates/row_hash.rs:
##########
@@ -587,7 +587,24 @@ impl GroupedHashAggregateStream {
_ => OutOfMemoryMode::ReportError,
};
- let group_values = new_group_values(group_schema, &group_ordering)?;
+ // Use NDV estimate from child statistics to pre-allocate hash table,
+ // bounded by 128K to avoid over-allocation.
+ const MAX_NDV_CAPACITY: usize = 128 * 1024;
+ let capacity_hint = agg
+ .input
+ .partition_statistics(None)
+ .ok()
+ .and_then(|stats| agg.compute_group_ndv(&stats))
+ .map(|ndv: usize| ndv.min(MAX_NDV_CAPACITY));
+
+ if let Some(capacity) = capacity_hint {
+ for acc in &mut accumulators {
+ acc.preallocate(capacity);
Review Comment:
Should probably do these calls after `MemoryConsumer`
--
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]