mirror of
https://github.com/postgres/postgres.git
synced 2025-08-30 06:01:21 +03:00
Support multi-stage aggregation.
Aggregate nodes now have two new modes: a "partial" mode where they output the unfinalized transition state, and a "finalize" mode where they accept unfinalized transition states rather than individual values as input. These new modes are not used anywhere yet, but they will be necessary for parallel aggregation. The infrastructure also figures to be useful for cases where we want to aggregate local data and remote data via the FDW interface, and want to bring back partial aggregates from the remote side that can then be combined with locally generated partial aggregates to produce the final value. It may also be useful even when neither FDWs nor parallelism are in play, as explained in the comments in nodeAgg.c. David Rowley and Simon Riggs, reviewed by KaiGai Kohei, Heikki Linnakangas, Haribabu Kommi, and me.
This commit is contained in:
@@ -27,6 +27,7 @@ CREATE AGGREGATE <replaceable class="parameter">name</replaceable> ( [ <replacea
|
||||
[ , SSPACE = <replaceable class="PARAMETER">state_data_size</replaceable> ]
|
||||
[ , FINALFUNC = <replaceable class="PARAMETER">ffunc</replaceable> ]
|
||||
[ , FINALFUNC_EXTRA ]
|
||||
[ , COMBINEFUNC = <replaceable class="PARAMETER">combinefunc</replaceable> ]
|
||||
[ , INITCOND = <replaceable class="PARAMETER">initial_condition</replaceable> ]
|
||||
[ , MSFUNC = <replaceable class="PARAMETER">msfunc</replaceable> ]
|
||||
[ , MINVFUNC = <replaceable class="PARAMETER">minvfunc</replaceable> ]
|
||||
@@ -45,6 +46,7 @@ CREATE AGGREGATE <replaceable class="parameter">name</replaceable> ( [ [ <replac
|
||||
[ , SSPACE = <replaceable class="PARAMETER">state_data_size</replaceable> ]
|
||||
[ , FINALFUNC = <replaceable class="PARAMETER">ffunc</replaceable> ]
|
||||
[ , FINALFUNC_EXTRA ]
|
||||
[ , COMBINEFUNC = <replaceable class="PARAMETER">combinefunc</replaceable> ]
|
||||
[ , INITCOND = <replaceable class="PARAMETER">initial_condition</replaceable> ]
|
||||
[ , HYPOTHETICAL ]
|
||||
)
|
||||
@@ -58,6 +60,7 @@ CREATE AGGREGATE <replaceable class="PARAMETER">name</replaceable> (
|
||||
[ , SSPACE = <replaceable class="PARAMETER">state_data_size</replaceable> ]
|
||||
[ , FINALFUNC = <replaceable class="PARAMETER">ffunc</replaceable> ]
|
||||
[ , FINALFUNC_EXTRA ]
|
||||
[ , COMBINEFUNC = <replaceable class="PARAMETER">combinefunc</replaceable> ]
|
||||
[ , INITCOND = <replaceable class="PARAMETER">initial_condition</replaceable> ]
|
||||
[ , MSFUNC = <replaceable class="PARAMETER">msfunc</replaceable> ]
|
||||
[ , MINVFUNC = <replaceable class="PARAMETER">minvfunc</replaceable> ]
|
||||
@@ -105,12 +108,15 @@ CREATE AGGREGATE <replaceable class="PARAMETER">name</replaceable> (
|
||||
functions:
|
||||
a state transition function
|
||||
<replaceable class="PARAMETER">sfunc</replaceable>,
|
||||
and an optional final calculation function
|
||||
<replaceable class="PARAMETER">ffunc</replaceable>.
|
||||
an optional final calculation function
|
||||
<replaceable class="PARAMETER">ffunc</replaceable>,
|
||||
and an optional combine function
|
||||
<replaceable class="PARAMETER">combinefunc</replaceable>.
|
||||
These are used as follows:
|
||||
<programlisting>
|
||||
<replaceable class="PARAMETER">sfunc</replaceable>( internal-state, next-data-values ) ---> next-internal-state
|
||||
<replaceable class="PARAMETER">ffunc</replaceable>( internal-state ) ---> aggregate-value
|
||||
<replaceable class="PARAMETER">combinefunc</replaceable>( internal-state, internal-state ) ---> next-internal-state
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
@@ -127,6 +133,12 @@ CREATE AGGREGATE <replaceable class="PARAMETER">name</replaceable> (
|
||||
is returned as-is.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
An aggregate function may also supply a combining function, which allows
|
||||
the aggregation process to be broken down into multiple steps. This
|
||||
facilitates query optimization techniques such as parallel query.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
An aggregate function can provide an initial condition,
|
||||
that is, an initial value for the internal state value.
|
||||
|
Reference in New Issue
Block a user