]> granicus.if.org Git - postgresql/commit
Share transition state between different aggregates when possible.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Tue, 4 Aug 2015 14:53:10 +0000 (17:53 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Tue, 4 Aug 2015 14:53:10 +0000 (17:53 +0300)
commit804163bc25e979fcd91b02e58fa2d1c6b587cc65
tree841c63e6356df2bc42b3729cb05ba2f9834bdd78
parentdee0200f0276c0f9da930a2c926f90f5615f2d64
Share transition state between different aggregates when possible.

If there are two different aggregates in the query with same inputs, and
the aggregates have the same initial condition and transition function,
only calculate the state value once, and only call the final functions
separately. For example, AVG(x) and SUM(x) aggregates have the same
transition function, which accumulates the sum and number of input tuples.
For a query like "SELECT AVG(x), SUM(x) FROM x", we can therefore
accumulate the state function only once, which gives a nice speedup.

David Rowley, reviewed and edited by me.
src/backend/executor/execQual.c
src/backend/executor/nodeAgg.c
src/backend/executor/nodeWindowAgg.c
src/backend/parser/parse_agg.c
src/include/nodes/execnodes.h
src/include/parser/parse_agg.h
src/test/regress/expected/aggregates.out
src/test/regress/sql/aggregates.sql