pgsql: Share transition state between different aggregates when possibl

From: Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Share transition state between different aggregates when possibl
Date: 2015-08-04 15:02:29
Message-ID: E1ZMdjZ-0006x7-1I@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/804163bc25e979fcd91b02e58fa2d1c6b587cc65

Modified Files
--------------
src/backend/executor/execQual.c | 22 +-
src/backend/executor/nodeAgg.c | 1070 +++++++++++++++++++-----------
src/backend/executor/nodeWindowAgg.c | 31 +-
src/backend/parser/parse_agg.c | 75 ++-
src/include/nodes/execnodes.h | 8 +-
src/include/parser/parse_agg.h | 14 +-
src/test/regress/expected/aggregates.out | 204 ++++++
src/test/regress/sql/aggregates.sql | 165 +++++
8 files changed, 1132 insertions(+), 457 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Robert Haas 2015-08-04 15:53:14 pgsql: Update comment to match behavior of latest code.
Previous Message Amit Kapila 2015-08-04 03:15:11 Re: Re: [COMMITTERS] pgsql: Map basebackup tablespaces using a tablespace_map file