Skip to content

Commit 1fdb7f9

Browse files
committed
expression eval: Don't redundantly keep track of AggState.
It's already tracked via ExprState->parent, so we don't need to also include it in ExprEvalStep. When that code originally was written ExprState->parent didn't exist, but it since has been introduced in 6719b23. Author: Andres Freund Discussion: https://postgr.es/m/[email protected]
1 parent 1ec7679 commit 1fdb7f9

File tree

5 files changed

+20
-31
lines changed

5 files changed

+20
-31
lines changed

src/backend/executor/execExpr.c

-5
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,6 @@ ExecInitExprRec(Expr *node, ExprState *state,
810810
elog(ERROR, "GroupingFunc found in non-Agg plan node");
811811

812812
scratch.opcode = EEOP_GROUPING_FUNC;
813-
scratch.d.grouping_func.parent = (AggState *) state->parent;
814813

815814
agg = (Agg *) (state->parent->plan);
816815

@@ -3050,7 +3049,6 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
30503049
else
30513050
scratch.opcode = EEOP_AGG_DESERIALIZE;
30523051

3053-
scratch.d.agg_deserialize.aggstate = aggstate;
30543052
scratch.d.agg_deserialize.fcinfo_data = ds_fcinfo;
30553053
scratch.d.agg_deserialize.jumpnull = -1; /* adjust later */
30563054
scratch.resvalue = &trans_fcinfo->args[argno + 1].value;
@@ -3252,7 +3250,6 @@ ExecBuildAggTransCall(ExprState *state, AggState *aggstate,
32523250
pertrans->initValueIsNull)
32533251
{
32543252
scratch->opcode = EEOP_AGG_INIT_TRANS;
3255-
scratch->d.agg_init_trans.aggstate = aggstate;
32563253
scratch->d.agg_init_trans.pertrans = pertrans;
32573254
scratch->d.agg_init_trans.setno = setno;
32583255
scratch->d.agg_init_trans.setoff = setoff;
@@ -3269,7 +3266,6 @@ ExecBuildAggTransCall(ExprState *state, AggState *aggstate,
32693266
fcinfo->flinfo->fn_strict)
32703267
{
32713268
scratch->opcode = EEOP_AGG_STRICT_TRANS_CHECK;
3272-
scratch->d.agg_strict_trans_check.aggstate = aggstate;
32733269
scratch->d.agg_strict_trans_check.setno = setno;
32743270
scratch->d.agg_strict_trans_check.setoff = setoff;
32753271
scratch->d.agg_strict_trans_check.transno = transno;
@@ -3294,7 +3290,6 @@ ExecBuildAggTransCall(ExprState *state, AggState *aggstate,
32943290
else
32953291
scratch->opcode = EEOP_AGG_ORDERED_TRANS_TUPLE;
32963292

3297-
scratch->d.agg_trans.aggstate = aggstate;
32983293
scratch->d.agg_trans.pertrans = pertrans;
32993294
scratch->d.agg_trans.setno = setno;
33003295
scratch->d.agg_trans.setoff = setoff;

src/backend/executor/execExprInterp.c

+7-10
Original file line numberDiff line numberDiff line change
@@ -1544,7 +1544,7 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
15441544
EEO_CASE(EEOP_AGG_DESERIALIZE)
15451545
{
15461546
FunctionCallInfo fcinfo = op->d.agg_deserialize.fcinfo_data;
1547-
AggState *aggstate = op->d.agg_deserialize.aggstate;
1547+
AggState *aggstate = castNode(AggState, state->parent);
15481548
MemoryContext oldContext;
15491549

15501550
/*
@@ -1596,10 +1596,9 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
15961596
*/
15971597
EEO_CASE(EEOP_AGG_INIT_TRANS)
15981598
{
1599-
AggState *aggstate;
1599+
AggState *aggstate = castNode(AggState, state->parent);
16001600
AggStatePerGroup pergroup;
16011601

1602-
aggstate = op->d.agg_init_trans.aggstate;
16031602
pergroup = &aggstate->all_pergroups
16041603
[op->d.agg_init_trans.setoff]
16051604
[op->d.agg_init_trans.transno];
@@ -1624,10 +1623,9 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
16241623
/* check that a strict aggregate's input isn't NULL */
16251624
EEO_CASE(EEOP_AGG_STRICT_TRANS_CHECK)
16261625
{
1627-
AggState *aggstate;
1626+
AggState *aggstate = castNode(AggState, state->parent);
16281627
AggStatePerGroup pergroup;
16291628

1630-
aggstate = op->d.agg_strict_trans_check.aggstate;
16311629
pergroup = &aggstate->all_pergroups
16321630
[op->d.agg_strict_trans_check.setoff]
16331631
[op->d.agg_strict_trans_check.transno];
@@ -1645,14 +1643,13 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
16451643
*/
16461644
EEO_CASE(EEOP_AGG_PLAIN_TRANS_BYVAL)
16471645
{
1648-
AggState *aggstate;
1646+
AggState *aggstate = castNode(AggState, state->parent);
16491647
AggStatePerTrans pertrans;
16501648
AggStatePerGroup pergroup;
16511649
FunctionCallInfo fcinfo;
16521650
MemoryContext oldContext;
16531651
Datum newVal;
16541652

1655-
aggstate = op->d.agg_trans.aggstate;
16561653
pertrans = op->d.agg_trans.pertrans;
16571654

16581655
pergroup = &aggstate->all_pergroups
@@ -1696,14 +1693,13 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
16961693
*/
16971694
EEO_CASE(EEOP_AGG_PLAIN_TRANS)
16981695
{
1699-
AggState *aggstate;
1696+
AggState *aggstate = castNode(AggState, state->parent);
17001697
AggStatePerTrans pertrans;
17011698
AggStatePerGroup pergroup;
17021699
FunctionCallInfo fcinfo;
17031700
MemoryContext oldContext;
17041701
Datum newVal;
17051702

1706-
aggstate = op->d.agg_trans.aggstate;
17071703
pertrans = op->d.agg_trans.pertrans;
17081704

17091705
pergroup = &aggstate->all_pergroups
@@ -3846,8 +3842,9 @@ ExecEvalXmlExpr(ExprState *state, ExprEvalStep *op)
38463842
void
38473843
ExecEvalGroupingFunc(ExprState *state, ExprEvalStep *op)
38483844
{
3845+
AggState *aggstate = castNode(AggState, state->parent);
38493846
int result = 0;
3850-
Bitmapset *grouped_cols = op->d.grouping_func.parent->grouped_cols;
3847+
Bitmapset *grouped_cols = aggstate->grouped_cols;
38513848
ListCell *lc;
38523849

38533850
foreach(lc, op->d.grouping_func.clauses)

src/backend/jit/llvm/llvmjit_expr.c

+12-11
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ llvm_compile_expr(ExprState *state)
8585
/* state itself */
8686
LLVMValueRef v_state;
8787
LLVMValueRef v_econtext;
88+
LLVMValueRef v_parent;
8889

8990
/* returnvalue */
9091
LLVMValueRef v_isnullp;
@@ -173,6 +174,9 @@ llvm_compile_expr(ExprState *state)
173174
v_tmpisnullp = LLVMBuildStructGEP(b, v_state,
174175
FIELDNO_EXPRSTATE_RESNULL,
175176
"v.state.resnull");
177+
v_parent = l_load_struct_gep(b, v_state,
178+
FIELDNO_EXPRSTATE_PARENT,
179+
"v.state.parent");
176180

177181
/* build global slots */
178182
v_scanslot = l_load_struct_gep(b, v_econtext,
@@ -1989,7 +1993,7 @@ llvm_compile_expr(ExprState *state)
19891993
LLVMValueRef v_tmpcontext;
19901994
LLVMValueRef v_oldcontext;
19911995

1992-
aggstate = op->d.agg_deserialize.aggstate;
1996+
aggstate = castNode(AggState, state->parent);
19931997
fcinfo = op->d.agg_deserialize.fcinfo_data;
19941998

19951999
v_tmpcontext =
@@ -2078,7 +2082,6 @@ llvm_compile_expr(ExprState *state)
20782082

20792083
case EEOP_AGG_INIT_TRANS:
20802084
{
2081-
AggState *aggstate;
20822085
AggStatePerTrans pertrans;
20832086

20842087
LLVMValueRef v_aggstatep;
@@ -2095,11 +2098,10 @@ llvm_compile_expr(ExprState *state)
20952098

20962099
LLVMBasicBlockRef b_init;
20972100

2098-
aggstate = op->d.agg_init_trans.aggstate;
20992101
pertrans = op->d.agg_init_trans.pertrans;
21002102

2101-
v_aggstatep = l_ptr_const(aggstate,
2102-
l_ptr(StructAggState));
2103+
v_aggstatep =
2104+
LLVMBuildBitCast(b, v_parent, l_ptr(StructAggState), "");
21032105
v_pertransp = l_ptr_const(pertrans,
21042106
l_ptr(StructAggStatePerTransData));
21052107

@@ -2176,7 +2178,6 @@ llvm_compile_expr(ExprState *state)
21762178

21772179
case EEOP_AGG_STRICT_TRANS_CHECK:
21782180
{
2179-
AggState *aggstate;
21802181
LLVMValueRef v_setoff,
21812182
v_transno;
21822183

@@ -2188,8 +2189,8 @@ llvm_compile_expr(ExprState *state)
21882189

21892190
int jumpnull = op->d.agg_strict_trans_check.jumpnull;
21902191

2191-
aggstate = op->d.agg_strict_trans_check.aggstate;
2192-
v_aggstatep = l_ptr_const(aggstate, l_ptr(StructAggState));
2192+
v_aggstatep =
2193+
LLVMBuildBitCast(b, v_parent, l_ptr(StructAggState), "");
21932194

21942195
/*
21952196
* pergroup = &aggstate->all_pergroups
@@ -2256,13 +2257,13 @@ llvm_compile_expr(ExprState *state)
22562257
LLVMValueRef v_tmpcontext;
22572258
LLVMValueRef v_oldcontext;
22582259

2259-
aggstate = op->d.agg_trans.aggstate;
2260+
aggstate = castNode(AggState, state->parent);
22602261
pertrans = op->d.agg_trans.pertrans;
22612262

22622263
fcinfo = pertrans->transfn_fcinfo;
22632264

2264-
v_aggstatep = l_ptr_const(aggstate,
2265-
l_ptr(StructAggState));
2265+
v_aggstatep =
2266+
LLVMBuildBitCast(b, v_parent, l_ptr(StructAggState), "");
22662267
v_pertransp = l_ptr_const(pertrans,
22672268
l_ptr(StructAggStatePerTransData));
22682269

src/include/executor/execExpr.h

-5
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,6 @@ typedef struct ExprEvalStep
569569
/* for EEOP_GROUPING_FUNC */
570570
struct
571571
{
572-
AggState *parent; /* parent Agg */
573572
List *clauses; /* integer list of column numbers */
574573
} grouping_func;
575574

@@ -597,7 +596,6 @@ typedef struct ExprEvalStep
597596
/* for EEOP_AGG_*DESERIALIZE */
598597
struct
599598
{
600-
AggState *aggstate;
601599
FunctionCallInfo fcinfo_data;
602600
int jumpnull;
603601
} agg_deserialize;
@@ -625,7 +623,6 @@ typedef struct ExprEvalStep
625623
/* for EEOP_AGG_INIT_TRANS */
626624
struct
627625
{
628-
AggState *aggstate;
629626
AggStatePerTrans pertrans;
630627
ExprContext *aggcontext;
631628
int setno;
@@ -637,7 +634,6 @@ typedef struct ExprEvalStep
637634
/* for EEOP_AGG_STRICT_TRANS_CHECK */
638635
struct
639636
{
640-
AggState *aggstate;
641637
int setno;
642638
int transno;
643639
int setoff;
@@ -647,7 +643,6 @@ typedef struct ExprEvalStep
647643
/* for EEOP_AGG_{PLAIN,ORDERED}_TRANS* */
648644
struct
649645
{
650-
AggState *aggstate;
651646
AggStatePerTrans pertrans;
652647
ExprContext *aggcontext;
653648
int setno;

src/include/nodes/execnodes.h

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ typedef struct ExprState
104104
int steps_len; /* number of steps currently */
105105
int steps_alloc; /* allocated length of steps array */
106106

107+
#define FIELDNO_EXPRSTATE_PARENT 11
107108
struct PlanState *parent; /* parent PlanState node, if any */
108109
ParamListInfo ext_params; /* for compiling PARAM_EXTERN nodes */
109110

0 commit comments

Comments
 (0)