From: | Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com> |
---|---|
To: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Missing update of all_hasnulls in BRIN opclasses |
Date: | 2022-10-21 15:23:45 |
Message-ID: | 402430e4-7d9d-6cf1-09ef-464d80afff3b@enterprisedb.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi,
While working on some BRIN code, I discovered a bug in handling NULL
values - when inserting a non-NULL value into a NULL-only range, we
reset the all_nulls flag but don't update the has_nulls flag. And
because of that we then fail to return the range for IS NULL ranges.
Reproducing this is trivial:
create table t (a int);
create index on t using brin (a);
insert into t values (null);
insert into t values (1);
set enable_seqscan = off;
select * from t where a is null;
This should return 1 row, but actually it returns no rows.
Attached is a patch fixing this by properly updating the has_nulls flag.
I reproduced this all the way back to 9.5, so it's a long-standing bug.
It's interesting no one noticed / reported it so far, it doesn't seem
like a particularly rare corner case.
regards
--
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
Attachment | Content-Type | Size |
---|---|---|
brin-hasnulls-fix.patch | text/x-patch | 4.6 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Bharath Rupireddy | 2022-10-21 15:32:04 | Re: Avoid memory leaks during base backups |
Previous Message | Bharath Rupireddy | 2022-10-21 15:07:18 | Re: Crash after a call to pg_backup_start() |