aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/nodeAgg.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/executor/nodeAgg.c')
-rw-r--r--src/backend/executor/nodeAgg.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c
index 58c837e8e9c..28f50bdd4f4 100644
--- a/src/backend/executor/nodeAgg.c
+++ b/src/backend/executor/nodeAgg.c
@@ -109,22 +109,24 @@ ExecAgg(Agg *node)
bool isNull = FALSE,
isNull1 = FALSE,
isNull2 = FALSE;
-
-
- do {
-
+ bool qual_result;
+
/* ---------------------
* get state info from node
* ---------------------
*/
+ /* We loop retrieving groups until we find one matching node->plan.qual */
+ do {
+
aggstate = node->aggstate;
if (aggstate->agg_done)
return NULL;
estate = node->plan.state;
econtext = aggstate->csstate.cstate.cs_ExprContext;
+
nagg = length(node->aggs);
aggregates = (Aggreg **) palloc(sizeof(Aggreg *) * nagg);
@@ -235,8 +237,7 @@ ExecAgg(Agg *node)
}
}
}
-
-
+
/* ----------------
* for each tuple from the the outer plan, apply all the aggregates
* ----------------
@@ -474,11 +475,6 @@ ExecAgg(Agg *node)
* slot and return it.
* ----------------
*/
-
- }
- while((ExecQual(fix_opids(node->plan.qual),econtext)!=true) &&
- (node->plan.qual!=NULL));
-
ExecStoreTuple(oneTuple,
aggstate->csstate.css_ScanTupleSlot,
@@ -488,8 +484,13 @@ ExecAgg(Agg *node)
resultSlot = ExecProject(projInfo, &isDone);
+ /* As long as the retrieved group does not match the qualifications it is ignored and
+ * the next group is fetched */
+ qual_result=ExecQual(fix_opids(node->plan.qual),econtext);
if (oneTuple)
- pfree(oneTuple);
+ pfree(oneTuple);
+ }
+ while((node->plan.qual!=NULL) && (qual_result!=true));
return resultSlot;
}