Re: New design for FK-based join selectivity estimation

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andrew Gierth <andrew@tao11.riddles.org.uk>
Cc: Tomas Vondra <tomas.vondra@2ndquadrant.com>, pgsql-hackers@postgresql.org
Date: 2016-06-29T19:34:25Z
Lists: pgsql-hackers
Andrew Gierth <andrew@tao11.riddles.org.uk> writes:
> If the query was produced by rule expansion then the code that populates
> fkinfo includes FK references to the OLD and NEW RTEs, but those might not
> appear in the jointree (the testcase for the bug is a DELETE rule where
> NEW clearly doesn't apply) and hence build_simple_rel was not called
> (causing find_base_rel to fail). Not sure what the right fix is.

Meh.  I had a vaguely uneasy feeling that just scanning the rtable was
too simplistic, but hadn't thought hard about it.

For a really correct fix we could search the jointree to see which rels
are in it, but that would add code and cycles.  A slightly cheating way to
do it is to not use find_base_rel() but look into the simple_rel_array for
ourselves, and do nothing if there's no rel corresponding to the RTE
index.

			regards, tom lane


Commits

  1. Fix FK-based join selectivity estimation for semi/antijoins.

  2. Restore foreign-key-aware estimation of join relation sizes.