citext gives wrong results with a nondeterministic collation

From: shihao zhong <zhong950419(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter(at)eisentraut(dot)org>, Jeff Davis <pgsql(at)j-davis(dot)com>
Subject: citext gives wrong results with a nondeterministic collation
Date: 2026-11-30 05:38:21
Message-ID: CAGRkXqS-Jns2A=MeWbFDGhitn+JuQwLRanuf-_nm2GS26wH0+g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

While working on BUG #19873 [1], I found that citext has a related
problem. With a nondeterministic collation, adding an index changes the
result.

create extension citext;
create collation ai (provider = icu, locale = 'und-u-ks-level1',
deterministic = false);
create table t (x citext collate ai);
insert into t values ('e'), ('é');

select count(*) from t where x = 'é';
count
-------
1

create index on t (x);
set enable_seqscan = off;
select count(*) from t where x = 'é';
count
-------
0

The index uses citext_cmp(), which follows the collation and says the
two values are equal. But "=" compares the lower-cased bytes and says
they are not. I see the same on 14 through master.

I think "=" and the hash functions should follow the collation too, like
they do for text. Does that sound right? I can write a patch.

[1] https://postgr.es/m/19873-2b5e1e0dd7b9eac0@postgresql.org

Thanks,
Shihao

Attachment Content-Type Size
repro.sql application/octet-stream 4.1 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Shinya Kato 2026-11-30 06:01:59 Re: Logical replication row filter loses unchanged toasted columns
Previous Message Michael Paquier 2026-11-30 05:36:22 Re: GetNewOidWithIndex() can reuse a TOAST value ID while its chunks are still in the heap