summaryrefslogtreecommitdiff
path: root/src/include/executor
diff options
context:
space:
mode:
authorAndres Freund2020-02-24 22:39:22 +0000
committerAndres Freund2020-02-24 23:09:09 +0000
commit2742c45080077ed3b08b810bb96341499b86d530 (patch)
tree84b13be23cc6f50af22d3656dd49576cf25f1dc5 /src/include/executor
parent7d672b76bf27327dc3527dabcd8be4e2dedf430f (diff)
expression eval: Reduce number of steps for agg transition invocations.
Do so by combining the various steps that are part of aggregate transition function invocation into one larger step. As some of the current steps are only necessary for some aggregates, have one variant of the aggregate transition step for each possible combination. To avoid further manual copies of code in the different transition step implementations, move most of the code into helper functions marked as "always inline". The benefit of this change is an increase in performance when aggregating lots of rows. This comes in part due to the reduced number of indirect jumps due to the reduced number of steps, and in part by reducing redundant setup code across steps. This mainly benefits interpreted execution, but the code generated by JIT is also improved a bit. As a nice side-effect it also ends up making the code a bit simpler. A small additional optimization is removing the need to set aggstate->curaggcontext before calling ExecAggInitGroup, choosing to instead passign curaggcontext as an argument. It was, in contrast to other aggregate related functions, only needed to fetch a memory context to copy the transition value into. Author: Andres Freund Discussion: https://postgr.es/m/[email protected] https://postgr.es/m/[email protected]
Diffstat (limited to 'src/include/executor')
-rw-r--r--src/include/executor/execExpr.h34
1 files changed, 9 insertions, 25 deletions
diff --git a/src/include/executor/execExpr.h b/src/include/executor/execExpr.h
index 73a2ca8c6dd..8bbf6621da0 100644
--- a/src/include/executor/execExpr.h
+++ b/src/include/executor/execExpr.h
@@ -225,10 +225,12 @@ typedef enum ExprEvalOp
EEOP_AGG_DESERIALIZE,
EEOP_AGG_STRICT_INPUT_CHECK_ARGS,
EEOP_AGG_STRICT_INPUT_CHECK_NULLS,
- EEOP_AGG_INIT_TRANS,
- EEOP_AGG_STRICT_TRANS_CHECK,
+ EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL,
+ EEOP_AGG_PLAIN_TRANS_STRICT_BYVAL,
EEOP_AGG_PLAIN_TRANS_BYVAL,
- EEOP_AGG_PLAIN_TRANS,
+ EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYREF,
+ EEOP_AGG_PLAIN_TRANS_STRICT_BYREF,
+ EEOP_AGG_PLAIN_TRANS_BYREF,
EEOP_AGG_ORDERED_TRANS_DATUM,
EEOP_AGG_ORDERED_TRANS_TUPLE,
@@ -620,27 +622,8 @@ typedef struct ExprEvalStep
int jumpnull;
} agg_strict_input_check;
- /* for EEOP_AGG_INIT_TRANS */
- struct
- {
- AggStatePerTrans pertrans;
- ExprContext *aggcontext;
- int setno;
- int transno;
- int setoff;
- int jumpnull;
- } agg_init_trans;
-
- /* for EEOP_AGG_STRICT_TRANS_CHECK */
- struct
- {
- int setno;
- int transno;
- int setoff;
- int jumpnull;
- } agg_strict_trans_check;
-
- /* for EEOP_AGG_{PLAIN,ORDERED}_TRANS* */
+ /* for EEOP_AGG_PLAIN_TRANS_[INIT_][STRICT_]{BYVAL,BYREF} */
+ /* for EEOP_AGG_ORDERED_TRANS_{DATUM,TUPLE} */
struct
{
AggStatePerTrans pertrans;
@@ -750,7 +733,8 @@ extern void ExecEvalWholeRowVar(ExprState *state, ExprEvalStep *op,
extern void ExecEvalSysVar(ExprState *state, ExprEvalStep *op,
ExprContext *econtext, TupleTableSlot *slot);
-extern void ExecAggInitGroup(AggState *aggstate, AggStatePerTrans pertrans, AggStatePerGroup pergroup);
+extern void ExecAggInitGroup(AggState *aggstate, AggStatePerTrans pertrans, AggStatePerGroup pergroup,
+ ExprContext *aggcontext);
extern Datum ExecAggTransReparent(AggState *aggstate, AggStatePerTrans pertrans,
Datum newValue, bool newValueIsNull,
Datum oldValue, bool oldValueIsNull);