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: Fix neqjoinsel's behavior for semi/anti join cases.
Date: Thu, 30 Nov 2017 03:01:48 +0000
Message-ID: <E1eKF6i-0001Rr-Hk@gemulon.postgresql.org> (raw)

Fix neqjoinsel's behavior for semi/anti join cases.

Previously, this function estimated the selectivity as 1 minus eqjoinsel()
for the negator equality operator, regardless of join type (I think there
was an expectation that eqjoinsel would handle the join type).  But
actually this is completely wrong for semijoin cases: the fraction of the
LHS that has a non-matching row is not one minus the fraction of the LHS
that has a matching row.  In reality a semijoin with <> will nearly always
succeed: it can only fail when the RHS is empty, or it contains a single
distinct value that is equal to the particular LHS value, or the LHS value
is null.  The only one of those things we should have much confidence in
estimating is the fraction of LHS values that are null, so let's just take
the selectivity as 1 minus outer nullfrac.

Per coding convention, antijoin should be estimated the same as semijoin.

Arguably this is a bug fix, but in view of the lack of field complaints
and the risk of destabilizing plans, no back-patch.

Thomas Munro, reviewed by Ashutosh Bapat

Discussion: https://postgr.es/m/CAEepm=270ze2hVxWkJw-5eKzc3AB4C9KpH3L2kih75R5pdSogg@mail.gmail.com

Branch
------
master

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

Modified Files
--------------
src/backend/utils/adt/selfuncs.c   | 70 +++++++++++++++++++++++++++++---------
src/test/regress/expected/join.out | 22 ++++++++++++
src/test/regress/sql/join.sql      |  9 +++++
3 files changed, 85 insertions(+), 16 deletions(-)



Message-ID: <E1eKF6i-0001Rr-Hk@gemulon.postgresql.org>
Permalink:  ../E1eKF6i-0001Rr-Hk@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1eKF6i-0001Rr-Hk@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 neqjoinsel's behavior for semi/anti join cases.
  In-Reply-To: <E1eKF6i-0001Rr-Hk@gemulon.postgresql.org>
  References: <E1eKF6i-0001Rr-Hk@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