Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 22bfa72

Browse files
committed
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.
1 parent 315a9ca commit 22bfa72

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/backend/parser/parse_clause.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.95 2002/08/04 19:48:10 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.96 2002/08/18 18:46:15 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -60,7 +60,7 @@ static TargetEntry *findTargetlistEntry(ParseState *pstate, Node *node,
6060
List *tlist, int clause);
6161
static List *addTargetToSortList(TargetEntry *tle, List *sortlist,
6262
List *targetlist, List *opname);
63-
static bool exprIsInSortList(Node *expr, List *sortList, List *targetList);
63+
static bool targetIsInSortList(TargetEntry *tle, List *sortList);
6464

6565

6666
/*
@@ -1138,7 +1138,7 @@ transformGroupClause(ParseState *pstate, List *grouplist, List *targetlist)
11381138
targetlist, GROUP_CLAUSE);
11391139

11401140
/* avoid making duplicate grouplist entries */
1141-
if (!exprIsInSortList(tle->expr, glist, targetlist))
1141+
if (!targetIsInSortList(tle, glist))
11421142
{
11431143
GroupClause *grpcl = makeNode(GroupClause);
11441144

@@ -1333,7 +1333,7 @@ addTargetToSortList(TargetEntry *tle, List *sortlist, List *targetlist,
13331333
List *opname)
13341334
{
13351335
/* avoid making duplicate sortlist entries */
1336-
if (!exprIsInSortList(tle->expr, sortlist, targetlist))
1336+
if (!targetIsInSortList(tle, sortlist))
13371337
{
13381338
SortClause *sortcl = makeNode(SortClause);
13391339

@@ -1382,23 +1382,28 @@ assignSortGroupRef(TargetEntry *tle, List *tlist)
13821382
}
13831383

13841384
/*
1385-
* exprIsInSortList
1386-
* Is the given expression already in the sortlist?
1387-
* Note we will say 'yes' if it is equal() to any sortlist item,
1388-
* even though that might be a different targetlist member.
1385+
* targetIsInSortList
1386+
* Is the given target item already in the sortlist?
13891387
*
1390-
* Works for both SortClause and GroupClause lists.
1388+
* Works for both SortClause and GroupClause lists. Note that the main
1389+
* reason we need this routine (and not just a quick test for nonzeroness
1390+
* of ressortgroupref) is that a TLE might be in only one of the lists.
13911391
*/
13921392
static bool
1393-
exprIsInSortList(Node *expr, List *sortList, List *targetList)
1393+
targetIsInSortList(TargetEntry *tle, List *sortList)
13941394
{
1395+
Index ref = tle->resdom->ressortgroupref;
13951396
List *i;
13961397

1398+
/* no need to scan list if tle has no marker */
1399+
if (ref == 0)
1400+
return false;
1401+
13971402
foreach(i, sortList)
13981403
{
13991404
SortClause *scl = (SortClause *) lfirst(i);
14001405

1401-
if (equal(expr, get_sortgroupclause_expr(scl, targetList)))
1406+
if (scl->tleSortGroupRef == ref)
14021407
return true;
14031408
}
14041409
return false;

0 commit comments

Comments
 (0)