aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/nodeAgg.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>1998-01-15 19:00:16 +0000
committerBruce Momjian <bruce@momjian.us>1998-01-15 19:00:16 +0000
commit763ff8aef848d71da079049890786edffc3302d6 (patch)
treea1aed2a633c409071dd6d724b6db2bc7bf4fcb75 /src/backend/executor/nodeAgg.c
parentf22d8e6668e36a5855c35b04cc21a4d1593298d9 (diff)
downloadpostgresql-763ff8aef848d71da079049890786edffc3302d6.tar.gz
postgresql-763ff8aef848d71da079049890786edffc3302d6.zip
Remove Query->qry_aggs and qry_numaggs and replace with Query->hasAggs.
Pass List* of Aggregs into executor, and create needed array there. No longer need to double-processs Aggregs with second copy in Query. Fix crash when doing: select sum(x+1) from test where 1 > 0;
Diffstat (limited to 'src/backend/executor/nodeAgg.c')
-rw-r--r--src/backend/executor/nodeAgg.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c
index e268bf3423f..62970db8c7b 100644
--- a/src/backend/executor/nodeAgg.c
+++ b/src/backend/executor/nodeAgg.c
@@ -105,6 +105,7 @@ ExecAgg(Agg *node)
ProjectionInfo *projInfo;
TupleTableSlot *resultSlot;
HeapTuple oneTuple;
+ List *alist;
char *nulls;
bool isDone;
bool isNull = FALSE,
@@ -121,8 +122,17 @@ ExecAgg(Agg *node)
estate = node->plan.state;
econtext = aggstate->csstate.cstate.cs_ExprContext;
- aggregates = node->aggs;
- nagg = node->numAgg;
+ nagg = length(node->aggs);
+
+ aggregates = (Aggreg **)palloc(sizeof(Aggreg *) * nagg);
+
+ /* take List* and make it an array that can be quickly indexed */
+ alist = node->aggs;
+ for (i = 0; i < nagg; i++)
+ {
+ aggregates[i] = lfirst(alist);
+ alist = lnext(alist);
+ }
value1 = node->aggstate->csstate.cstate.cs_ExprContext->ecxt_values;
nulls = node->aggstate->csstate.cstate.cs_ExprContext->ecxt_nulls;
@@ -540,10 +550,10 @@ ExecInitAgg(Agg *node, EState *estate, Plan *parent)
econtext = aggstate->csstate.cstate.cs_ExprContext;
econtext->ecxt_values =
- (Datum *) palloc(sizeof(Datum) * node->numAgg);
- MemSet(econtext->ecxt_values, 0, sizeof(Datum) * node->numAgg);
- econtext->ecxt_nulls = (char *) palloc(node->numAgg);
- MemSet(econtext->ecxt_nulls, 0, node->numAgg);
+ (Datum *) palloc(sizeof(Datum) * length(node->aggs));
+ MemSet(econtext->ecxt_values, 0, sizeof(Datum) * length(node->aggs));
+ econtext->ecxt_nulls = (char *) palloc(length(node->aggs));
+ MemSet(econtext->ecxt_nulls, 0, length(node->aggs));
/*
* initializes child nodes