Skip to content

Commit 1ec7679

Browse files
committed
expression eval, jit: Minor code cleanups.
This mostly consists of using C99 style for loops, moving variables into narrower scopes, and a smattering of other minor improvements. Done separately to make it easier to review patches with actual functional changes. Author: Andres Freund Discussion: https://postgr.es/m/20191023163849.sosqbfs5yenocez3@alap3.anarazel.de
1 parent 5ac4e9a commit 1ec7679

File tree

3 files changed

+240
-257
lines changed

3 files changed

+240
-257
lines changed

src/backend/executor/execExpr.c

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2779,12 +2779,7 @@ static void
27792779
ExecInitCoerceToDomain(ExprEvalStep *scratch, CoerceToDomain *ctest,
27802780
ExprState *state, Datum *resv, bool *resnull)
27812781
{
2782-
ExprEvalStep scratch2 = {0};
27832782
DomainConstraintRef *constraint_ref;
2784-
Datum *domainval = NULL;
2785-
bool *domainnull = NULL;
2786-
Datum *save_innermost_domainval;
2787-
bool *save_innermost_domainnull;
27882783
ListCell *l;
27892784

27902785
scratch->d.domaincheck.resulttype = ctest->resulttype;
@@ -2831,6 +2826,10 @@ ExecInitCoerceToDomain(ExprEvalStep *scratch, CoerceToDomain *ctest,
28312826
foreach(l, constraint_ref->constraints)
28322827
{
28332828
DomainConstraintState *con = (DomainConstraintState *) lfirst(l);
2829+
Datum *domainval = NULL;
2830+
bool *domainnull = NULL;
2831+
Datum *save_innermost_domainval;
2832+
bool *save_innermost_domainnull;
28342833

28352834
scratch->d.domaincheck.constraintname = con->name;
28362835

@@ -2862,6 +2861,8 @@ ExecInitCoerceToDomain(ExprEvalStep *scratch, CoerceToDomain *ctest,
28622861
*/
28632862
if (get_typlen(ctest->resulttype) == -1)
28642863
{
2864+
ExprEvalStep scratch2 = {0};
2865+
28652866
/* Yes, so make output workspace for MAKE_READONLY */
28662867
domainval = (Datum *) palloc(sizeof(Datum));
28672868
domainnull = (bool *) palloc(sizeof(bool));
@@ -2932,8 +2933,6 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
29322933
ExprState *state = makeNode(ExprState);
29332934
PlanState *parent = &aggstate->ss.ps;
29342935
ExprEvalStep scratch = {0};
2935-
int transno = 0;
2936-
int setoff = 0;
29372936
bool isCombine = DO_AGGSPLIT_COMBINE(aggstate->aggsplit);
29382937
LastAttnumInfo deform = {0, 0, 0};
29392938

@@ -2947,7 +2946,7 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
29472946
* First figure out which slots, and how many columns from each, we're
29482947
* going to need.
29492948
*/
2950-
for (transno = 0; transno < aggstate->numtrans; transno++)
2949+
for (int transno = 0; transno < aggstate->numtrans; transno++)
29512950
{
29522951
AggStatePerTrans pertrans = &aggstate->pertrans[transno];
29532952

@@ -2967,17 +2966,15 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
29672966
/*
29682967
* Emit instructions for each transition value / grouping set combination.
29692968
*/
2970-
for (transno = 0; transno < aggstate->numtrans; transno++)
2969+
for (int transno = 0; transno < aggstate->numtrans; transno++)
29712970
{
29722971
AggStatePerTrans pertrans = &aggstate->pertrans[transno];
2973-
int argno;
2974-
int setno;
29752972
FunctionCallInfo trans_fcinfo = pertrans->transfn_fcinfo;
2976-
ListCell *arg;
2977-
ListCell *bail;
29782973
List *adjust_bailout = NIL;
29792974
NullableDatum *strictargs = NULL;
29802975
bool *strictnulls = NULL;
2976+
int argno;
2977+
ListCell *bail;
29812978

29822979
/*
29832980
* If filter present, emit. Do so before evaluating the input, to
@@ -3071,6 +3068,8 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
30713068
}
30723069
else if (pertrans->numSortCols == 0)
30733070
{
3071+
ListCell *arg;
3072+
30743073
/*
30753074
* Normal transition function without ORDER BY / DISTINCT.
30763075
*/
@@ -3113,6 +3112,7 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
31133112
*/
31143113
Datum *values = pertrans->sortslot->tts_values;
31153114
bool *nulls = pertrans->sortslot->tts_isnull;
3115+
ListCell *arg;
31163116

31173117
strictnulls = nulls;
31183118

@@ -3152,12 +3152,12 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
31523152
* grouping set). Do so for both sort and hash based computations, as
31533153
* applicable.
31543154
*/
3155-
setoff = 0;
31563155
if (doSort)
31573156
{
31583157
int processGroupingSets = Max(phase->numsets, 1);
3158+
int setoff = 0;
31593159

3160-
for (setno = 0; setno < processGroupingSets; setno++)
3160+
for (int setno = 0; setno < processGroupingSets; setno++)
31613161
{
31623162
ExecBuildAggTransCall(state, aggstate, &scratch, trans_fcinfo,
31633163
pertrans, transno, setno, setoff, false);
@@ -3168,14 +3168,15 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
31683168
if (doHash)
31693169
{
31703170
int numHashes = aggstate->num_hashes;
3171+
int setoff;
31713172

31723173
/* in MIXED mode, there'll be preceding transition values */
31733174
if (aggstate->aggstrategy != AGG_HASHED)
31743175
setoff = aggstate->maxsets;
31753176
else
31763177
setoff = 0;
31773178

3178-
for (setno = 0; setno < numHashes; setno++)
3179+
for (int setno = 0; setno < numHashes; setno++)
31793180
{
31803181
ExecBuildAggTransCall(state, aggstate, &scratch, trans_fcinfo,
31813182
pertrans, transno, setno, setoff, true);
@@ -3204,6 +3205,8 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
32043205
Assert(as->d.agg_deserialize.jumpnull == -1);
32053206
as->d.agg_deserialize.jumpnull = state->steps_len;
32063207
}
3208+
else
3209+
Assert(false);
32073210
}
32083211
}
32093212

@@ -3338,7 +3341,6 @@ ExecBuildGroupingEqual(TupleDesc ldesc, TupleDesc rdesc,
33383341
{
33393342
ExprState *state = makeNode(ExprState);
33403343
ExprEvalStep scratch = {0};
3341-
int natt;
33423344
int maxatt = -1;
33433345
List *adjust_jumps = NIL;
33443346
ListCell *lc;
@@ -3358,7 +3360,7 @@ ExecBuildGroupingEqual(TupleDesc ldesc, TupleDesc rdesc,
33583360
scratch.resnull = &state->resnull;
33593361

33603362
/* compute max needed attribute */
3361-
for (natt = 0; natt < numCols; natt++)
3363+
for (int natt = 0; natt < numCols; natt++)
33623364
{
33633365
int attno = keyColIdx[natt];
33643366

@@ -3388,7 +3390,7 @@ ExecBuildGroupingEqual(TupleDesc ldesc, TupleDesc rdesc,
33883390
* Start comparing at the last field (least significant sort key). That's
33893391
* the most likely to be different if we are dealing with sorted input.
33903392
*/
3391-
for (natt = numCols; --natt >= 0;)
3393+
for (int natt = numCols; --natt >= 0;)
33923394
{
33933395
int attno = keyColIdx[natt];
33943396
Form_pg_attribute latt = TupleDescAttr(ldesc, attno - 1);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy