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@postgresql.org
Subject: pgsql: Distinguish selectivity of < from <= and > from >=.
Date: Wed, 13 Sep 2017 15:12:57 +0000
Message-ID: <E1ds9LV-0000B9-E1@gemulon.postgresql.org> (raw)
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-committers>

Distinguish selectivity of < from <= and > from >=.

Historically, the selectivity functions have simply not distinguished
< from <=, or > from >=, arguing that the fraction of the population that
satisfies the "=" aspect can be considered to be vanishingly small, if the
comparison value isn't any of the most-common-values for the variable.
(If it is, the code path that executes the operator against each MCV will
take care of things properly.)  But that isn't really true unless we're
dealing with a continuum of variable values, and in practice we seldom are.
If "x = const" would estimate a nonzero number of rows for a given const
value, then it follows that we ought to estimate different numbers of rows
for "x < const" and "x <= const", even if the const is not one of the MCVs.
Handling this more honestly makes a significant difference in edge cases,
such as the estimate for a tight range (x BETWEEN y AND z where y and z
are close together).

Hence, split scalarltsel into scalarltsel/scalarlesel, and similarly
split scalargtsel into scalargtsel/scalargesel.  Adjust <= and >=
operator definitions to reference the new selectivity functions.
Improve the core ineq_histogram_selectivity() function to make a
correction for equality.  (Along the way, I learned quite a bit about
exactly why that function gives good answers, which I tried to memorialize
in improved comments.)

The corresponding join selectivity functions were, and remain, just stubs.
But I chose to split them similarly, to avoid confusion and to prevent the
need for doing this exercise again if someone ever makes them less stubby.

In passing, change ineq_histogram_selectivity's clamp for extreme
probability estimates so that it varies depending on the histogram
size, instead of being hardwired at 0.0001.  With the default histogram
size of 100 entries, you still get the old clamp value, but bigger
histograms should allow us to put more faith in edge values.

Tom Lane, reviewed by Aleksander Alekseev and Kuntal Ghosh

Discussion: https://postgr.es/m/12232.1499140410@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/7d08ce286cd5854d58152e428c28636a616bdc42

Modified Files
--------------
contrib/citext/Makefile                |   3 +-
contrib/citext/citext--1.4--1.5.sql    |  14 ++
contrib/citext/citext.control          |   2 +-
contrib/cube/Makefile                  |   3 +-
contrib/cube/cube--1.2--1.3.sql        |  12 ++
contrib/cube/cube.control              |   2 +-
contrib/hstore/Makefile                |   3 +-
contrib/hstore/hstore--1.4--1.5.sql    |  14 ++
contrib/hstore/hstore.control          |   2 +-
contrib/isn/Makefile                   |   3 +-
contrib/isn/isn--1.1--1.2.sql          | 228 +++++++++++++++++++++++
contrib/isn/isn.control                |   2 +-
doc/src/sgml/xindex.sgml               |   3 +-
doc/src/sgml/xoper.sgml                |  35 ++--
src/backend/optimizer/path/clausesel.c |  14 +-
src/backend/utils/adt/network.c        |   4 +-
src/backend/utils/adt/selfuncs.c       | 323 +++++++++++++++++++++------------
src/include/catalog/catversion.h       |   2 +-
src/include/catalog/pg_operator.h      | 224 +++++++++++------------
src/include/catalog/pg_proc.h          |   9 +
src/tutorial/complex.source            |   4 +-
21 files changed, 633 insertions(+), 273 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


Message-ID: <E1ds9LV-0000B9-E1@gemulon.postgresql.org>
Permalink:  ../E1ds9LV-0000B9-E1@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1ds9LV-0000B9-E1@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: Distinguish selectivity of < from <= and > from >=.
  In-Reply-To: <E1ds9LV-0000B9-E1@gemulon.postgresql.org>
  References: <E1ds9LV-0000B9-E1@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