wudidapaopao opened a new pull request, #25536: URL: https://github.com/apache/datafusion/pull/25536
## Which issue does this PR close? - Closes #19637. ## Rationale for this change `AVG` maintains both sum and count state. When the same aggregate node already computes a matching `SUM` or `COUNT`, those states are redundant. ## What changes are included in this PR? - Add an aggregate decomposition hook and apply candidates only when deduplication does not increase the number of distinct aggregates. - Decompose eligible Float64 `AVG` expressions into shared `SUM` / `COUNT` components. - Keep the combined `AVG` accumulator when no component can be shared. - Reuse `NameTracker` for internal aggregate name conflicts. Decimal AVG is not included because its widened sum state and result semantics differ from regular Decimal SUM and require a separate design. ## What is the testing strategy for this PR? - Added `avg_to_sum_count.slt` covering shared SUM/COUNT, no-share cases, NULL/empty input, grouping sets, unsupported AVG forms, Decimal, and naming conflicts. - Added unit tests for decomposition profitability and UDAF forwarding. - Ran `cargo fmt --all`, full workspace Clippy with `-D warnings`, and the extended workspace test suite. Release benchmark using TPC-H SF1 with the four Q1 Decimal inputs materialized as Float64 Parquet: - baseline median: 29.137 ms - this PR median: 25.978 ms - improvement: 10.84% The no-sharing ClickBench Q32 case remained unchanged (48.931 ms vs 48.705 ms). ## Are there any user-facing changes? Eligible Float64 AVG aggregates may use shared SUM/COUNT states. Query results and output schemas are unchanged. -- 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]
