From: Jeff Davis Date: Thu, 1 Dec 2022 19:08:47 +0000 (-0800) Subject: Fix broken hash function hashbpcharextended(). X-Git-Tag: REL_16_BETA1~1181 X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=7ac0f8d384a4633c6652ae1f6bba40d42d21ec18;p=postgresql.git Fix broken hash function hashbpcharextended(). Ignore trailing spaces for non-deterministic collations when hashing. The previous behavior could lead to tuples falling into the wrong partitions when hash partitioning is combined with the BPCHAR type and a non-deterministic collation. Fortunately, it did not affect hash indexes, because hash indexes do not use extended hash functions. Decline to backpatch, per discussion. Discussion: https://postgr.es/m/eb83d0ac7b299eb08f9b900dd08a5a0c5d90e517.camel@j-davis.com Reviewed-by: Richard Guo, Tom Lane --- diff --git a/src/backend/utils/adt/varchar.c b/src/backend/utils/adt/varchar.c index 09c483d6ff8..a63c498181e 100644 --- a/src/backend/utils/adt/varchar.c +++ b/src/backend/utils/adt/varchar.c @@ -1086,7 +1086,7 @@ hashbpcharextended(PG_FUNCTION_ARGS) Size bsize; uint8_t *buf; - ulen = icu_to_uchar(&uchar, VARDATA_ANY(key), VARSIZE_ANY_EXHDR(key)); + ulen = icu_to_uchar(&uchar, keydata, keylen); bsize = ucol_getSortKey(mylocale->info.icu.ucol, uchar, ulen, NULL, 0);