wudidapaopao commented on code in PR #25536:
URL: https://github.com/apache/datafusion/pull/25536#discussion_r4065514376
##########
datafusion/expr/src/udaf.rs:
##########
@@ -311,6 +312,17 @@ impl AggregateUDF {
self.inner.simplify()
}
+ /// Returns this aggregate function's candidate decomposition, if any.
+ ///
+ /// See [`AggregateUDFImpl::decompose`] for more details.
+ pub fn decompose(
Review Comment:
Thanks, I considered using `simplify`. I think we should retain the AVG
accumulator and only decompose `AVG` when its generated `SUM` or `COUNT` can be
shared. If implemented in `simplify`, every AVG would be unconditionally
rewritten into `SUM/COUNT`.
On 20 million random non-null Int64 rows:
```
SELECT AVG(x) FROM t;
```
versus:
```
SELECT SUM(CAST(x AS DOUBLE))
/ CAST(COUNT(*) AS DOUBLE)
FROM t;
```
took `9.06` ms and `10.72` ms respectively, so decomposition was `18.29%`
slower.
With one reusable SUM:
```
SELECT SUM(CAST(x AS DOUBLE)), AVG(x) FROM t;
```
decomposition improved `11.72` ms to `10.79` ms (`7.95%`).
With three reusable SUMs:
```
SELECT
SUM(CAST(x AS DOUBLE)), AVG(x),
SUM(CAST(y AS DOUBLE)), AVG(y),
SUM(CAST(z AS DOUBLE)), AVG(z)
FROM t;
```
decomposition improved `32.91` ms to `27.85` ms (`15.38%`).
--
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]