]> granicus.if.org Git - postgresql/commit
Create infrastructure for moving-aggregate optimization.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 12 Apr 2014 15:58:53 +0000 (11:58 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 12 Apr 2014 16:03:30 +0000 (12:03 -0400)
commita9d9acbf219b9e96585779cd5f99d674d4ccba74
tree4bd26a78fa7f6f0bc558c611278e42a9f41d4875
parent3c41b812c5578fd7bd5c2de42941012d7d56dde2
Create infrastructure for moving-aggregate optimization.

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
20 files changed:
doc/src/sgml/catalogs.sgml
doc/src/sgml/ref/create_aggregate.sgml
doc/src/sgml/xaggr.sgml
src/backend/catalog/pg_aggregate.c
src/backend/commands/aggregatecmds.c
src/backend/executor/nodeAgg.c
src/backend/executor/nodeWindowAgg.c
src/backend/optimizer/util/clauses.c
src/backend/parser/parse_agg.c
src/bin/pg_dump/pg_dump.c
src/include/catalog/catversion.h
src/include/catalog/pg_aggregate.h
src/include/nodes/execnodes.h
src/include/parser/parse_agg.h
src/test/regress/expected/create_aggregate.out
src/test/regress/expected/opr_sanity.out
src/test/regress/expected/window.out
src/test/regress/sql/create_aggregate.sql
src/test/regress/sql/opr_sanity.sql
src/test/regress/sql/window.sql