From 63247bec284a935b3145d5302c834967049e5dea Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 31 Jul 2008 22:47:56 +0000 Subject: Fix parser so that we don't modify the user-written ORDER BY list in order to represent DISTINCT or DISTINCT ON. This gets rid of a longstanding annoyance that a view or rule using SELECT DISTINCT will be dumped out with an overspecified ORDER BY list, and is one small step along the way to decoupling DISTINCT and ORDER BY enough so that hash-based implementation of DISTINCT will be possible. In passing, improve transformDistinctClause so that it doesn't reject duplicate DISTINCT ON items, as was reported by Steve Midgley a couple weeks ago. --- src/backend/parser/analyze.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/backend/parser/analyze.c') diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index 520b5037255..329b1bc881a 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -17,7 +17,7 @@ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.373 2008/07/18 20:26:06 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.374 2008/07/31 22:47:56 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -711,6 +711,8 @@ transformSelectStmt(ParseState *pstate, SelectStmt *stmt) /* * Transform sorting/grouping stuff. Do ORDER BY first because both * transformGroupClause and transformDistinctClause need the results. + * Note that these functions can also change the targetList, so it's + * passed to them by reference. */ qry->sortClause = transformSortClause(pstate, stmt->sortClause, @@ -725,8 +727,9 @@ transformSelectStmt(ParseState *pstate, SelectStmt *stmt) qry->distinctClause = transformDistinctClause(pstate, stmt->distinctClause, &qry->targetList, - &qry->sortClause); + qry->sortClause); + /* transform LIMIT */ qry->limitOffset = transformLimitClause(pstate, stmt->limitOffset, "OFFSET"); qry->limitCount = transformLimitClause(pstate, stmt->limitCount, -- cgit v1.2.3