summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/util/clauses.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2009-12-15 17:57:48 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2009-12-15 17:57:48 +0000
commit34d26872ed816b299eef2fa4240d55316697f42d (patch)
treed7373e29b365c151702c44325f0f5cc9dcc3e17c /src/backend/optimizer/util/clauses.c
parent6a6efb964092902bf53965649c3ed78b1868b37e (diff)
downloadpostgresql-34d26872ed816b299eef2fa4240d55316697f42d.tar.gz
Support ORDER BY within aggregate function calls, at long last providing a
non-kluge method for controlling the order in which values are fed to an aggregate function. At the same time eliminate the old implementation restriction that DISTINCT was only supported for single-argument aggregates. Possibly release-notable behavioral change: formerly, agg(DISTINCT x) dropped null values of x unconditionally. Now, it does so only if the agg transition function is strict; otherwise nulls are treated as DISTINCT normally would, ie, you get one copy. Andrew Gierth, reviewed by Hitoshi Harada
Diffstat (limited to 'src/backend/optimizer/util/clauses.c')
-rw-r--r--src/backend/optimizer/util/clauses.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c
index a5c343298e..56b432c9bb 100644
--- a/src/backend/optimizer/util/clauses.c
+++ b/src/backend/optimizer/util/clauses.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.280 2009/12/14 02:15:52 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.281 2009/12/15 17:57:47 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@@ -471,21 +471,22 @@ count_agg_clauses_walker(Node *node, AggClauseCounts *counts)
HeapTuple aggTuple;
Form_pg_aggregate aggform;
Oid aggtranstype;
- int i;
ListCell *l;
Assert(aggref->agglevelsup == 0);
counts->numAggs++;
- if (aggref->aggdistinct)
- counts->numDistinctAggs++;
+ if (aggref->aggorder != NIL || aggref->aggdistinct != NIL)
+ counts->numOrderedAggs++;
- /* extract argument types */
- numArguments = list_length(aggref->args);
- inputTypes = (Oid *) palloc(sizeof(Oid) * numArguments);
- i = 0;
+ /* extract argument types (ignoring any ORDER BY expressions) */
+ inputTypes = (Oid *) palloc(sizeof(Oid) * list_length(aggref->args));
+ numArguments = 0;
foreach(l, aggref->args)
{
- inputTypes[i++] = exprType((Node *) lfirst(l));
+ TargetEntry *tle = (TargetEntry *) lfirst(l);
+
+ if (!tle->resjunk)
+ inputTypes[numArguments++] = exprType((Node *) tle->expr);
}
/* fetch aggregate transition datatype from pg_aggregate */