| From: | shihao zhong <zhong950419(at)gmail(dot)com> |
|---|---|
| To: | pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Cc: | Guofenglinux <guofenglinux(at)gmail(dot)com>, pg(at)bowt(dot)ie |
| Subject: | [PG19] eager aggregation gives wrong results because of bpchar_ops |
| Date: | 2026-10-06 02:19:01 |
| Message-ID: | CAGRkXqQQ311Lg=62x5UdZtPuRFgpT6XpPMw4X9E3tgbTu162Mw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi hackers,
I used Opus to go over the new features in PG19, and it found wrong
results from eager aggregation on a bpchar column with no length.
create table e1 (k int, pat text);
insert into e1 values (1, 'a'), (2, 'a ');
create table e2 (c bpchar, v int);
insert into e2 select case when g % 2 = 0 then 'a' else 'a ' end, 1
from generate_series(1, 20000) g;
analyze e1, e2;
select e1.k, count(*) from e1 join e2 on e2.c like e1.pat
group by e1.k order by 1;
18 returns
k | count
---+-------
1 | 10000
2 | 10000
19 and master return
k | count
---+-------
2 | 20000
bpchar equality ignores trailing spaces, but bpchar_ops and
bpchar_pattern_ops have an equalimage function, and eager aggregation
trusts it. nbtree deduplication does too, also on 18. In the attached
bpchar-nbtree-ios.sql the heap has octet_length 1 x 98 and 3 x 1, and
the index-only scan returns 1 x 99. BUG #19749 [1] has the assert.
The patches follow the interval_ops fix [2]. 0001 drops support
function 4 from both opclasses, catversion bump needed. 0002 is a
test. The .txt file is for back branches, where the equalimage
functions also return false for bpchar. Opus drafted them.
This also ends deduplication for char(n), where it was safe. Peter,
do you want to keep it there? Old indexes need REINDEX, and amcheck
flags them until then, so I am not sure about the back branches. The
eager aggregation part is new in 19, so I suggest an open item.
[1] https://postgr.es/m/19749-d46adf7c7d910b07@postgresql.org
[2] https://postgr.es/m/20231011013317.22.nmisch@google.com
Thanks,
Shihao
| Attachment | Content-Type | Size |
|---|---|---|
| v1-REL_18-0001-Remove-equalimage-support-from-bpchar_ops-and-bpc.patch.txt | text/plain | 10.1 KB |
| v1-0001-Remove-equalimage-support-from-bpchar_ops-and-bpc.patch | application/octet-stream | 7.6 KB |
| v1-0002-Add-test-for-eager-aggregation-with-a-bpchar-colu.patch | application/octet-stream | 3.2 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2026-10-06 02:29:52 | Re: [PG19] eager aggregation gives wrong results because of bpchar_ops |
| Previous Message | Richard Guo | 2026-10-06 02:04:29 | Re: remove_useless_joins vs. bug #19560 |