pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Maxim Boguk <maxim.boguk@gmail.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #5885: Strange rows estimation for left join
Date: Tue, 15 Feb 2011 12:18:07 -0500
Message-ID: <23761.1297790287@sss.pgh.pa.us> (raw)
In-Reply-To: <AANLkTi=MbqQ6CA_C8K+XQ0Lg8b8h2e4TtnSXZKZ=15_T@mail.gmail.com>
References: <201102150243.p1F2hHge058708@wwwmaster.postgresql.org>
	<27062.1297740451@sss.pgh.pa.us>
	<AANLkTi=MbqQ6CA_C8K+XQ0Lg8b8h2e4TtnSXZKZ=15_T@mail.gmail.com>

Maxim Boguk <maxim.boguk@gmail.com> writes:
> Test case look like:

> create table "references" ( attr_id integer, reference integer,
> object_id integer );
> insert into "references" select *100**(random()),
> *100000**(random()^*10*), *1000000**(random()) from
> generate_series(*1*,*10000000*);
> create index xif01references on "references" ( reference, attr_id );
> create index xif02references on "references" ( object_id, attr_id, reference );

> analyze "references";

> explain select * from "references" rs left join "references" vm on
> vm.reference = rs.reference and vm.attr_id = *10* where rs.object_id =
> *1000*;

I don't believe there's actually anything very wrong here.  The
large-looking estimate for the join size is not out of line: if you try
different values for object_id you will find that some produce more rows
than that and some produce less.  If we had cross-column stats we could
maybe derive a better estimate, but as-is you're getting an estimate
that is probably about right on the average, depending on whether the
particular object_id matches to more common or less common reference
values.

The thing that looks funny is that the inner indexscan rowcount estimate
is so small, which is because that's being done on the assumption that
the passed-in rs.reference value is random.  It's not really --- it's
more likely to be one of the more common reference values --- which is
something that's correctly accounted for in the join size estimate but
not in the inner indexscan estimate.

			regards, tom lane



view thread (5+ messages)  latest in thread

Message-ID: <23761.1297790287@sss.pgh.pa.us>
Permalink:  ../23761.1297790287@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/23761.1297790287@sss.pgh.pa.us

 · 

reply

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, maxim.boguk@gmail.com
  Subject: Re: BUG #5885: Strange rows estimation for left join
  In-Reply-To: <23761.1297790287@sss.pgh.pa.us>
  References: <201102150243.p1F2hHge058708@wwwmaster.postgresql.org> <27062.1297740451@sss.pgh.pa.us> <AANLkTi=MbqQ6CA_C8K+XQ0Lg8b8h2e4TtnSXZKZ=15_T@mail.gmail.com> <23761.1297790287@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