fix: count aggregation_time once per batch instead of once per accumulator - #24736
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #24736 +/- ##
==========================================
+ Coverage 81.42% 81.52% +0.09%
==========================================
Files 1121 1123 +2
Lines 402142 406194 +4052
Branches 402142 406194 +4052
==========================================
+ Hits 327460 331153 +3693
- Misses 55484 55668 +184
- Partials 19198 19373 +175 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
kumarUjjawal
left a comment
There was a problem hiding this comment.
Thank you @ranflarion for the fix.
This looks correct. I was wondering if adding and assert or a test help?
added a test. the assertion that works is a structural invariant rather than a value check: aggregation_time is accumulated strictly inside the elapsed_compute timer that wraps group_aggregate_batch, so aggregation_time <= elapsed_compute always holds and double counting breaks it. there's no wall-clock threshold so no reason for it to be flaky |
…n the timer comment
kumarUjjawal
left a comment
There was a problem hiding this comment.
Thank you @ranflarion for the iterations.
Looks good!
Which issue does this PR close?
aggregation_timemetric is inflated up to (N+1)/2 times on GROUP BY nodes with N aggregate functions #24735.Rationale for this change
aggregation_timeonGroupedHashAggregateStreamis added inside the per-accumulator loop whileagg_start_timeis taken once before it, so with N aggregate functions the k-th accumulator re-adds the elapsed time of all k accumulators so far, inflating the metric by up to (N+1)/2. On a 28-function GROUP BY a single task reported 4m22s ofaggregation_timeinside a 2m0s stage. Single-aggregate plans are unaffected. The neweraggregate_hash_tableimplementations already scope the timer around the whole loop.What changes are included in this PR?
Move the
add_elapsedcall after the accumulator loop, once per interned batch.time_calculating_group_ids, which sharesagg_start_timeas its end point, is unchanged, and the per-accumulatoraggregate_accumulator_metricstimings are unaffected.Are these changes tested?
Covered by the existing aggregate tests (
cargo test -p datafusion-physical-plan aggregates, 193 passed). The metric's value is wall-clock time, which the existing tests do not assert exactly; the inflation itself was measured on a 28-aggregate workload where the fixed metric now stays within the operator's elapsed time.Are there any user-facing changes?
aggregation_time(shown inEXPLAIN ANALYZEas elapsed_compute subset time) now reports the actual time spent in accumulators on plans with more than one aggregate function; previously it over-reported on such plans.