Fix RI_Initial_Check to use a COLLATE clause when needed in its query.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 12 Apr 2011 01:32:53 +0000 (21:32 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 12 Apr 2011 01:32:53 +0000 (21:32 -0400)
commit921b993677e165607029a52e7f866bbd112345a5
tree9b0da7062c6fb3fc6af33a5d414ff13c28abb386
parent5caa3479c2efd31fca1b271db687e5e57c7de2d4
Fix RI_Initial_Check to use a COLLATE clause when needed in its query.

If the referencing and referenced columns have different collations,
the parser will be unable to resolve which collation to use unless it's
helped out in this way.  The effects are sometimes masked, if we end up
using a non-collation-sensitive plan; but if we do use a mergejoin
we'll see a failure, as recently noted by Robert Haas.

The SQL spec states that the referenced column's collation should be used
to resolve RI checks, so that's what we do.  Note however that we currently
don't append a COLLATE clause when writing a query that examines only the
referencing column.  If we ever support collations that have varying
notions of equality, that will have to be changed.  For the moment, though,
it's preferable to leave it off so that we can use a normal index on the
referencing column.
src/backend/parser/parse_relation.c
src/backend/utils/adt/ri_triggers.c
src/include/parser/parse_relation.h
src/test/regress/expected/collate.out
src/test/regress/sql/collate.sql