pgsql: Use Foreign Key relationships to infer multi-column join selecti

From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Use Foreign Key relationships to infer multi-column join selecti
Date: 2016-04-08 01:51:52
Message-ID: E1aoLaS-0005ZY-QL@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Use Foreign Key relationships to infer multi-column join selectivity

In cases where joins use multiple columns we currently assess each join
separately causing gross mis-estimates for join cardinality.

This patch adds use of FK information for the first time into the
planner. When FKs are present and we have multi-column join information,
plan estimates will be drastically improved. Cases with multiple FKs
are handled, though partial matches are ignored currently.

Net effect is substantial performance improvements for joins in many
common cases. Additional planning time is isolated to cases that are
currently performing poorly, measured at 0.08 - 0.15 ms.

Please watch for planner performance regressions; circumstances seem
unlikely but the law of unintended consequences may apply somewhen.
Additional complex tests welcome to prove this before release.

Tests can be performed using SET enable_fkey_estimates = on | off
using scripts provided during Hackers discussions, message id:
552335D9(dot)3090707(at)2ndquadrant(dot)com

Authors: Tomas Vondra and David Rowley
Reviewed and tested by Simon Riggs, adding comments only

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/137805f89acb361144ec98d9847e26d2848aa57e

Modified Files
--------------
src/backend/optimizer/path/costsize.c | 375 ++++++++++++++++++++++++++++++-
src/backend/utils/misc/guc.c | 9 +
src/include/optimizer/cost.h | 1 +
src/include/optimizer/paths.h | 2 +
src/test/regress/expected/rangefuncs.out | 29 +--
5 files changed, 392 insertions(+), 24 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2016-04-08 02:19:18 Re: pgsql: Phrase full text search.
Previous Message Peter Geoghegan 2016-04-08 00:23:54 Re: pgsql: Load FK defs into relcache for use by planner