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: v1-0001-Make-hashname-honor-nondeterministic-collations.patch
Description: Binary data

Attachment: v1-0002-Add-tests-for-hashname-with-nondeterministic-collati.patch
Description: Binary data

Reply via email to