@@ -4510,28 +4510,35 @@ ExecInitExpr(Expr *node, PlanState *parent)
45104510case T_Aggref :
45114511{
45124512AggrefExprState * astate = makeNode (AggrefExprState );
4513+ AggState * aggstate = (AggState * )parent ;
4514+ Aggref * aggref = (Aggref * )node ;
45134515
45144516astate -> xprstate .evalfunc = (ExprStateEvalFunc )ExecEvalAggref ;
4515- if (parent && IsA (parent ,AggState ))
4517+ if (! aggstate || ! IsA (aggstate ,AggState ))
45164518{
4517- AggState * aggstate = (AggState * )parent ;
4518- Aggref * aggref = (Aggref * )node ;
4519-
4520- if (aggstate -> finalizeAggs &&
4521- aggref -> aggoutputtype != aggref -> aggtype )
4522- {
4523- /* planner messed up */
4524- elog (ERROR ,"Aggref aggoutputtype must match aggtype" );
4525- }
4526-
4527- aggstate -> aggs = lcons (astate ,aggstate -> aggs );
4528- aggstate -> numaggs ++ ;
4519+ /* planner messed up */
4520+ elog (ERROR ,"Aggref found in non-Agg plan node" );
45294521}
4530- else
4522+ if ( aggref -> aggpartial == aggstate -> finalizeAggs )
45314523{
45324524/* planner messed up */
4533- elog (ERROR ,"Aggref found in non-Agg plan node" );
4525+ if (aggref -> aggpartial )
4526+ elog (ERROR ,"partial Aggref found in finalize agg plan node" );
4527+ else
4528+ elog (ERROR ,"non-partial Aggref found in non-finalize agg plan node" );
45344529}
4530+
4531+ if (aggref -> aggcombine != aggstate -> combineStates )
4532+ {
4533+ /* planner messed up */
4534+ if (aggref -> aggcombine )
4535+ elog (ERROR ,"combine Aggref found in non-combine agg plan node" );
4536+ else
4537+ elog (ERROR ,"non-combine Aggref found in combine agg plan node" );
4538+ }
4539+
4540+ aggstate -> aggs = lcons (astate ,aggstate -> aggs );
4541+ aggstate -> numaggs ++ ;
45354542state = (ExprState * )astate ;
45364543}
45374544break ;