pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: John Naylor <john.naylor@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Plug holes in SP-GiST quad tree getQuadrant()
Date: Wed, 14 Oct 2026 11:26:21 +0000
Message-ID: <E1xGx7l-00000001aVB-3SfA@gemulon.postgresql.org> (raw)

Plug holes in SP-GiST quad tree getQuadrant()

getQuadrant() places a point on each axis with the fuzzy comparisons
FPlt(), FPgt() and FPeq(), which do not cover every case.  FPeq()
compares the rounded difference against EPSILON, while FPlt() and FPgt()
round the sum of one operand and EPSILON.  When the centroid plus
EPSILON rounds up, a point equal to that rounded sum is more than
EPSILON above the centroid, so FPeq() is false. FPgt() compares it with
the same rounded sum, so it is false too, and FPlt() is false because
the point is above the centroid.  The same gap exists below the
centroid, when the centroid minus EPSILON rounds down.  No quadrant
matches, and index builds, inserts and searches fail with
"getQuadrant: impossible case".

To fix, fall back to deciding each axis separately: Use fuzzy tests
first and then tiebreak with exact comparisons. That gives every finite
value a quadrant (NaN coordinates are still an error). Points that
matched a fuzzy test before are routed as before, so existing indexes
remain valid.

Bug: #19597
Reported-by: Michael Malis <malis@pgrust.com>
Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Andrey Rachitskiy <pl0h0yp1@gmail.com>
Reviewed-by: Pierre Forstmann <pierre.forstmann@gmail.com>
Discussion: https://postgr.es/m/19597-39c532e61d78dff6@postgresql.org
Backpatch-through: 14

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/235e15ec7b5a1200394ca37c6b58b500b7ac1284

Modified Files
--------------
src/backend/access/spgist/spgquadtreeproc.c | 43 +++++++++++++++++++++++++++--
src/test/regress/expected/spgist.out        | 16 +++++++++++
src/test/regress/sql/spgist.sql             | 13 +++++++++
3 files changed, 70 insertions(+), 2 deletions(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1xGx7l-00000001aVB-3SfA@gemulon.postgresql.org>
Permalink:  ../E1xGx7l-00000001aVB-3SfA@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xGx7l-00000001aVB-3SfA@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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: john.naylor@postgresql.org
  Subject: Re: pgsql: Plug holes in SP-GiST quad tree getQuadrant()
  In-Reply-To: <E1xGx7l-00000001aVB-3SfA@gemulon.postgresql.org>
  References: <E1xGx7l-00000001aVB-3SfA@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