aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_clause.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2002-08-18 18:46:15 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2002-08-18 18:46:15 +0000
commit22bfa720688c4343ab98c4853466c4011a048204 (patch)
tree8d848a55ad6488657b582101b764607b6766a0c9 /src/backend/parser/parse_clause.c
parent315a9ca32e0de215f9822aec1e4cbe52c94fe09c (diff)
downloadpostgresql-22bfa720688c4343ab98c4853466c4011a048204.tar.gz
postgresql-22bfa720688c4343ab98c4853466c4011a048204.zip
Remove optimization whereby parser would make only one sort-list entry
when two equal() targetlist items were to be added to an ORDER BY or DISTINCT list. Although indeed this would make sorting fractionally faster by sometimes saving a comparison, it confuses the heck out of later stages of processing, because it makes it look like the user wrote DISTINCT ON rather than DISTINCT. Bug reported by joe@piscitella.com.
Diffstat (limited to 'src/backend/parser/parse_clause.c')
-rw-r--r--src/backend/parser/parse_clause.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c
index ae87b056f3e..95f45a942a8 100644
--- a/src/backend/parser/parse_clause.c
+++ b/src/backend/parser/parse_clause.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.95 2002/08/04 19:48:10 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.96 2002/08/18 18:46:15 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -60,7 +60,7 @@ static TargetEntry *findTargetlistEntry(ParseState *pstate, Node *node,
List *tlist, int clause);
static List *addTargetToSortList(TargetEntry *tle, List *sortlist,
List *targetlist, List *opname);
-static bool exprIsInSortList(Node *expr, List *sortList, List *targetList);
+static bool targetIsInSortList(TargetEntry *tle, List *sortList);
/*
@@ -1138,7 +1138,7 @@ transformGroupClause(ParseState *pstate, List *grouplist, List *targetlist)
targetlist, GROUP_CLAUSE);
/* avoid making duplicate grouplist entries */
- if (!exprIsInSortList(tle->expr, glist, targetlist))
+ if (!targetIsInSortList(tle, glist))
{
GroupClause *grpcl = makeNode(GroupClause);
@@ -1333,7 +1333,7 @@ addTargetToSortList(TargetEntry *tle, List *sortlist, List *targetlist,
List *opname)
{
/* avoid making duplicate sortlist entries */
- if (!exprIsInSortList(tle->expr, sortlist, targetlist))
+ if (!targetIsInSortList(tle, sortlist))
{
SortClause *sortcl = makeNode(SortClause);
@@ -1382,23 +1382,28 @@ assignSortGroupRef(TargetEntry *tle, List *tlist)
}
/*
- * exprIsInSortList
- * Is the given expression already in the sortlist?
- * Note we will say 'yes' if it is equal() to any sortlist item,
- * even though that might be a different targetlist member.
+ * targetIsInSortList
+ * Is the given target item already in the sortlist?
*
- * Works for both SortClause and GroupClause lists.
+ * Works for both SortClause and GroupClause lists. Note that the main
+ * reason we need this routine (and not just a quick test for nonzeroness
+ * of ressortgroupref) is that a TLE might be in only one of the lists.
*/
static bool
-exprIsInSortList(Node *expr, List *sortList, List *targetList)
+targetIsInSortList(TargetEntry *tle, List *sortList)
{
+ Index ref = tle->resdom->ressortgroupref;
List *i;
+ /* no need to scan list if tle has no marker */
+ if (ref == 0)
+ return false;
+
foreach(i, sortList)
{
SortClause *scl = (SortClause *) lfirst(i);
- if (equal(expr, get_sortgroupclause_expr(scl, targetList)))
+ if (scl->tleSortGroupRef == ref)
return true;
}
return false;