Re: Compute the distance between a point and a box exactly

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Greg Burd <greg(at)burd(dot)me>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Compute the distance between a point and a box exactly
Date: 2026-12-04 20:44:19
Message-ID: 2499479.1796417059@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Greg Burd <greg(at)burd(dot)me> writes:
> An ordering GiST or SP-GiST scan uses the distance in two ways. For a
> key that is the indexed value, such as a box_ops leaf, the distance is
> the row's, and it must equal the operator's result, or the index and a
> seq scan disagree. For a key that only bounds the values below it, an
> internal key or a polygon's bounding box, the distance needs to be a
> lower bound, nothing more; the scan visits keys in that order, so a
> bound that is too high returns rows late. NaN is never a lower bound:
> it sorts after every number.

> Master breaks both rules. The operator's edge projection returns
> whatever the NaN comparisons happen to produce, and GiST's
> computeDistance() raises "inconsistent point values" (or fails an
> assertion) on a key that holds a NaN, which one NaN row anywhere in the
> subtree is enough to cause; that is bug #19937 [1].

TBH, we really need to start rejecting NaN coordinates in the
geometric types. It's tough enough to deal with infinities
(and maybe we'd reject those too if we were smart), but NaNs
don't even have any plausible geometric interpretation.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Ivan Alekseev 2026-12-04 20:53:01 Re: [PATCH] Release replication slot on error in SQL-callable slot functions
Previous Message Kacper Kuras 2026-12-04 20:42:22 Re: Proposal: SELECT * EXCLUDE (...) command