On Fri, Nov 27, 2026 at 5:43 AM Tom Lane <[email protected]> wrote: > > Ewan Young <[email protected]> writes: > > 15b3dc140d9 fixed overflow in btree_gist's date/float8/timestamp penalty > > and distance functions, but the numeric opclass has the same problem. > > Yeah, we should fix this, but your v1 doesn't feel quite right to me. > > 1. Wouldn't it make more sense to treat an overflowed subtraction > result as Infinity rather than NaN? That's what happens in > gbt_float8_dist() since 15b3dc140d9.
Agreed, done -- an overflowed width is now treated as infinite. > > 2. I'm unconvinced that the ds calculation is entirely safe yet. > In particular, it seems we could be computing Inf - Inf there, > which will yield NaN when we'd rather get zero. Right. v2 attached, which handles a NaN or infinite width (whether from an overflow or an actual infinite bound) up front, so ds = us - os only runs when us is finite. > > regards, tom lane -- Regards, Ewan Young
v2-0001-btree_gist-avoid-numeric-overflow-in-gbt_numeric_penalty.patch
Description: Binary data
