From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | pgsql-committers(at)postgresql(dot)org |
Subject: | pgsql: Explicitly track whether aggregate final functions modify transi |
Date: | 2017-10-14 19:22:06 |
Message-ID: | E1e3S0c-0006Ur-3k@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers |
Explicitly track whether aggregate final functions modify transition state.
Up to now, there's been hard-wired assumptions that normal aggregates'
final functions never modify their transition states, while ordered-set
aggregates' final functions always do. This has always been a bit
limiting, and in particular it's getting in the way of improving the
built-in ordered-set aggregates to allow merging of transition states.
Therefore, let's introduce catalog and CREATE AGGREGATE infrastructure
that lets the finalfn's behavior be declared explicitly.
There are now three possibilities for the finalfn behavior: it's purely
read-only, it trashes the transition state irrecoverably, or it changes
the state in such a way that no more transfn calls are possible but the
state can still be passed to other, compatible finalfns. There are no
examples of this third case today, but we'll shortly make the built-in
OSAs act like that.
This change allows user-defined aggregates to explicitly disclaim support
for use as window functions, and/or to prevent transition state merging,
if their implementations cannot handle that. While it was previously
possible to handle the window case with a run-time error check, there was
not any way to prevent transition state merging, which in retrospect is
something commit 804163bc2 should have provided for. But better late
than never.
In passing, split out pg_aggregate.c's extern function declarations into
a new header file pg_aggregate_fn.h, similarly to what we've done for
some other catalog headers, so that pg_aggregate.h itself can be safe
for frontend files to include. This lets pg_dump use the symbolic
names for relevant constants.
Discussion: https://postgr.es/m/4834.1507849699@sss.pgh.pa.us
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/4de2d4fba38f4f7aff7f95401eb43a6cd05a6db4
Modified Files
--------------
doc/src/sgml/catalogs.sgml | 20 ++
doc/src/sgml/ref/create_aggregate.sgml | 72 ++++-
doc/src/sgml/xaggr.sgml | 20 +-
src/backend/catalog/pg_aggregate.c | 5 +
src/backend/commands/aggregatecmds.c | 42 +++
src/backend/executor/nodeAgg.c | 65 +++--
src/backend/executor/nodeWindowAgg.c | 43 ++-
src/bin/pg_dump/pg_dump.c | 107 +++++++-
src/bin/pg_dump/t/002_pg_dump.pl | 4 +-
src/include/catalog/catversion.h | 2 +-
src/include/catalog/pg_aggregate.h | 346 ++++++++++++-------------
src/include/catalog/pg_aggregate_fn.h | 52 ++++
src/test/regress/expected/create_aggregate.out | 15 +-
src/test/regress/expected/opr_sanity.out | 2 +
src/test/regress/sql/create_aggregate.sql | 9 +-
src/test/regress/sql/opr_sanity.sql | 2 +
16 files changed, 555 insertions(+), 251 deletions(-)
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2017-10-14 19:52:13 | pgsql: gcc's support for __attribute__((noinline)) hasn't been around f |
Previous Message | Peter Eisentraut | 2017-10-14 15:46:49 | pgsql: Reinstate genhtml --prefix option for non-vpath builds |