@@ -117,8 +117,7 @@ ExecAgg(Agg *node)
117117 */
118118
119119/*
120- * We loop retrieving groups until we find one matching
121- * node->plan.qual
120+ * We loop retrieving groups until we find one matching node->plan.qual
122121 */
123122do
124123{
@@ -141,14 +140,14 @@ ExecAgg(Agg *node)
141140MemSet (aggFuncInfo ,0 ,sizeof (AggFuncInfo )* nagg );
142141
143142noInitValue = (int * )palloc (sizeof (int )* nagg );
144- MemSet (noInitValue ,0 ,sizeof (noInitValue )* nagg );
143+ MemSet (noInitValue ,0 ,sizeof (int )* nagg );
145144
146145outerPlan = outerPlan (node );
147146oneTuple = NULL ;
148147
149148projInfo = aggstate -> csstate .cstate .cs_ProjInfo ;
150149
151- aggno = 0 ;
150+ aggno = -1 ;
152151foreach (alist ,node -> aggs )
153152{
154153Aggref * aggref = lfirst (alist );
@@ -159,6 +158,8 @@ ExecAgg(Agg *node)
159158xfn2_oid ,
160159finalfn_oid ;
161160
161+ aggno ++ ;
162+
162163/* ---------------------
163164 *find transfer functions of all the aggregates and initialize
164165 *their initial values
@@ -226,7 +227,6 @@ ExecAgg(Agg *node)
226227nulls [aggno ]= 1 ;
227228}
228229}
229- aggno ++ ;
230230}
231231
232232/* ----------------
@@ -257,7 +257,7 @@ ExecAgg(Agg *node)
257257tupValue = projInfo -> pi_tupValue ;
258258
259259/* initially, set all the values to NULL */
260- null_array = palloc (tupType -> natts );
260+ null_array = palloc (sizeof ( char ) * tupType -> natts );
261261for (aggno = 0 ;aggno < tupType -> natts ;aggno ++ )
262262null_array [aggno ]= 'n' ;
263263oneTuple = heap_formtuple (tupType ,tupValue ,null_array );
@@ -266,14 +266,14 @@ ExecAgg(Agg *node)
266266break ;
267267}
268268
269- aggno = 0 ;
269+ aggno = -1 ;
270270foreach (alist ,node -> aggs )
271271{
272272Aggref * aggref = lfirst (alist );
273273AttrNumber attnum ;
274274int2 attlen = 0 ;
275275Datum newVal = (Datum )NULL ;
276- AggFuncInfo * aggfns = & aggFuncInfo [aggno ];
276+ AggFuncInfo * aggfns = & aggFuncInfo [++ aggno ];
277277Datum args [2 ];
278278Node * tagnode = NULL ;
279279
@@ -388,7 +388,6 @@ ExecAgg(Agg *node)
388388 (FmgrValues * )& xfn2_val ,& isNull2 );
389389Assert (!isNull2 );
390390}
391- aggno ++ ;
392391}
393392
394393/*
@@ -407,11 +406,11 @@ ExecAgg(Agg *node)
407406 * --------------
408407 */
409408
410- aggno = 0 ;
409+ aggno = -1 ;
411410foreach (alist ,node -> aggs )
412411{
413412char * args [2 ];
414- AggFuncInfo * aggfns = & aggFuncInfo [aggno ];
413+ AggFuncInfo * aggfns = & aggFuncInfo [++ aggno ];
415414
416415if (noInitValue [aggno ])
417416{
@@ -450,7 +449,6 @@ ExecAgg(Agg *node)
450449value1 [aggno ]= value2 [aggno ];
451450else
452451elog (ERROR ,"ExecAgg: no valid transition functions??" );
453- aggno ++ ;
454452}
455453
456454/*
@@ -539,10 +537,10 @@ ExecInitAgg(Agg *node, EState *estate, Plan *parent)
539537
540538econtext = aggstate -> csstate .cstate .cs_ExprContext ;
541539econtext -> ecxt_values =
542- (Datum * )palloc (sizeof (Datum )* length (node -> aggs ));
540+ (Datum * )palloc (sizeof (Datum )* length (node -> aggs ));
543541MemSet (econtext -> ecxt_values ,0 ,sizeof (Datum )* length (node -> aggs ));
544- econtext -> ecxt_nulls = (char * )palloc (length (node -> aggs ));
545- MemSet (econtext -> ecxt_nulls ,0 ,length (node -> aggs ));
542+ econtext -> ecxt_nulls = (char * )palloc (sizeof ( char ) * length (node -> aggs ));
543+ MemSet (econtext -> ecxt_nulls ,0 ,sizeof ( char ) * length (node -> aggs ));
546544
547545/*
548546 * initializes child nodes
583581ExecCountSlotsAgg (Agg * node )
584582{
585583return ExecCountSlotsNode (outerPlan (node ))+
586- ExecCountSlotsNode (innerPlan (node ))+
587- AGG_NSLOTS ;
584+ ExecCountSlotsNode (innerPlan (node ))+
585+ AGG_NSLOTS ;
588586}
589587
590588/* ------------------------
@@ -654,8 +652,8 @@ aggGetAttr(TupleTableSlot *slot,
654652tempSlot = makeNode (TupleTableSlot );
655653tempSlot -> ttc_shouldFree = false;
656654tempSlot -> ttc_descIsNew = true;
657- tempSlot -> ttc_tupleDescriptor = (TupleDesc )NULL ,
658- tempSlot -> ttc_buffer = InvalidBuffer ;
655+ tempSlot -> ttc_tupleDescriptor = (TupleDesc )NULL ;
656+ tempSlot -> ttc_buffer = InvalidBuffer ;
659657tempSlot -> ttc_whichplan = -1 ;
660658
661659tup = heap_copytuple (heapTuple );
@@ -691,7 +689,7 @@ ExecReScanAgg(Agg *node, ExprContext *exprCtxt, Plan *parent)
691689
692690aggstate -> agg_done = FALSE;
693691MemSet (econtext -> ecxt_values ,0 ,sizeof (Datum )* length (node -> aggs ));
694- MemSet (econtext -> ecxt_nulls ,0 ,length (node -> aggs ));
692+ MemSet (econtext -> ecxt_nulls ,0 ,sizeof ( char ) * length (node -> aggs ));
695693
696694/*
697695 * if chgParam of subnode is not null then plan will be re-scanned by