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

From Simon Riggs
Subject pgsql: Use Foreign Key relationships to infer multi-column join selecti
Date
Msg-id E1aoLaS-0005ZY-QL@gemulon.postgresql.org
Whole thread Raw
List 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.3090707@2ndquadrant.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(-)


pgsql-committers by date:

Previous
From: Peter Geoghegan
Date:
Subject: Re: pgsql: Load FK defs into relcache for use by planner
Next
From: Tom Lane
Date:
Subject: Re: pgsql: Phrase full text search.