Commit 1ec7679f authored by Andres Freund's avatar Andres Freund

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
parent 5ac4e9a1
...@@ -2779,12 +2779,7 @@ static void ...@@ -2779,12 +2779,7 @@ static void
ExecInitCoerceToDomain(ExprEvalStep *scratch, CoerceToDomain *ctest, ExecInitCoerceToDomain(ExprEvalStep *scratch, CoerceToDomain *ctest,
ExprState *state, Datum *resv, bool *resnull) ExprState *state, Datum *resv, bool *resnull)
{ {
ExprEvalStep scratch2 = {0};
DomainConstraintRef *constraint_ref; DomainConstraintRef *constraint_ref;
Datum *domainval = NULL;
bool *domainnull = NULL;
Datum *save_innermost_domainval;
bool *save_innermost_domainnull;
ListCell *l; ListCell *l;
scratch->d.domaincheck.resulttype = ctest->resulttype; scratch->d.domaincheck.resulttype = ctest->resulttype;
...@@ -2831,6 +2826,10 @@ ExecInitCoerceToDomain(ExprEvalStep *scratch, CoerceToDomain *ctest, ...@@ -2831,6 +2826,10 @@ ExecInitCoerceToDomain(ExprEvalStep *scratch, CoerceToDomain *ctest,
foreach(l, constraint_ref->constraints) foreach(l, constraint_ref->constraints)
{ {
DomainConstraintState *con = (DomainConstraintState *) lfirst(l); DomainConstraintState *con = (DomainConstraintState *) lfirst(l);
Datum *domainval = NULL;
bool *domainnull = NULL;
Datum *save_innermost_domainval;
bool *save_innermost_domainnull;
scratch->d.domaincheck.constraintname = con->name; scratch->d.domaincheck.constraintname = con->name;
...@@ -2862,6 +2861,8 @@ ExecInitCoerceToDomain(ExprEvalStep *scratch, CoerceToDomain *ctest, ...@@ -2862,6 +2861,8 @@ ExecInitCoerceToDomain(ExprEvalStep *scratch, CoerceToDomain *ctest,
*/ */
if (get_typlen(ctest->resulttype) == -1) if (get_typlen(ctest->resulttype) == -1)
{ {
ExprEvalStep scratch2 = {0};
/* Yes, so make output workspace for MAKE_READONLY */ /* Yes, so make output workspace for MAKE_READONLY */
domainval = (Datum *) palloc(sizeof(Datum)); domainval = (Datum *) palloc(sizeof(Datum));
domainnull = (bool *) palloc(sizeof(bool)); domainnull = (bool *) palloc(sizeof(bool));
...@@ -2932,8 +2933,6 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase, ...@@ -2932,8 +2933,6 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
ExprState *state = makeNode(ExprState); ExprState *state = makeNode(ExprState);
PlanState *parent = &aggstate->ss.ps; PlanState *parent = &aggstate->ss.ps;
ExprEvalStep scratch = {0}; ExprEvalStep scratch = {0};
int transno = 0;
int setoff = 0;
bool isCombine = DO_AGGSPLIT_COMBINE(aggstate->aggsplit); bool isCombine = DO_AGGSPLIT_COMBINE(aggstate->aggsplit);
LastAttnumInfo deform = {0, 0, 0}; LastAttnumInfo deform = {0, 0, 0};
...@@ -2947,7 +2946,7 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase, ...@@ -2947,7 +2946,7 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
* First figure out which slots, and how many columns from each, we're * First figure out which slots, and how many columns from each, we're
* going to need. * going to need.
*/ */
for (transno = 0; transno < aggstate->numtrans; transno++) for (int transno = 0; transno < aggstate->numtrans; transno++)
{ {
AggStatePerTrans pertrans = &aggstate->pertrans[transno]; AggStatePerTrans pertrans = &aggstate->pertrans[transno];
...@@ -2967,17 +2966,15 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase, ...@@ -2967,17 +2966,15 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
/* /*
* Emit instructions for each transition value / grouping set combination. * Emit instructions for each transition value / grouping set combination.
*/ */
for (transno = 0; transno < aggstate->numtrans; transno++) for (int transno = 0; transno < aggstate->numtrans; transno++)
{ {
AggStatePerTrans pertrans = &aggstate->pertrans[transno]; AggStatePerTrans pertrans = &aggstate->pertrans[transno];
int argno;
int setno;
FunctionCallInfo trans_fcinfo = pertrans->transfn_fcinfo; FunctionCallInfo trans_fcinfo = pertrans->transfn_fcinfo;
ListCell *arg;
ListCell *bail;
List *adjust_bailout = NIL; List *adjust_bailout = NIL;
NullableDatum *strictargs = NULL; NullableDatum *strictargs = NULL;
bool *strictnulls = NULL; bool *strictnulls = NULL;
int argno;
ListCell *bail;
/* /*
* If filter present, emit. Do so before evaluating the input, to * If filter present, emit. Do so before evaluating the input, to
...@@ -3071,6 +3068,8 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase, ...@@ -3071,6 +3068,8 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
} }
else if (pertrans->numSortCols == 0) else if (pertrans->numSortCols == 0)
{ {
ListCell *arg;
/* /*
* Normal transition function without ORDER BY / DISTINCT. * Normal transition function without ORDER BY / DISTINCT.
*/ */
...@@ -3113,6 +3112,7 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase, ...@@ -3113,6 +3112,7 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
*/ */
Datum *values = pertrans->sortslot->tts_values; Datum *values = pertrans->sortslot->tts_values;
bool *nulls = pertrans->sortslot->tts_isnull; bool *nulls = pertrans->sortslot->tts_isnull;
ListCell *arg;
strictnulls = nulls; strictnulls = nulls;
...@@ -3152,12 +3152,12 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase, ...@@ -3152,12 +3152,12 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
* grouping set). Do so for both sort and hash based computations, as * grouping set). Do so for both sort and hash based computations, as
* applicable. * applicable.
*/ */
setoff = 0;
if (doSort) if (doSort)
{ {
int processGroupingSets = Max(phase->numsets, 1); int processGroupingSets = Max(phase->numsets, 1);
int setoff = 0;
for (setno = 0; setno < processGroupingSets; setno++) for (int setno = 0; setno < processGroupingSets; setno++)
{ {
ExecBuildAggTransCall(state, aggstate, &scratch, trans_fcinfo, ExecBuildAggTransCall(state, aggstate, &scratch, trans_fcinfo,
pertrans, transno, setno, setoff, false); pertrans, transno, setno, setoff, false);
...@@ -3168,6 +3168,7 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase, ...@@ -3168,6 +3168,7 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
if (doHash) if (doHash)
{ {
int numHashes = aggstate->num_hashes; int numHashes = aggstate->num_hashes;
int setoff;
/* in MIXED mode, there'll be preceding transition values */ /* in MIXED mode, there'll be preceding transition values */
if (aggstate->aggstrategy != AGG_HASHED) if (aggstate->aggstrategy != AGG_HASHED)
...@@ -3175,7 +3176,7 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase, ...@@ -3175,7 +3176,7 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
else else
setoff = 0; setoff = 0;
for (setno = 0; setno < numHashes; setno++) for (int setno = 0; setno < numHashes; setno++)
{ {
ExecBuildAggTransCall(state, aggstate, &scratch, trans_fcinfo, ExecBuildAggTransCall(state, aggstate, &scratch, trans_fcinfo,
pertrans, transno, setno, setoff, true); pertrans, transno, setno, setoff, true);
...@@ -3204,6 +3205,8 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase, ...@@ -3204,6 +3205,8 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
Assert(as->d.agg_deserialize.jumpnull == -1); Assert(as->d.agg_deserialize.jumpnull == -1);
as->d.agg_deserialize.jumpnull = state->steps_len; as->d.agg_deserialize.jumpnull = state->steps_len;
} }
else
Assert(false);
} }
} }
...@@ -3338,7 +3341,6 @@ ExecBuildGroupingEqual(TupleDesc ldesc, TupleDesc rdesc, ...@@ -3338,7 +3341,6 @@ ExecBuildGroupingEqual(TupleDesc ldesc, TupleDesc rdesc,
{ {
ExprState *state = makeNode(ExprState); ExprState *state = makeNode(ExprState);
ExprEvalStep scratch = {0}; ExprEvalStep scratch = {0};
int natt;
int maxatt = -1; int maxatt = -1;
List *adjust_jumps = NIL; List *adjust_jumps = NIL;
ListCell *lc; ListCell *lc;
...@@ -3358,7 +3360,7 @@ ExecBuildGroupingEqual(TupleDesc ldesc, TupleDesc rdesc, ...@@ -3358,7 +3360,7 @@ ExecBuildGroupingEqual(TupleDesc ldesc, TupleDesc rdesc,
scratch.resnull = &state->resnull; scratch.resnull = &state->resnull;
/* compute max needed attribute */ /* compute max needed attribute */
for (natt = 0; natt < numCols; natt++) for (int natt = 0; natt < numCols; natt++)
{ {
int attno = keyColIdx[natt]; int attno = keyColIdx[natt];
...@@ -3388,7 +3390,7 @@ ExecBuildGroupingEqual(TupleDesc ldesc, TupleDesc rdesc, ...@@ -3388,7 +3390,7 @@ ExecBuildGroupingEqual(TupleDesc ldesc, TupleDesc rdesc,
* Start comparing at the last field (least significant sort key). That's * Start comparing at the last field (least significant sort key). That's
* the most likely to be different if we are dealing with sorted input. * the most likely to be different if we are dealing with sorted input.
*/ */
for (natt = numCols; --natt >= 0;) for (int natt = numCols; --natt >= 0;)
{ {
int attno = keyColIdx[natt]; int attno = keyColIdx[natt];
Form_pg_attribute latt = TupleDescAttr(ldesc, attno - 1); Form_pg_attribute latt = TupleDescAttr(ldesc, attno - 1);
......
...@@ -307,18 +307,14 @@ ExecReadyInterpretedExpr(ExprState *state) ...@@ -307,18 +307,14 @@ ExecReadyInterpretedExpr(ExprState *state)
* In the direct-threaded implementation, replace each opcode with the * In the direct-threaded implementation, replace each opcode with the
* address to jump to. (Use ExecEvalStepOp() to get back the opcode.) * address to jump to. (Use ExecEvalStepOp() to get back the opcode.)
*/ */
for (int off = 0; off < state->steps_len; off++)
{ {
int off; ExprEvalStep *op = &state->steps[off];
for (off = 0; off < state->steps_len; off++) op->opcode = EEO_OPCODE(op->opcode);
{
ExprEvalStep *op = &state->steps[off];
op->opcode = EEO_OPCODE(op->opcode);
}
state->flags |= EEO_FLAG_DIRECT_THREADED;
} }
state->flags |= EEO_FLAG_DIRECT_THREADED;
#endif /* EEO_USE_COMPUTED_GOTO */ #endif /* EEO_USE_COMPUTED_GOTO */
state->evalfunc_private = (void *) ExecInterpExpr; state->evalfunc_private = (void *) ExecInterpExpr;
...@@ -673,11 +669,11 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull) ...@@ -673,11 +669,11 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
{ {
FunctionCallInfo fcinfo = op->d.func.fcinfo_data; FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
NullableDatum *args = fcinfo->args; NullableDatum *args = fcinfo->args;
int argno; int nargs = op->d.func.nargs;
Datum d; Datum d;
/* strict function, so check for NULL args */ /* strict function, so check for NULL args */
for (argno = 0; argno < op->d.func.nargs; argno++) for (int argno = 0; argno < nargs; argno++)
{ {
if (args[argno].isnull) if (args[argno].isnull)
{ {
...@@ -1568,29 +1564,28 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull) ...@@ -1568,29 +1564,28 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
* Check that a strict aggregate transition / combination function's * Check that a strict aggregate transition / combination function's
* input is not NULL. * input is not NULL.
*/ */
EEO_CASE(EEOP_AGG_STRICT_INPUT_CHECK_NULLS)
EEO_CASE(EEOP_AGG_STRICT_INPUT_CHECK_ARGS)
{ {
int argno; NullableDatum *args = op->d.agg_strict_input_check.args;
bool *nulls = op->d.agg_strict_input_check.nulls;
int nargs = op->d.agg_strict_input_check.nargs; int nargs = op->d.agg_strict_input_check.nargs;
for (argno = 0; argno < nargs; argno++) for (int argno = 0; argno < nargs; argno++)
{ {
if (nulls[argno]) if (args[argno].isnull)
EEO_JUMP(op->d.agg_strict_input_check.jumpnull); EEO_JUMP(op->d.agg_strict_input_check.jumpnull);
} }
EEO_NEXT(); EEO_NEXT();
} }
EEO_CASE(EEOP_AGG_STRICT_INPUT_CHECK_ARGS) EEO_CASE(EEOP_AGG_STRICT_INPUT_CHECK_NULLS)
{ {
int argno; bool *nulls = op->d.agg_strict_input_check.nulls;
NullableDatum *args = op->d.agg_strict_input_check.args;
int nargs = op->d.agg_strict_input_check.nargs; int nargs = op->d.agg_strict_input_check.nargs;
for (argno = 0; argno < nargs; argno++) for (int argno = 0; argno < nargs; argno++)
{ {
if (args[argno].isnull) if (nulls[argno])
EEO_JUMP(op->d.agg_strict_input_check.jumpnull); EEO_JUMP(op->d.agg_strict_input_check.jumpnull);
} }
EEO_NEXT(); EEO_NEXT();
...@@ -1825,7 +1820,6 @@ ExecInterpExprStillValid(ExprState *state, ExprContext *econtext, bool *isNull) ...@@ -1825,7 +1820,6 @@ ExecInterpExprStillValid(ExprState *state, ExprContext *econtext, bool *isNull)
void void
CheckExprStillValid(ExprState *state, ExprContext *econtext) CheckExprStillValid(ExprState *state, ExprContext *econtext)
{ {
int i = 0;
TupleTableSlot *innerslot; TupleTableSlot *innerslot;
TupleTableSlot *outerslot; TupleTableSlot *outerslot;
TupleTableSlot *scanslot; TupleTableSlot *scanslot;
...@@ -1834,7 +1828,7 @@ CheckExprStillValid(ExprState *state, ExprContext *econtext) ...@@ -1834,7 +1828,7 @@ CheckExprStillValid(ExprState *state, ExprContext *econtext)
outerslot = econtext->ecxt_outertuple; outerslot = econtext->ecxt_outertuple;
scanslot = econtext->ecxt_scantuple; scanslot = econtext->ecxt_scantuple;
for (i = 0; i < state->steps_len; i++) for (int i = 0; i < state->steps_len; i++)
{ {
ExprEvalStep *op = &state->steps[i]; ExprEvalStep *op = &state->steps[i];
...@@ -2104,7 +2098,7 @@ ExecJustApplyFuncToCase(ExprState *state, ExprContext *econtext, bool *isnull) ...@@ -2104,7 +2098,7 @@ ExecJustApplyFuncToCase(ExprState *state, ExprContext *econtext, bool *isnull)
ExprEvalStep *op = &state->steps[0]; ExprEvalStep *op = &state->steps[0];
FunctionCallInfo fcinfo; FunctionCallInfo fcinfo;
NullableDatum *args; NullableDatum *args;
int argno; int nargs;
Datum d; Datum d;
/* /*
...@@ -2116,11 +2110,12 @@ ExecJustApplyFuncToCase(ExprState *state, ExprContext *econtext, bool *isnull) ...@@ -2116,11 +2110,12 @@ ExecJustApplyFuncToCase(ExprState *state, ExprContext *econtext, bool *isnull)
op++; op++;
nargs = op->d.func.nargs;
fcinfo = op->d.func.fcinfo_data; fcinfo = op->d.func.fcinfo_data;
args = fcinfo->args; args = fcinfo->args;
/* strict function, so check for NULL args */ /* strict function, so check for NULL args */
for (argno = 0; argno < op->d.func.nargs; argno++) for (int argno = 0; argno < nargs; argno++)
{ {
if (args[argno].isnull) if (args[argno].isnull)
{ {
...@@ -2258,13 +2253,11 @@ ExecInitInterpreter(void) ...@@ -2258,13 +2253,11 @@ ExecInitInterpreter(void)
/* Set up externally-visible pointer to dispatch table */ /* Set up externally-visible pointer to dispatch table */
if (dispatch_table == NULL) if (dispatch_table == NULL)
{ {
int i;
dispatch_table = (const void **) dispatch_table = (const void **)
DatumGetPointer(ExecInterpExpr(NULL, NULL, NULL)); DatumGetPointer(ExecInterpExpr(NULL, NULL, NULL));
/* build reverse lookup table */ /* build reverse lookup table */
for (i = 0; i < EEOP_LAST; i++) for (int i = 0; i < EEOP_LAST; i++)
{ {
reverse_dispatch_table[i].opcode = dispatch_table[i]; reverse_dispatch_table[i].opcode = dispatch_table[i];
reverse_dispatch_table[i].op = (ExprEvalOp) i; reverse_dispatch_table[i].op = (ExprEvalOp) i;
...@@ -2344,11 +2337,11 @@ ExecEvalFuncExprStrictFusage(ExprState *state, ExprEvalStep *op, ...@@ -2344,11 +2337,11 @@ ExecEvalFuncExprStrictFusage(ExprState *state, ExprEvalStep *op,
FunctionCallInfo fcinfo = op->d.func.fcinfo_data; FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
PgStat_FunctionCallUsage fcusage; PgStat_FunctionCallUsage fcusage;
NullableDatum *args = fcinfo->args; NullableDatum *args = fcinfo->args;
int argno; int nargs = op->d.func.nargs;
Datum d; Datum d;
/* strict function, so check for NULL args */ /* strict function, so check for NULL args */
for (argno = 0; argno < op->d.func.nargs; argno++) for (int argno = 0; argno < nargs; argno++)
{ {
if (args[argno].isnull) if (args[argno].isnull)
{ {
...@@ -2568,7 +2561,6 @@ ExecEvalRowNullInt(ExprState *state, ExprEvalStep *op, ...@@ -2568,7 +2561,6 @@ ExecEvalRowNullInt(ExprState *state, ExprEvalStep *op,
int32 tupTypmod; int32 tupTypmod;
TupleDesc tupDesc; TupleDesc tupDesc;
HeapTupleData tmptup; HeapTupleData tmptup;
int att;
*op->resnull = false; *op->resnull = false;
...@@ -2611,7 +2603,7 @@ ExecEvalRowNullInt(ExprState *state, ExprEvalStep *op, ...@@ -2611,7 +2603,7 @@ ExecEvalRowNullInt(ExprState *state, ExprEvalStep *op,
tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple); tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
tmptup.t_data = tuple; tmptup.t_data = tuple;
for (att = 1; att <= tupDesc->natts; att++) for (int att = 1; att <= tupDesc->natts; att++)
{ {
/* ignore dropped columns */ /* ignore dropped columns */
if (TupleDescAttr(tupDesc, att - 1)->attisdropped) if (TupleDescAttr(tupDesc, att - 1)->attisdropped)
...@@ -2694,8 +2686,6 @@ ExecEvalArrayExpr(ExprState *state, ExprEvalStep *op) ...@@ -2694,8 +2686,6 @@ ExecEvalArrayExpr(ExprState *state, ExprEvalStep *op)
int32 dataoffset; int32 dataoffset;
char *dat; char *dat;
int iitem; int iitem;
int elemoff;
int i;
subdata = (char **) palloc(nelems * sizeof(char *)); subdata = (char **) palloc(nelems * sizeof(char *));
subbitmaps = (bits8 **) palloc(nelems * sizeof(bits8 *)); subbitmaps = (bits8 **) palloc(nelems * sizeof(bits8 *));
...@@ -2703,7 +2693,7 @@ ExecEvalArrayExpr(ExprState *state, ExprEvalStep *op) ...@@ -2703,7 +2693,7 @@ ExecEvalArrayExpr(ExprState *state, ExprEvalStep *op)
subnitems = (int *) palloc(nelems * sizeof(int)); subnitems = (int *) palloc(nelems * sizeof(int));
/* loop through and get data area from each element */ /* loop through and get data area from each element */
for (elemoff = 0; elemoff < nelems; elemoff++) for (int elemoff = 0; elemoff < nelems; elemoff++)
{ {
Datum arraydatum; Datum arraydatum;
bool eisnull; bool eisnull;
...@@ -2805,7 +2795,7 @@ ExecEvalArrayExpr(ExprState *state, ExprEvalStep *op) ...@@ -2805,7 +2795,7 @@ ExecEvalArrayExpr(ExprState *state, ExprEvalStep *op)
/* setup for multi-D array */ /* setup for multi-D array */
dims[0] = outer_nelems; dims[0] = outer_nelems;
lbs[0] = 1; lbs[0] = 1;
for (i = 1; i < ndims; i++) for (int i = 1; i < ndims; i++)
{ {
dims[i] = elem_dims[i - 1]; dims[i] = elem_dims[i - 1];
lbs[i] = elem_lbs[i - 1]; lbs[i] = elem_lbs[i - 1];
...@@ -2832,7 +2822,7 @@ ExecEvalArrayExpr(ExprState *state, ExprEvalStep *op) ...@@ -2832,7 +2822,7 @@ ExecEvalArrayExpr(ExprState *state, ExprEvalStep *op)
dat = ARR_DATA_PTR(result); dat = ARR_DATA_PTR(result);
iitem = 0; iitem = 0;
for (i = 0; i < outer_nelems; i++) for (int i = 0; i < outer_nelems; i++)
{ {
memcpy(dat, subdata[i], subbytes[i]); memcpy(dat, subdata[i], subbytes[i]);
dat += subbytes[i]; dat += subbytes[i];
...@@ -2920,7 +2910,6 @@ ExecEvalMinMax(ExprState *state, ExprEvalStep *op) ...@@ -2920,7 +2910,6 @@ ExecEvalMinMax(ExprState *state, ExprEvalStep *op)
bool *nulls = op->d.minmax.nulls; bool *nulls = op->d.minmax.nulls;
FunctionCallInfo fcinfo = op->d.minmax.fcinfo_data; FunctionCallInfo fcinfo = op->d.minmax.fcinfo_data;
MinMaxOp operator = op->d.minmax.op; MinMaxOp operator = op->d.minmax.op;
int off;
/* set at initialization */ /* set at initialization */
Assert(fcinfo->args[0].isnull == false); Assert(fcinfo->args[0].isnull == false);
...@@ -2929,7 +2918,7 @@ ExecEvalMinMax(ExprState *state, ExprEvalStep *op) ...@@ -2929,7 +2918,7 @@ ExecEvalMinMax(ExprState *state, ExprEvalStep *op)
/* default to null result */ /* default to null result */
*op->resnull = true; *op->resnull = true;
for (off = 0; off < op->d.minmax.nelems; off++) for (int off = 0; off < op->d.minmax.nelems; off++)
{ {
/* ignore NULL inputs */ /* ignore NULL inputs */
if (nulls[off]) if (nulls[off])
...@@ -3461,7 +3450,6 @@ ExecEvalScalarArrayOp(ExprState *state, ExprEvalStep *op) ...@@ -3461,7 +3450,6 @@ ExecEvalScalarArrayOp(ExprState *state, ExprEvalStep *op)
int nitems; int nitems;
Datum result; Datum result;
bool resultnull; bool resultnull;
int i;
int16 typlen; int16 typlen;
bool typbyval; bool typbyval;
char typalign; char typalign;
...@@ -3529,7 +3517,7 @@ ExecEvalScalarArrayOp(ExprState *state, ExprEvalStep *op) ...@@ -3529,7 +3517,7 @@ ExecEvalScalarArrayOp(ExprState *state, ExprEvalStep *op)
bitmap = ARR_NULLBITMAP(arr); bitmap = ARR_NULLBITMAP(arr);
bitmask = 1; bitmask = 1;
for (i = 0; i < nitems; i++) for (int i = 0; i < nitems; i++)
{ {
Datum elt; Datum elt;
Datum thisresult; Datum thisresult;
...@@ -3641,7 +3629,6 @@ ExecEvalXmlExpr(ExprState *state, ExprEvalStep *op) ...@@ -3641,7 +3629,6 @@ ExecEvalXmlExpr(ExprState *state, ExprEvalStep *op)
{ {
XmlExpr *xexpr = op->d.xmlexpr.xexpr; XmlExpr *xexpr = op->d.xmlexpr.xexpr;
Datum value; Datum value;
int i;
*op->resnull = true; /* until we get a result */ *op->resnull = true; /* until we get a result */
*op->resvalue = (Datum) 0; *op->resvalue = (Datum) 0;
...@@ -3654,7 +3641,7 @@ ExecEvalXmlExpr(ExprState *state, ExprEvalStep *op) ...@@ -3654,7 +3641,7 @@ ExecEvalXmlExpr(ExprState *state, ExprEvalStep *op)
bool *argnull = op->d.xmlexpr.argnull; bool *argnull = op->d.xmlexpr.argnull;
List *values = NIL; List *values = NIL;
for (i = 0; i < list_length(xexpr->args); i++) for (int i = 0; i < list_length(xexpr->args); i++)
{ {
if (!argnull[i]) if (!argnull[i])
values = lappend(values, DatumGetPointer(argvalue[i])); values = lappend(values, DatumGetPointer(argvalue[i]));
...@@ -3675,6 +3662,7 @@ ExecEvalXmlExpr(ExprState *state, ExprEvalStep *op) ...@@ -3675,6 +3662,7 @@ ExecEvalXmlExpr(ExprState *state, ExprEvalStep *op)
StringInfoData buf; StringInfoData buf;
ListCell *lc; ListCell *lc;
ListCell *lc2; ListCell *lc2;
int i;
initStringInfo(&buf); initStringInfo(&buf);
...@@ -3968,7 +3956,6 @@ ExecEvalWholeRowVar(ExprState *state, ExprEvalStep *op, ExprContext *econtext) ...@@ -3968,7 +3956,6 @@ ExecEvalWholeRowVar(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
{ {
TupleDesc var_tupdesc; TupleDesc var_tupdesc;
TupleDesc slot_tupdesc; TupleDesc slot_tupdesc;
int i;
/* /*
* We really only care about numbers of attributes and data types. * We really only care about numbers of attributes and data types.
...@@ -4000,7 +3987,7 @@ ExecEvalWholeRowVar(ExprState *state, ExprEvalStep *op, ExprContext *econtext) ...@@ -4000,7 +3987,7 @@ ExecEvalWholeRowVar(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
slot_tupdesc->natts, slot_tupdesc->natts,
var_tupdesc->natts))); var_tupdesc->natts)));
for (i = 0; i < var_tupdesc->natts; i++) for (int i = 0; i < var_tupdesc->natts; i++)
{ {
Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i); Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
Form_pg_attribute sattr = TupleDescAttr(slot_tupdesc, i); Form_pg_attribute sattr = TupleDescAttr(slot_tupdesc, i);
...@@ -4095,11 +4082,10 @@ ExecEvalWholeRowVar(ExprState *state, ExprEvalStep *op, ExprContext *econtext) ...@@ -4095,11 +4082,10 @@ ExecEvalWholeRowVar(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
/* Check to see if any dropped attributes are non-null */ /* Check to see if any dropped attributes are non-null */
TupleDesc tupleDesc = slot->tts_tupleDescriptor; TupleDesc tupleDesc = slot->tts_tupleDescriptor;
TupleDesc var_tupdesc = op->d.wholerow.tupdesc; TupleDesc var_tupdesc = op->d.wholerow.tupdesc;
int i;
Assert(var_tupdesc->natts == tupleDesc->natts); Assert(var_tupdesc->natts == tupleDesc->natts);
for (i = 0; i < var_tupdesc->natts; i++) for (int i = 0; i < var_tupdesc->natts; i++)
{ {
Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i); Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
Form_pg_attribute sattr = TupleDescAttr(tupleDesc, i); Form_pg_attribute sattr = TupleDescAttr(tupleDesc, i);
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment