pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Put "excludeOnly" GIN scan keys at the end of the scankey array.
Date: Tue, 26 Aug 2025 16:09:12 +0000
Message-ID: <E1uqwER-001mPH-2q@gemulon.postgresql.org> (raw)

Put "excludeOnly" GIN scan keys at the end of the scankey array.

Commit 4b754d6c1 introduced the concept of an excludeOnly scan key,
which cannot select matching index entries but can reject
non-matching tuples, for example a tsquery such as '!term'.  There are
poorly-documented assumptions that such scan keys do not appear as the
first scan key.  ginNewScanKey did nothing to ensure that, however,
with the result that certain GIN index searches could go into an
infinite loop while apparently-equivalent queries with the clauses in
a different order were fine.

Fix by teaching ginNewScanKey to place all excludeOnly scan keys
after all not-excludeOnly ones.  So far as we know at present,
it might be sufficient to avoid the case where the very first
scan key is excludeOnly; but I'm not very convinced that there
aren't other dependencies on the ordering.

Bug: #19031
Reported-by: Tim Wood <washwithcare@gmail.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/19031-0638148643d25548@postgresql.org
Backpatch-through: 13

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/d532069c391a2b50432f273052196496b7a61c64

Modified Files
--------------
contrib/pg_trgm/expected/pg_trgm.out | 46 ++++++++++++++++++++++++++++++++++++
contrib/pg_trgm/sql/pg_trgm.sql      |  8 +++++++
src/backend/access/gin/ginscan.c     | 43 +++++++++++++++++++++++++++++++++
3 files changed, 97 insertions(+)



view thread (7+ messages)

Message-ID: <E1uqwER-001mPH-2q@gemulon.postgresql.org>
Permalink:  ../E1uqwER-001mPH-2q@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1uqwER-001mPH-2q@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Put "excludeOnly" GIN scan keys at the end of the scankey array.
  In-Reply-To: <E1uqwER-001mPH-2q@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox