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)
commitb8efe5d913ae71ef32f972cc38c4ae713d6b6a7a
tree3d5e0d8d4eabfadc481efef74656f335aeaa2dd6
parentf9c08b9e06f40703da3bed3e3d21d98941c4818e
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