Create infrastructure for moving-aggregate optimization

Enterprise / PostgreSQL - Tom Lane [sss.pgh.pa.us] - 12 April 2014 11:03 UTC

Until now, when executing an aggregate function as a window function within a window with moving frame start (that is, any frame start mode except UNBOUNDED PRECEDING), we had to recalculate the aggregate from scratch each time the frame head moved. This patch allows an aggregate definition to include an alternate "moving aggregate" implementation that includes an inverse transition function for removing rows from the aggregate's running state. As long as this can be done successfully, runtime is proportional to the total number of input rows, rather than to the number of input rows times the average frame length.

This commit includes the core infrastructure, documentation, and regression tests using user-defined aggregates. Follow-on commits will update some of the built-in aggregates to use this feature.

David Rowley and Florian Pflug, reviewed by Dean Rasheed; additional hacking by me

a9d9acb Create infrastructure for moving-aggregate optimization.
doc/src/sgml/catalogs.sgml | 43 ++
doc/src/sgml/ref/create_aggregate.sgml | 153 +++++-
doc/src/sgml/xaggr.sgml | 197 +++++++-
src/backend/catalog/pg_aggregate.c | 241 ++++++++-
src/backend/commands/aggregatecmds.c | 101 +++-
src/backend/executor/nodeAgg.c | 13 +-
src/backend/executor/nodeWindowAgg.c | 639 ++++++++++++++++++++----
src/backend/optimizer/util/clauses.c | 6 +-
src/backend/parser/parse_agg.c | 32 +-
src/bin/pg_dump/pg_dump.c | 68 +++
src/include/catalog/catversion.h | 2 +-
src/include/catalog/pg_aggregate.h | 302 +++++------
src/include/nodes/execnodes.h | 3 +-
src/include/parser/parse_agg.h | 2 +
src/test/regress/expected/create_aggregate.out | 35 ++
src/test/regress/expected/opr_sanity.out | 122 ++++-
src/test/regress/expected/window.out | 223 +++++++++
src/test/regress/sql/create_aggregate.sql | 41 ++
src/test/regress/sql/opr_sanity.sql | 103 +++-
src/test/regress/sql/window.sql | 192 +++++++
20 files changed, 2228 insertions(+), 290 deletions(-)

Upstream: git.postgresql.org


  • Share