diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2007-11-08 21:49:48 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2007-11-08 21:49:48 +0000 |
commit | c291203ca3cde3b10e7a8962df2c1ccc737a9e6f (patch) | |
tree | 2fef9ed8d4bbd9b725b4f857918ea98cf85bbc09 /src/include/nodes/relation.h | |
parent | 1be0601681197fe79a2d2d403c518e7aeff1788a (diff) | |
download | postgresql-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/include/nodes/relation.h')
-rw-r--r-- | src/include/nodes/relation.h | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/include/nodes/relation.h b/src/include/nodes/relation.h index 38903520222..db6eef20964 100644 --- a/src/include/nodes/relation.h +++ b/src/include/nodes/relation.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.147 2007/10/11 18:05:27 tgl Exp $ + * $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.148 2007/11/08 21:49:48 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -449,7 +449,10 @@ typedef struct IndexOptInfo * which is a case that can't arise otherwise since clauses containing * volatile functions are never considered mergejoinable. We mark such * EquivalenceClasses specially to prevent them from being merged with - * ordinary EquivalenceClasses. + * ordinary EquivalenceClasses. Also, for volatile expressions we have + * to be careful to match the EquivalenceClass to the correct targetlist + * entry: consider SELECT random() AS a, random() AS b ... ORDER BY b,a. + * So we record the SortGroupRef of the originating sort clause. * * We allow equality clauses appearing below the nullable side of an outer join * to form EquivalenceClasses, but these have a slightly different meaning: @@ -472,6 +475,7 @@ typedef struct EquivalenceClass bool ec_has_volatile; /* the (sole) member is a volatile expr */ bool ec_below_outer_join; /* equivalence applies below an OJ */ bool ec_broken; /* failed to generate needed clauses? */ + Index ec_sortref; /* originating sortclause label, or 0 */ struct EquivalenceClass *ec_merged; /* set if merged into another EC */ } EquivalenceClass; |