diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2015-08-04 17:53:10 +0300 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2015-08-04 17:53:10 +0300 |
commit | 804163bc25e979fcd91b02e58fa2d1c6b587cc65 (patch) | |
tree | 841c63e6356df2bc42b3729cb05ba2f9834bdd78 /src/include/nodes/execnodes.h | |
parent | dee0200f0276c0f9da930a2c926f90f5615f2d64 (diff) | |
download | postgresql-804163bc25e979fcd91b02e58fa2d1c6b587cc65.tar.gz postgresql-804163bc25e979fcd91b02e58fa2d1c6b587cc65.zip |
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.
Diffstat (limited to 'src/include/nodes/execnodes.h')
-rw-r--r-- | src/include/nodes/execnodes.h | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index 303fc3c1c77..5796de861c4 100644 --- a/src/include/nodes/execnodes.h +++ b/src/include/nodes/execnodes.h @@ -609,9 +609,6 @@ typedef struct WholeRowVarExprState typedef struct AggrefExprState { ExprState xprstate; - List *aggdirectargs; /* states of direct-argument expressions */ - List *args; /* states of aggregated-argument expressions */ - ExprState *aggfilter; /* state of FILTER expression, if any */ int aggno; /* ID number for agg within its plan node */ } AggrefExprState; @@ -1825,6 +1822,7 @@ typedef struct GroupState */ /* these structs are private in nodeAgg.c: */ typedef struct AggStatePerAggData *AggStatePerAgg; +typedef struct AggStatePerTransData *AggStatePerTrans; typedef struct AggStatePerGroupData *AggStatePerGroup; typedef struct AggStatePerPhaseData *AggStatePerPhase; @@ -1833,14 +1831,16 @@ typedef struct AggState ScanState ss; /* its first field is NodeTag */ List *aggs; /* all Aggref nodes in targetlist & quals */ int numaggs; /* length of list (could be zero!) */ + int numtrans; /* number of pertrans items */ AggStatePerPhase phase; /* pointer to current phase data */ int numphases; /* number of phases */ int current_phase; /* current phase number */ FmgrInfo *hashfunctions; /* per-grouping-field hash fns */ AggStatePerAgg peragg; /* per-Aggref information */ + AggStatePerTrans pertrans; /* per-Trans state information */ ExprContext **aggcontexts; /* econtexts for long-lived data (per GS) */ ExprContext *tmpcontext; /* econtext for input expressions */ - AggStatePerAgg curperagg; /* identifies currently active aggregate */ + AggStatePerTrans curpertrans; /* currently active trans state */ bool input_done; /* indicates end of input */ bool agg_done; /* indicates completion of Agg scan */ int projected_set; /* The last projected grouping set */ |