|
8 | 8 | * |
9 | 9 | * |
10 | 10 | * 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 $ |
12 | 12 | * |
13 | 13 | *------------------------------------------------------------------------- |
14 | 14 | */ |
@@ -60,7 +60,7 @@ static TargetEntry *findTargetlistEntry(ParseState *pstate, Node *node, |
60 | 60 | List*tlist,intclause); |
61 | 61 | staticList*addTargetToSortList(TargetEntry*tle,List*sortlist, |
62 | 62 | List*targetlist,List*opname); |
63 | | -staticboolexprIsInSortList(Node*expr,List*sortList,List*targetList); |
| 63 | +staticbooltargetIsInSortList(TargetEntry*tle,List*sortList); |
64 | 64 |
|
65 | 65 |
|
66 | 66 | /* |
@@ -1138,7 +1138,7 @@ transformGroupClause(ParseState *pstate, List *grouplist, List *targetlist) |
1138 | 1138 | targetlist,GROUP_CLAUSE); |
1139 | 1139 |
|
1140 | 1140 | /* avoid making duplicate grouplist entries */ |
1141 | | -if (!exprIsInSortList(tle->expr,glist,targetlist)) |
| 1141 | +if (!targetIsInSortList(tle,glist)) |
1142 | 1142 | { |
1143 | 1143 | GroupClause*grpcl=makeNode(GroupClause); |
1144 | 1144 |
|
@@ -1333,7 +1333,7 @@ addTargetToSortList(TargetEntry *tle, List *sortlist, List *targetlist, |
1333 | 1333 | List*opname) |
1334 | 1334 | { |
1335 | 1335 | /* avoid making duplicate sortlist entries */ |
1336 | | -if (!exprIsInSortList(tle->expr,sortlist,targetlist)) |
| 1336 | +if (!targetIsInSortList(tle,sortlist)) |
1337 | 1337 | { |
1338 | 1338 | SortClause*sortcl=makeNode(SortClause); |
1339 | 1339 |
|
@@ -1382,23 +1382,28 @@ assignSortGroupRef(TargetEntry *tle, List *tlist) |
1382 | 1382 | } |
1383 | 1383 |
|
1384 | 1384 | /* |
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? |
1389 | 1387 | * |
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. |
1391 | 1391 | */ |
1392 | 1392 | staticbool |
1393 | | -exprIsInSortList(Node*expr,List*sortList,List*targetList) |
| 1393 | +targetIsInSortList(TargetEntry*tle,List*sortList) |
1394 | 1394 | { |
| 1395 | +Indexref=tle->resdom->ressortgroupref; |
1395 | 1396 | List*i; |
1396 | 1397 |
|
| 1398 | +/* no need to scan list if tle has no marker */ |
| 1399 | +if (ref==0) |
| 1400 | +return false; |
| 1401 | + |
1397 | 1402 | foreach(i,sortList) |
1398 | 1403 | { |
1399 | 1404 | SortClause*scl= (SortClause*)lfirst(i); |
1400 | 1405 |
|
1401 | | -if (equal(expr,get_sortgroupclause_expr(scl,targetList))) |
| 1406 | +if (scl->tleSortGroupRef==ref) |
1402 | 1407 | return true; |
1403 | 1408 | } |
1404 | 1409 | return false; |
|