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`.
   
   Benchmark: 20 million random non-null `Int64` rows, single-threaded.
   
   | Scenario | SQL | Before decomposition | After decomposition | Change |
   |---|---|---:|---:|---:|
   | No sharing | `SELECT AVG(x) FROM t` | 9.06 ms | 10.72 ms | 18.29% slower |
   | One reusable SUM | `SELECT SUM(CAST(x AS DOUBLE)), AVG(x) FROM t` | 11.72 
ms | 10.79 ms | 7.95% faster |
   | 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` | 32.91 ms | 27.85 
ms | 15.38% faster |



-- 
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]

Reply via email to