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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Chinmay Kanchi <cgkanchi(at)gmail(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: GIN disagrees with seq scan when NOT and AND operators are combined
Date: 2026-10-09 20:27:44
Message-ID: 2924325.1791577664@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Chinmay Kanchi <cgkanchi(at)gmail(dot)com> writes:
> 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.

Thanks for the report. (For the archives' sake, note this repro
requires "set enable_seqscan = 0", else you get a seqscan plan
and no bug.)

I'm not too familiar with this code, but it looks like
extract_jsp_bool_expr concludes that !($.b == 20) is not supported
as a GIN scan condition, and then the next recursion level up does
the wrong thing with the negated && condition. The attached quick
hack seems to fix it. I didn't look around for other instances
of the same thinko, but there might be some.

regards, tom lane

Attachment Content-Type Size
wip-fix-jsonb-gin-not-semantics.patch text/x-diff 1.1 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Previous Message Chinmay Kanchi 2026-10-09 17:04:44 GIN disagrees with seq scan when NOT and AND operators are combined