1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +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:
Robert Haas
2016-01-20 13:46:50 -05:00
parent c8642d909f
commit a7de3dc5c3
21 changed files with 652 additions and 234 deletions

View File

@ -101,6 +101,24 @@ CREATE AGGREGATE sumdouble (float8)
msfunc = float8pl,
minvfunc = float8mi
);
-- Test aggregate combine function
-- ensure create aggregate works.
CREATE AGGREGATE mysum (int)
(
stype = int,
sfunc = int4pl,
combinefunc = int4pl
);
-- Ensure all these functions made it into the catalog
SELECT aggfnoid,aggtransfn,aggcombinefn,aggtranstype
FROM pg_aggregate
WHERE aggfnoid = 'mysum'::REGPROC;
aggfnoid | aggtransfn | aggcombinefn | aggtranstype
----------+------------+--------------+--------------
mysum | int4pl | int4pl | 23
(1 row)
DROP AGGREGATE mysum (int);
-- invalid: nonstrict inverse with strict forward function
CREATE FUNCTION float8mi_n(float8, float8) RETURNS float8 AS
$$ SELECT $1 - $2; $$

View File

@ -115,6 +115,23 @@ CREATE AGGREGATE sumdouble (float8)
minvfunc = float8mi
);
-- Test aggregate combine function
-- ensure create aggregate works.
CREATE AGGREGATE mysum (int)
(
stype = int,
sfunc = int4pl,
combinefunc = int4pl
);
-- Ensure all these functions made it into the catalog
SELECT aggfnoid,aggtransfn,aggcombinefn,aggtranstype
FROM pg_aggregate
WHERE aggfnoid = 'mysum'::REGPROC;
DROP AGGREGATE mysum (int);
-- invalid: nonstrict inverse with strict forward function
CREATE FUNCTION float8mi_n(float8, float8) RETURNS float8 AS