hashname() ignores nondeterministic collations

From: shihao zhong <zhong950419(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Peter Eisentraut <peter(at)eisentraut(dot)org>, Jeff Davis <pgsql(at)j-davis(dot)com>
Subject: hashname() ignores nondeterministic collations
Date: 2026-12-01 01:21:46
Message-ID: CAGRkXqTjmvbX=W7WZQ0GZ2sxc1TTA6OWNMgh82RWmQ0-oY_Pdg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

586b98fdf1a made "=" on name follow the collation, but hashname() still
hashes the bytes. With a nondeterministic collation, a hash join can
lose rows.

create collation ci (provider = icu, locale = 'und-u-ks-level2',
deterministic = false);
create table n1 (n name);
create table n2 (n name);
insert into n1 values ('abc'), ('xyz');
insert into n2 values ('ABC'), ('XYZ');

set enable_mergejoin = off;
set enable_hashjoin = off;
select count(*) from n1 join n2 on n1.n = n2.n collate ci;
count
-------
2

set enable_hashjoin = on;
set enable_nestloop = off;
select count(*) from n1 join n2 on n1.n = n2.n collate ci;
count
-------
0

The attached patch hashes such names the way hashtext() does.
Nothing changes for deterministic collations.

The hash values do change for nondeterministic ones. Existing hash and
BRIN bloom indexes on such name columns need a REINDEX, and hash
partitions need a dump and reload with --load-via-partition-root.

0002 is an optional test, given it is very small, I prefer to include that
in the commit.

Thanks,
Shihao

Attachment Content-Type Size
v1-0001-Make-hashname-honor-nondeterministic-collations.patch application/octet-stream 2.1 KB
v1-0002-Add-tests-for-hashname-with-nondeterministic-collati.patch application/octet-stream 2.3 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message shihao zhong 2026-12-01 01:32:25 Re: Don't use the deprecated and insecure PQcancel in our frontend tools anymore
Previous Message Chao Li 2026-12-01 01:06:36 Re: REPACK (CONCURRENTLY) fails during parallel build of exclusion constraint indexes