Fix assertion failure when a SELECT DISTINCT ON expression is volatile.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 12 Sep 2009 00:04:59 +0000 (00:04 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 12 Sep 2009 00:04:59 +0000 (00:04 +0000)
commitd5a4b69c3a0d2668fa6098c73be7b6f0036bb642
treef807e00ab424c10166007bb04b9a97ab2d0c4c75
parent8c5463a51176c8d2a01fcf154d7ac33fa9a74f6a
Fix assertion failure when a SELECT DISTINCT ON expression is volatile.
In this case we generate two PathKey references to the expression (one for
DISTINCT and one for ORDER BY) and they really need to refer to the same
EquivalenceClass.  However get_eclass_for_sort_expr was being overly paranoid
and creating two different EC's.  Correct behavior is to use the SortGroupRef
index to decide whether two references to volatile expressions that are
equal() (ie textually equivalent) should be considered the same.

Backpatch to 8.4.  Possibly this should be changed in 8.3 as well, but
I'll refrain in the absence of evidence of a visible failure in that branch.

Per bug #5049.
src/backend/optimizer/path/equivclass.c
src/backend/optimizer/path/pathkeys.c
src/test/regress/expected/select_distinct_on.out
src/test/regress/sql/select_distinct_on.sql