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: Fix edge-case crashes and misestimation in range containment sel
Date: Sun, 12 Jan 2020 19:37:32 +0000
Message-ID: <E1iqj3E-0002Xp-TB@gemulon.postgresql.org> (raw)

Fix edge-case crashes and misestimation in range containment selectivity.

When estimating the selectivity of "range_var <@ range_constant" or
"range_var @> range_constant", if the upper (or respectively lower)
bound of the range_constant was above the last bin of the range_var's
histogram, the code would access uninitialized memory and potentially
crash (though it seems the probability of a crash is quite low).
Handle the endpoint cases explicitly to fix that.

While at it, be more paranoid about the possibility of getting NaN
or other silly results from the range type's subdiff function.
And improve some comments.

Ordinarily we'd probably add a regression test case demonstrating
the bug in unpatched code.  But it's too hard to get it to crash
reliably because of the uninitialized-memory dependence, so skip that.

Per bug #16122 from Adam Scott.  It's been broken from the beginning,
apparently, so backpatch to all supported branches.

Diagnosis by Michael Paquier, patch by Andrey Borodin and Tom Lane.

Discussion: https://postgr.es/m/16122-eb35bc248c806c15@postgresql.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/652686a334b437f57f9bd0e3baa5dbd245a9e15d

Modified Files
--------------
src/backend/utils/adt/rangetypes_selfuncs.c | 102 ++++++++++++++++++++--------
1 file changed, 72 insertions(+), 30 deletions(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1iqj3E-0002Xp-TB@gemulon.postgresql.org>
Permalink:  ../E1iqj3E-0002Xp-TB@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1iqj3E-0002Xp-TB@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: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Fix edge-case crashes and misestimation in range containment sel
  In-Reply-To: <E1iqj3E-0002Xp-TB@gemulon.postgresql.org>
  References: <E1iqj3E-0002Xp-TB@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