Tighten up sanity checks for parallel aggregate in execQual.c.

David Rowley
This commit is contained in:
Robert Haas 2016-04-27 12:05:35 -04:00
parent b33dc77665
commit cf402ba734
1 changed files with 23 additions and 16 deletions

View File

@ -4510,28 +4510,35 @@ ExecInitExpr(Expr *node, PlanState *parent)
case T_Aggref:
{
AggrefExprState *astate = makeNode(AggrefExprState);
AggState *aggstate = (AggState *) parent;
Aggref *aggref = (Aggref *) node;
astate->xprstate.evalfunc = (ExprStateEvalFunc) ExecEvalAggref;
if (parent && IsA(parent, AggState))
{
AggState *aggstate = (AggState *) parent;
Aggref *aggref = (Aggref *) node;
if (aggstate->finalizeAggs &&
aggref->aggoutputtype != aggref->aggtype)
{
/* planner messed up */
elog(ERROR, "Aggref aggoutputtype must match aggtype");
}
aggstate->aggs = lcons(astate, aggstate->aggs);
aggstate->numaggs++;
}
else
if (!aggstate || !IsA(aggstate, AggState))
{
/* planner messed up */
elog(ERROR, "Aggref found in non-Agg plan node");
}
if (aggref->aggpartial == aggstate->finalizeAggs)
{
/* planner messed up */
if (aggref->aggpartial)
elog(ERROR, "partial Aggref found in finalize agg plan node");
else
elog(ERROR, "non-partial Aggref found in non-finalize agg plan node");
}
if (aggref->aggcombine != aggstate->combineStates)
{
/* planner messed up */
if (aggref->aggcombine)
elog(ERROR, "combine Aggref found in non-combine agg plan node");
else
elog(ERROR, "non-combine Aggref found in combine agg plan node");
}
aggstate->aggs = lcons(astate, aggstate->aggs);
aggstate->numaggs++;
state = (ExprState *) astate;
}
break;