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