SimpleAggregateFunction

SimpleAggregateFunction(name, types_of_arguments…) data type stores current value of the aggregate function, and does not store its full state as AggregateFunction does. This optimization can be applied to functions for which the following property holds: the result of applying a function f to a row set S1 UNION ALL S2 can be obtained by applying f to parts of the row set separately, and then again applying f to the results: f(S1 UNION ALL S2) = f(f(S1) UNION ALL f(S2)). This property guarantees that partial aggregation results are enough to compute the combined one, so we don’t have to store and process any extra data.

The following aggregate functions are supported:

Values of the SimpleAggregateFunction(func, Type) look and stored the same way as Type, so you do not need to apply functions with -Merge/-State suffixes. SimpleAggregateFunction has better performance than AggregateFunction with same aggregation function.

Parameters

  • Name of the aggregate function.
  • Types of the aggregate function arguments.

Example

  1. CREATE TABLE t
  2. (
  3. column1 SimpleAggregateFunction(sum, UInt64),
  4. column2 SimpleAggregateFunction(any, String)
  5. ) ENGINE = ...

Original article