@@ -117,8 +117,7 @@ ExecAgg(Agg *node)
117
117
*/
118
118
119
119
/*
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
122
121
*/
123
122
do
124
123
{
@@ -141,14 +140,14 @@ ExecAgg(Agg *node)
141
140
MemSet (aggFuncInfo , 0 , sizeof (AggFuncInfo ) * nagg );
142
141
143
142
noInitValue = (int * ) palloc (sizeof (int ) * nagg );
144
- MemSet (noInitValue , 0 , sizeof (noInitValue ) * nagg );
143
+ MemSet (noInitValue , 0 , sizeof (int ) * nagg );
145
144
146
145
outerPlan = outerPlan (node );
147
146
oneTuple = NULL ;
148
147
149
148
projInfo = aggstate -> csstate .cstate .cs_ProjInfo ;
150
149
151
- aggno = 0 ;
150
+ aggno = -1 ;
152
151
foreach (alist , node -> aggs )
153
152
{
154
153
Aggref * aggref = lfirst (alist );
@@ -159,6 +158,8 @@ ExecAgg(Agg *node)
159
158
xfn2_oid ,
160
159
finalfn_oid ;
161
160
161
+ aggno ++ ;
162
+
162
163
/* ---------------------
163
164
* find transfer functions of all the aggregates and initialize
164
165
* their initial values
@@ -226,7 +227,6 @@ ExecAgg(Agg *node)
226
227
nulls [aggno ] = 1 ;
227
228
}
228
229
}
229
- aggno ++ ;
230
230
}
231
231
232
232
/* ----------------
@@ -257,7 +257,7 @@ ExecAgg(Agg *node)
257
257
tupValue = projInfo -> pi_tupValue ;
258
258
259
259
/* initially, set all the values to NULL */
260
- null_array = palloc (tupType -> natts );
260
+ null_array = palloc (sizeof ( char ) * tupType -> natts );
261
261
for (aggno = 0 ; aggno < tupType -> natts ; aggno ++ )
262
262
null_array [aggno ] = 'n' ;
263
263
oneTuple = heap_formtuple (tupType , tupValue , null_array );
@@ -266,14 +266,14 @@ ExecAgg(Agg *node)
266
266
break ;
267
267
}
268
268
269
- aggno = 0 ;
269
+ aggno = -1 ;
270
270
foreach (alist , node -> aggs )
271
271
{
272
272
Aggref * aggref = lfirst (alist );
273
273
AttrNumber attnum ;
274
274
int2 attlen = 0 ;
275
275
Datum newVal = (Datum ) NULL ;
276
- AggFuncInfo * aggfns = & aggFuncInfo [aggno ];
276
+ AggFuncInfo * aggfns = & aggFuncInfo [++ aggno ];
277
277
Datum args [2 ];
278
278
Node * tagnode = NULL ;
279
279
@@ -388,7 +388,6 @@ ExecAgg(Agg *node)
388
388
(FmgrValues * ) & xfn2_val , & isNull2 );
389
389
Assert (!isNull2 );
390
390
}
391
- aggno ++ ;
392
391
}
393
392
394
393
/*
@@ -407,11 +406,11 @@ ExecAgg(Agg *node)
407
406
* --------------
408
407
*/
409
408
410
- aggno = 0 ;
409
+ aggno = -1 ;
411
410
foreach (alist , node -> aggs )
412
411
{
413
412
char * args [2 ];
414
- AggFuncInfo * aggfns = & aggFuncInfo [aggno ];
413
+ AggFuncInfo * aggfns = & aggFuncInfo [++ aggno ];
415
414
416
415
if (noInitValue [aggno ])
417
416
{
@@ -450,7 +449,6 @@ ExecAgg(Agg *node)
450
449
value1 [aggno ] = value2 [aggno ];
451
450
else
452
451
elog (ERROR , "ExecAgg: no valid transition functions??" );
453
- aggno ++ ;
454
452
}
455
453
456
454
/*
@@ -539,10 +537,10 @@ ExecInitAgg(Agg *node, EState *estate, Plan *parent)
539
537
540
538
econtext = aggstate -> csstate .cstate .cs_ExprContext ;
541
539
econtext -> ecxt_values =
542
- (Datum * ) palloc (sizeof (Datum ) * length (node -> aggs ));
540
+ (Datum * ) palloc (sizeof (Datum ) * length (node -> aggs ));
543
541
MemSet (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 ));
546
544
547
545
/*
548
546
* initializes child nodes
583
581
ExecCountSlotsAgg (Agg * node )
584
582
{
585
583
return ExecCountSlotsNode (outerPlan (node )) +
586
- ExecCountSlotsNode (innerPlan (node )) +
587
- AGG_NSLOTS ;
584
+ ExecCountSlotsNode (innerPlan (node )) +
585
+ AGG_NSLOTS ;
588
586
}
589
587
590
588
/* ------------------------
@@ -654,8 +652,8 @@ aggGetAttr(TupleTableSlot *slot,
654
652
tempSlot = makeNode (TupleTableSlot );
655
653
tempSlot -> ttc_shouldFree = false;
656
654
tempSlot -> 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 ;
659
657
tempSlot -> ttc_whichplan = -1 ;
660
658
661
659
tup = heap_copytuple (heapTuple );
@@ -691,7 +689,7 @@ ExecReScanAgg(Agg *node, ExprContext *exprCtxt, Plan *parent)
691
689
692
690
aggstate -> agg_done = FALSE;
693
691
MemSet (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 ));
695
693
696
694
/*
697
695
* if chgParam of subnode is not null then plan will be re-scanned by
0 commit comments