fix(physical-plan): fix aggregation_time metric inflation on multi-aggregate GROUP BY - #24743
Closed
arnavahire19 wants to merge 1 commit into
Closed
fix(physical-plan): fix aggregation_time metric inflation on multi-aggregate GROUP BY#24743arnavahire19 wants to merge 1 commit into
arnavahire19 wants to merge 1 commit into
Conversation
… per accumulator In GroupedHashAggregateStream, add_elapsed was called inside the accumulator loop using agg_start_time recorded before the loop. On queries with multiple aggregate functions, this compounded elapsed time across all accumulators in each batch and inflated aggregation_time up to (N+1)/2 times. Moving add_elapsed after the loop aligns grouped_hash_stream with the scoped timer pattern used across the other aggregate hash table implementations.
Contributor
|
Closing this in favour of #24736 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #24743 +/- ##
==========================================
+ Coverage 81.42% 81.47% +0.04%
==========================================
Files 1121 1122 +1
Lines 402142 403629 +1487
Branches 402142 403629 +1487
==========================================
+ Hits 327460 328860 +1400
- Misses 55484 55510 +26
- Partials 19198 19259 +61 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #24735.
Problem
In
GroupedHashAggregateStream::process_batch,agg_start_timeis recorded once before iterating over the accumulators. However,self.group_by_metrics.aggregation_time.add_elapsed(agg_start_time)was placed inside the accumulator loop.For queries with$N$ aggregate functions, every iteration re-adds the accumulated duration from the start of the loop (
sum_{k=1..N} (t_1 + ... + t_k)), inflating the reportedaggregation_timemetric by up to $(N+1)/2$x.Solution
Move
add_elapsed(agg_start_time)outside and after the accumulator loop so that the total time spent updating/merging accumulators for the batch is recorded exactly once per batch. This matches the behavior inaggregate_hash_table/common.rsandaggregate_hash_table/common_ordered.rs.Testing
Ran
cargo test --package datafusion-physical-plan --lib aggregates(all 193 tests passing).