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