From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andres Freund <andres@anarazel.de>
Cc: pgsql-bugs@postgresql.org
Cc: casey.shobe@messagesystems.com
Subject: Re: Botched estimation in eqjoinsel_semi for cases without reliable ndistinct
Date: Wed, 11 Jan 2012 20:24:44 -0500
Message-ID: <1378.1326331484@sss.pgh.pa.us> (raw)
In-Reply-To: <201201120140.35229.andres@anarazel.de>
References: <201201112110.40403.andres@anarazel.de>
<29570.1326326461@sss.pgh.pa.us>
<201201120140.35229.andres@anarazel.de>
Andres Freund <andres@anarazel.de> writes:
> On Thursday, January 12, 2012 01:01:01 AM Tom Lane wrote:
>> Looks pretty bogus to me. You're essentially assuming that the side of
>> the join without statistics is unique, which is a mighty dubious
>> assumption.
> It sure is a bit dubious. But assuming that a semijoin that has max of n rows
> on the inner side results in half of the outer sides rows (>> n) is pretty
> bogus as well.
How so? There is no reason to think that the number of LHS rows with a
match is limited by the number of RHS rows. If we knew that the LHS
join key was unique, then yes that'd be sensible, but we don't know
that.
> SELECT * FROM blub WHERE foo IN (SELECT something_with_aggregation);
> is not exactly a fringe case, so I find it problematic regressing
> quite a bit in the estimates.
Agreed, and that's why I don't want to put in a patch that carries the
risk of regressing even more. I'm happy to do something that's got some
amount of theory behind it, but if we're just guessing, we can't afford
to guess a very high or low selectivity.
One thing I've considered but not done anything about is that in a lot
of practical cases for this, the aggregation or grouping properties of
the sub-select would provide adequate reason for assuming its output is
more or less unique, so that taking ndistinct equal to number of rows
actually is sane. But it would need a bit of thought about what
properties we want to treat as justifying such an assumption, and then
some code to see if the join key is a Var coming out of such a
sub-select. (Actually, what such a patch would probably look like is
modifying examine_simple_variable to not just punt when it finds the
Var came from an aggregating subquery.)
regards, tom lane
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-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, andres@anarazel.de, casey.shobe@messagesystems.com
Subject: Re: Botched estimation in eqjoinsel_semi for cases without reliable ndistinct
In-Reply-To: <1378.1326331484@sss.pgh.pa.us>
References: <201201112110.40403.andres@anarazel.de> <29570.1326326461@sss.pgh.pa.us> <201201120140.35229.andres@anarazel.de> <1378.1326331484@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