|
|
|
@ -4510,28 +4510,35 @@ ExecInitExpr(Expr *node, PlanState *parent) |
|
|
|
|
case T_Aggref: |
|
|
|
|
{ |
|
|
|
|
AggrefExprState *astate = makeNode(AggrefExprState); |
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
astate->xprstate.evalfunc = (ExprStateEvalFunc) ExecEvalAggref; |
|
|
|
|
if (!aggstate || !IsA(aggstate, AggState)) |
|
|
|
|
{ |
|
|
|
|
/* planner messed up */ |
|
|
|
|
elog(ERROR, "Aggref aggoutputtype must match aggtype"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
aggstate->aggs = lcons(astate, aggstate->aggs); |
|
|
|
|
aggstate->numaggs++; |
|
|
|
|
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 */ |
|
|
|
|
elog(ERROR, "Aggref found in non-Agg plan node"); |
|
|
|
|
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; |
|
|
|
|