Fix Memoize to correctly use clause's input collation

When building Memoize cache keys from a parameterized path's join clauses,
paraminfo_get_equal_hashops() used the outer side expression of each
clause verbatim, which meant the cache was hashed and probed using that
expression's collation rather than the input collation of the join
condition.

If the expression's collation is nondeterministic and the clause compares
using a different collation, values that the clause can distinguish, such
as 'abc' and 'ABC' under a case-insensitive collation, could be treated as
equal by the cache.  This could cause a lookup to return the cached
results for another value, giving wrong query results.

Here we fix this by relabeling the cache key expression with the join
clause's input collation, so that cache lookups match values the same way
as the join clause does.

Author: shihao zhong <[email protected]>
Reviewed-by: Manu <[email protected]>
Reviewed-by: David Rowley <[email protected]>
Discussion: 
https://postgr.es/m/cagrkxqtbsbegz8rnmyjwkeu1v5wrq06zr6jtvickqp_3e7m...@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/083d60e34ae081a18f57071e45fcad9f07d1d7f6

Modified Files
--------------
src/backend/optimizer/path/joinpath.c          | 11 +++++++
src/test/regress/expected/collate.icu.utf8.out | 42 ++++++++++++++++++++++++++
src/test/regress/sql/collate.icu.utf8.sql      | 25 +++++++++++++++
3 files changed, 78 insertions(+)

Reply via email to