Fix EquivalenceClass code to handle volatile sort expressions in a more
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 8 Nov 2007 21:49:48 +0000 (21:49 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 8 Nov 2007 21:49:48 +0000 (21:49 +0000)
commit4fef2516432ba9429265fc0f784dbf02ea85e8e5
tree9920f652880c8541718276bb7747ce89ada411c7
parent1e8a0141062ca3c18edfb8dd27753399f06560ed
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.
src/backend/nodes/outfuncs.c
src/backend/optimizer/path/equivclass.c
src/backend/optimizer/path/pathkeys.c
src/backend/optimizer/plan/createplan.c
src/backend/optimizer/util/tlist.c
src/include/nodes/relation.h
src/include/optimizer/paths.h
src/include/optimizer/tlist.h