pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tomas.vondra@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Recognize some OR clauses as compatible with functional dependen
Date: Wed, 18 Mar 2020 15:52:39 +0000
Message-ID: <E1jEazn-0008Ic-4T@gemulon.postgresql.org> (raw)

Recognize some OR clauses as compatible with functional dependencies

Since commit 8f321bd16c functional dependencies can handle IN clauses,
which however introduced a possible (and surprising) inconsistency,
because IN clauses may be expressed as an OR clause, which are still
considered incompatible. For example

  a IN (1, 2, 3)

may be rewritten as

  (a = 1 OR a = 2 OR a = 3)

The IN clause will work fine with functional dependencies, but the OR
clause will force the estimation to fall back to plain per-column
estimates, possibly introducing significant estimation errors.

This commit recognizes OR clauses equivalent to an IN clause (when all
arugments are compatible and reference the same attribute) as a special
case, compatible with functional dependencies. This allows applying
functional dependencies, just like for IN clauses.

This does not eliminate the difference in estimating the clause itself,
i.e. IN clause and OR clause still use different formulas. It would be
possible to change that (for these special OR clauses), but that's not
really about extended statistics - it was always like this. Moreover the
errors are usually much smaller compared to ignoring dependencies.

Author: Tomas Vondra
Reviewed-by: Dean Rasheed
Discussion: https://www.postgresql.org/message-id/flat/13902317.Eha0YfKkKy%40pierred-pdoc

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/ccaa3569f58796868303629bc2d63ddddb599b38

Modified Files
--------------
src/backend/statistics/dependencies.c   | 65 +++++++++++++++++++++++++--------
src/test/regress/expected/stats_ext.out | 52 ++++++++++++++++++++++++++
src/test/regress/sql/stats_ext.sql      | 20 ++++++++++
3 files changed, 121 insertions(+), 16 deletions(-)



Message-ID: <E1jEazn-0008Ic-4T@gemulon.postgresql.org>
Permalink:  ../E1jEazn-0008Ic-4T@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1jEazn-0008Ic-4T@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: tomas.vondra@postgresql.org
  Subject: Re: pgsql: Recognize some OR clauses as compatible with functional dependen
  In-Reply-To: <E1jEazn-0008Ic-4T@gemulon.postgresql.org>
  References: <E1jEazn-0008Ic-4T@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