aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/util/tlist.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-11-08 21:49:48 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-11-08 21:49:48 +0000
commitc291203ca3cde3b10e7a8962df2c1ccc737a9e6f (patch)
tree2fef9ed8d4bbd9b725b4f857918ea98cf85bbc09 /src/backend/optimizer/util/tlist.c
parent1be0601681197fe79a2d2d403c518e7aeff1788a (diff)
downloadpostgresql-c291203ca3cde3b10e7a8962df2c1ccc737a9e6f.tar.gz
postgresql-c291203ca3cde3b10e7a8962df2c1ccc737a9e6f.zip
Fix EquivalenceClass code to handle volatile sort expressions in a more
predictable manner; in particular that if you say ORDER BY output-column-ref, it will in fact sort by that specific column even if there are multiple syntactic matches. An example is SELECT random() AS a, random() AS b FROM ... ORDER BY b, a; While the use-case for this might be a bit debatable, it worked as expected in earlier releases, so we should preserve the behavior for 8.3. Per my recent proposal. While at it, fix convert_subquery_pathkeys() to handle RelabelType stripping in both directions; it needs this for the same reasons make_sort_from_pathkeys does.
Diffstat (limited to 'src/backend/optimizer/util/tlist.c')
-rw-r--r--src/backend/optimizer/util/tlist.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/backend/optimizer/util/tlist.c b/src/backend/optimizer/util/tlist.c
index e58fe7dc7f1..d2ac14cfa1b 100644
--- a/src/backend/optimizer/util/tlist.c
+++ b/src/backend/optimizer/util/tlist.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/util/tlist.c,v 1.75 2007/11/08 19:25:37 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/util/tlist.c,v 1.76 2007/11/08 21:49:47 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -131,26 +131,22 @@ add_to_flat_tlist(List *tlist, List *vars)
return tlist;
}
+
/*
- * get_sortgroupclause_tle
- * Find the targetlist entry matching the given SortClause
- * (or GroupClause) by ressortgroupref, and return it.
- *
- * Because GroupClause is typedef'd as SortClause, either kind of
- * node can be passed without casting.
+ * get_sortgroupref_tle
+ * Find the targetlist entry matching the given SortGroupRef index,
+ * and return it.
*/
TargetEntry *
-get_sortgroupclause_tle(SortClause *sortClause,
- List *targetList)
+get_sortgroupref_tle(Index sortref, List *targetList)
{
- Index refnumber = sortClause->tleSortGroupRef;
ListCell *l;
foreach(l, targetList)
{
TargetEntry *tle = (TargetEntry *) lfirst(l);
- if (tle->ressortgroupref == refnumber)
+ if (tle->ressortgroupref == sortref)
return tle;
}
@@ -159,6 +155,21 @@ get_sortgroupclause_tle(SortClause *sortClause,
}
/*
+ * get_sortgroupclause_tle
+ * Find the targetlist entry matching the given SortClause
+ * (or GroupClause) by ressortgroupref, and return it.
+ *
+ * Because GroupClause is typedef'd as SortClause, either kind of
+ * node can be passed without casting.
+ */
+TargetEntry *
+get_sortgroupclause_tle(SortClause *sortClause,
+ List *targetList)
+{
+ return get_sortgroupref_tle(sortClause->tleSortGroupRef, targetList);
+}
+
+/*
* get_sortgroupclause_expr
* Find the targetlist entry matching the given SortClause
* (or GroupClause) by ressortgroupref, and return its expression.