Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit69c3936

Browse files
committed
Expression evaluation based aggregate transition invocation.
Previously aggregate transition and combination functions were invokedby special case code in nodeAgg.c, evaluating input and filtersseparately using the expression evaluation machinery. That turns outto not be great for performance for several reasons:- repeated expression evaluations have some cost- the transition functions invocations are poorly predicted, as commonly there are multiple aggregates in a query, resulting in the same call-stack invoking different functions.- filter and input computation had to be done separately- the special case code made it hard to implement JITing of the whole transition function invocationAddress this by building one large expression that computes input,evaluates filters, and invokes transition functions.This leads to moderate speedups in queries bottlenecked by aggregatecomputations, and enables large speedups for similar cases once JITingis done.There's potential for further improvement:- It'd be nice if we could simplify the somewhat expensive aggstate->all_pergroups lookups.- right now there's still an advance_transition_function invocation in nodeAgg.c, leading to some code duplication.Author: Andres FreundDiscussion:https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de
1 parent272c2ab commit69c3936

File tree

8 files changed

+1230
-789
lines changed

8 files changed

+1230
-789
lines changed

‎src/backend/executor/execExpr.c

Lines changed: 422 additions & 7 deletions
Large diffs are not rendered by default.

‎src/backend/executor/execExprInterp.c

Lines changed: 345 additions & 11 deletions
Large diffs are not rendered by default.

‎src/backend/executor/nodeAgg.c

Lines changed: 98 additions & 766 deletions
Large diffs are not rendered by default.

‎src/include/executor/execExpr.h

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndefEXEC_EXPR_H
1515
#defineEXEC_EXPR_H
1616

17+
#include"executor/nodeAgg.h"
1718
#include"nodes/execnodes.h"
1819

1920
/* forward references to avoid circularity */
@@ -64,9 +65,9 @@ typedef enum ExprEvalOp
6465
EEOP_WHOLEROW,
6566

6667
/*
67-
* Compute non-system Var value, assign it into ExprState's
68-
*resultslot.These are not used if a CheckVarSlotCompatibility() check
69-
*would beneeded.
68+
* Compute non-system Var value, assign it into ExprState's resultslot.
69+
* These are not used if a CheckVarSlotCompatibility() check would be
70+
* needed.
7071
*/
7172
EEOP_ASSIGN_INNER_VAR,
7273
EEOP_ASSIGN_OUTER_VAR,
@@ -218,6 +219,17 @@ typedef enum ExprEvalOp
218219
EEOP_SUBPLAN,
219220
EEOP_ALTERNATIVE_SUBPLAN,
220221

222+
/* aggregation related nodes */
223+
EEOP_AGG_STRICT_DESERIALIZE,
224+
EEOP_AGG_DESERIALIZE,
225+
EEOP_AGG_STRICT_INPUT_CHECK,
226+
EEOP_AGG_INIT_TRANS,
227+
EEOP_AGG_STRICT_TRANS_CHECK,
228+
EEOP_AGG_PLAIN_TRANS_BYVAL,
229+
EEOP_AGG_PLAIN_TRANS,
230+
EEOP_AGG_ORDERED_TRANS_DATUM,
231+
EEOP_AGG_ORDERED_TRANS_TUPLE,
232+
221233
/* non-existent operation, used e.g. to check array lengths */
222234
EEOP_LAST
223235
}ExprEvalOp;
@@ -573,6 +585,55 @@ typedef struct ExprEvalStep
573585
/* out-of-line state, created by nodeSubplan.c */
574586
AlternativeSubPlanState*asstate;
575587
}alternative_subplan;
588+
589+
/* for EEOP_AGG_*DESERIALIZE */
590+
struct
591+
{
592+
AggState*aggstate;
593+
FunctionCallInfofcinfo_data;
594+
intjumpnull;
595+
}agg_deserialize;
596+
597+
/* for EEOP_AGG_STRICT_INPUT_CHECK */
598+
struct
599+
{
600+
bool*nulls;
601+
intnargs;
602+
intjumpnull;
603+
}agg_strict_input_check;
604+
605+
/* for EEOP_AGG_INIT_TRANS */
606+
struct
607+
{
608+
AggState*aggstate;
609+
AggStatePerTranspertrans;
610+
ExprContext*aggcontext;
611+
intsetno;
612+
inttransno;
613+
intsetoff;
614+
intjumpnull;
615+
}agg_init_trans;
616+
617+
/* for EEOP_AGG_STRICT_TRANS_CHECK */
618+
struct
619+
{
620+
AggState*aggstate;
621+
intsetno;
622+
inttransno;
623+
intsetoff;
624+
intjumpnull;
625+
}agg_strict_trans_check;
626+
627+
/* for EEOP_AGG_{PLAIN,ORDERED}_TRANS* */
628+
struct
629+
{
630+
AggState*aggstate;
631+
AggStatePerTranspertrans;
632+
ExprContext*aggcontext;
633+
intsetno;
634+
inttransno;
635+
intsetoff;
636+
}agg_trans;
576637
}d;
577638
}ExprEvalStep;
578639

@@ -669,4 +730,13 @@ extern void ExecEvalAlternativeSubPlan(ExprState *state, ExprEvalStep *op,
669730
externvoidExecEvalWholeRowVar(ExprState*state,ExprEvalStep*op,
670731
ExprContext*econtext);
671732

733+
externvoidExecAggInitGroup(AggState*aggstate,AggStatePerTranspertrans,AggStatePerGrouppergroup);
734+
externDatumExecAggTransReparent(AggState*aggstate,AggStatePerTranspertrans,
735+
DatumnewValue,boolnewValueIsNull,
736+
DatumoldValue,boololdValueIsNull);
737+
externvoidExecEvalAggOrderedTransDatum(ExprState*state,ExprEvalStep*op,
738+
ExprContext*econtext);
739+
externvoidExecEvalAggOrderedTransTuple(ExprState*state,ExprEvalStep*op,
740+
ExprContext*econtext);
741+
672742
#endif/* EXEC_EXPR_H */

‎src/include/executor/executor.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ extern void ExecConstraints(ResultRelInfo *resultRelInfo,
192192
externboolExecPartitionCheck(ResultRelInfo*resultRelInfo,
193193
TupleTableSlot*slot,EState*estate);
194194
externvoidExecPartitionCheckEmitError(ResultRelInfo*resultRelInfo,
195-
TupleTableSlot*slot,EState*estate);
195+
TupleTableSlot*slot,EState*estate);
196196
externvoidExecWithCheckOptions(WCOKindkind,ResultRelInfo*resultRelInfo,
197197
TupleTableSlot*slot,EState*estate);
198198
externLockTupleModeExecUpdateLockMode(EState*estate,ResultRelInfo*relinfo);
@@ -254,6 +254,8 @@ extern ExprState *ExecInitExprWithParams(Expr *node, ParamListInfo ext_params);
254254
externExprState*ExecInitQual(List*qual,PlanState*parent);
255255
externExprState*ExecInitCheck(List*qual,PlanState*parent);
256256
externList*ExecInitExprList(List*nodes,PlanState*parent);
257+
externExprState*ExecBuildAggTrans(AggState*aggstate,structAggStatePerPhaseData*phase,
258+
booldoSort,booldoHash);
257259
externProjectionInfo*ExecBuildProjectionInfo(List*targetList,
258260
ExprContext*econtext,
259261
TupleTableSlot*slot,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp