summaryrefslogtreecommitdiff
path: root/src/backend/parser/analyze.c
diff options
context:
space:
mode:
authorTom Lane2003-06-15 16:42:08 +0000
committerTom Lane2003-06-15 16:42:08 +0000
commit996fdb9af1e298ae1ce3729429d2416e41344086 (patch)
tree32cf3e674e9eb5ab60d925f1408eea7b7c7bae6c /src/backend/parser/analyze.c
parentda78e3e2eba4e1f54769eecebaf560f14e2711ea (diff)
Cause GROUP BY clause to adopt ordering operators from ORDER BY when
both clauses specify the same targets, rather than always using the default ordering operator. This allows 'GROUP BY foo ORDER BY foo DESC' to be done with only one sort step.
Diffstat (limited to 'src/backend/parser/analyze.c')
-rw-r--r--src/backend/parser/analyze.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c
index 9ac8132f08a..95b209e4acb 100644
--- a/src/backend/parser/analyze.c
+++ b/src/backend/parser/analyze.c
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.273 2003/06/06 15:04:02 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.274 2003/06/15 16:42:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1787,14 +1787,19 @@ transformSelectStmt(ParseState *pstate, SelectStmt *stmt)
*/
qry->havingQual = transformWhereClause(pstate, stmt->havingClause);
- qry->groupClause = transformGroupClause(pstate,
- stmt->groupClause,
- qry->targetList);
-
+ /*
+ * Transform sorting/grouping stuff. Do ORDER BY first because both
+ * transformGroupClause and transformDistinctClause need the results.
+ */
qry->sortClause = transformSortClause(pstate,
stmt->sortClause,
qry->targetList);
+ qry->groupClause = transformGroupClause(pstate,
+ stmt->groupClause,
+ qry->targetList,
+ qry->sortClause);
+
qry->distinctClause = transformDistinctClause(pstate,
stmt->distinctClause,
qry->targetList,