GIN disagrees with seq scan when NOT and AND operators are combined

From: Chinmay Kanchi <cgkanchi(at)gmail(dot)com>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: GIN disagrees with seq scan when NOT and AND operators are combined
Date: 2026-10-09 17:04:44
Message-ID: CAJqPDh9Cm=x8eYZ1Jf=_avd2WEqc=0t_f7_SO4igo-CKPi25_Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi all,

When working on pg_lion (https://github.com/cgkanchi/pg_lion) I stumbled
upon a bug where GIN returns fewer rows when multiple ! operators are
specified. I was able to repro this on all versions from 16 to trunk.

Repro:
```
postgres=# CREATE TABLE t (j jsonb);
INSERT INTO t VALUES ('{"a": 1, "b": 10}'), ('{"a": 2, "b": 10}'), ('{"a":
2, "b": 20}');
CREATE TABLE
INSERT 0 3
postgres=# SELECT j FROM t WHERE j @@ '!(!($.a == 1) && $.b == 20)';
j
-------------------
{"a": 1, "b": 10}
{"a": 2, "b": 10}
(2 rows)

postgres=# create index on t using gin(j);
CREATE INDEX
postgres=# SELECT j FROM t WHERE j @@ '!(!($.a == 1) && $.b == 20)';
j
-------------------
{"a": 1, "b": 10}
(1 row)
```

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2026-10-09 20:27:44 Re: GIN disagrees with seq scan when NOT and AND operators are combined
Previous Message Andrew Dunstan 2026-10-09 14:28:31 Re: PG18: use-after-free in exec partition pruning after an EPQ recheck in LockRows