From: Tom Lane <tgl@sss.pgh.pa.us>
To: ronan.dunklau@dalibo.com
Cc: pgsql-hackers@postgresql.org
Cc: Tomas Vondra <tomas.vondra@2ndquadrant.com>
Cc: Adrien Nayrat <adrien.nayrat@dalibo.com>
Subject: Re: New design for FK-based join selectivity estimation
Date: Tue, 13 Dec 2016 14:44:07 -0500
Message-ID: <23545.1481658247@sss.pgh.pa.us> (raw)
In-Reply-To: <3012483.BymkNIPMEm@ronan_laptop>
References: <31041.1465069446@sss.pgh.pa.us>
<13294.1466278050@sss.pgh.pa.us>
<9e35d4cb-a12d-7987-e23a-8a6020e01e88@dalibo.com>
<3012483.BymkNIPMEm@ronan_laptop>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
ronan.dunklau@dalibo.com writes:
> On mardi 13 décembre 2016 09:10:47 CET Adrien Nayrat wrote:
>> The commit 100340e2dcd05d6505082a8fe343fb2ef2fa5b2a introduce an
>> estimation error :
> The problem is, for semi and anti joins, we assume that we have nohing to do
> (costsize.c:4253):
> else if (jointype == JOIN_SEMI || jointype == JOIN_ANTI)
> {
> /*
> * For JOIN_SEMI and JOIN_ANTI, the selectivity is defined as the
> * fraction of LHS rows that have matches. If the referenced
> * table is on the inner side, that means the selectivity is 1.0
> * (modulo nulls, which we're ignoring for now). We already
> * covered the other case, so no work here.
> */
> }
> This results in assuming that the whole outerrel will match, no matter the
> selectivity of the innerrel.
Yeah. In the terms of this example, the FK means that every outer row
would have a match, if the query were
select * from t3 where j in (select * from t4);
But actually it's
select * from t3 where j in (select * from t4 where j<10);
so of course we should not expect a match for every row.
> If I understand it correctly and the above is right, I think we should ignore
> SEMI or ANTI joins altogether when considering FKs, and keep the corresponding
> restrictinfos for later processing since they are already special-cased later
> on.
That seems like an overreaction. While the old code happens to get this
example exactly right, eqjoinsel_semi is still full of assumptions and
approximations, and it doesn't do very well at all if it lacks MCV lists
for both sides.
I'm inclined to think that what we want to have happen in this case is
to estimate the fraction of outer rows having a match as equal to the
selectivity of the inner query's WHERE clauses, ie the semijoin
selectivity should be sizeof(inner result) divided by sizeof(inner
relation).
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
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-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us, ronan.dunklau@dalibo.com, tomas.vondra@2ndquadrant.com, adrien.nayrat@dalibo.com
Subject: Re: New design for FK-based join selectivity estimation
In-Reply-To: <23545.1481658247@sss.pgh.pa.us>
References: <31041.1465069446@sss.pgh.pa.us> <13294.1466278050@sss.pgh.pa.us> <9e35d4cb-a12d-7987-e23a-8a6020e01e88@dalibo.com> <3012483.BymkNIPMEm@ronan_laptop> <23545.1481658247@sss.pgh.pa.us>
* 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