pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jeff Davis <pgsql@j-davis.com>
To: pgsql-bugs@postgresql.org
Subject: hashing bpchar for nondeterministic collations is broken
Date: Thu, 01 Dec 2022 12:11:29 -0800
Message-ID: <eb83d0ac7b299eb08f9b900dd08a5a0c5d90e517.camel@j-davis.com> (raw)

CREATE COLLATION ctest_nondet(
  provider = icu, locale = '', deterministic = false);

=# select hashbpcharextended('a' collate ctest_nondet, 3);
 hashbpcharextended  
---------------------
 2792701603979490504
(1 row)

=# select hashbpcharextended('a  ' collate ctest_nondet, 3);
  hashbpcharextended  
----------------------
 -4885217598372536483
(1 row)


I don't see any major consequences, because in both hash indexes and
partitioning it appears that the trailing spaces on the key are already
gone before hashbpcharextended is called. If someone does see bigger
consequences here, please let me know.

Seems to be an oversight. Patch attached.

Also, does someone have an opinion on backporting this? I'm inclined
to.


-- 
Jeff Davis
PostgreSQL Contributor Team - AWS

Attachments:

v1-0001-Fix-broken-hash-function-hashbpcharextended.patch (text/x-patch, 1.0K) download From 0f8759691ae226837091d409404b8d1eb14d99f0 Mon Sep 17 00:00:00 2001 From: Jeff Davis <jdavis@postgresql.org> Date: Thu, 1 Dec 2022 11:08:47 -0800 Subject: [PATCH v1] Fix broken hash function hashbpcharextended(). Ignore trailing spaces for non-deterministic collations when hashing. Fortunately, the previous behavior did not seem to affect hash indexes or hash partitions, because the trailing spaces were removed before hashbpcharextended() was called. --- src/backend/utils/adt/varchar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/utils/adt/varchar.c b/src/backend/utils/adt/varchar.c index 09c483d6ff..a63c498181 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); -- 2.34.1

view thread (6+ messages)  latest in thread

Message-ID: <eb83d0ac7b299eb08f9b900dd08a5a0c5d90e517.camel@j-davis.com>
Permalink:  ../eb83d0ac7b299eb08f9b900dd08a5a0c5d90e517.camel@j-davis.com/
Also on:    postgresql.org/message-id/eb83d0ac7b299eb08f9b900dd08a5a0c5d90e517.camel@j-davis.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: pgsql@j-davis.com
  Subject: Re: hashing bpchar for nondeterministic collations is broken
  In-Reply-To: <eb83d0ac7b299eb08f9b900dd08a5a0c5d90e517.camel@j-davis.com>
  References: <eb83d0ac7b299eb08f9b900dd08a5a0c5d90e517.camel@j-davis.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox