pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kynn Jones <kynnjo@gmail.com>
To: pgsql-performance@postgresql.org
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Subject: Re: Optimizing a huge_table/tiny_table join
Date: Thu, 25 May 2006 12:21:53 -0400
Message-ID: <c2350ba40605250921m1d83299ah72ec8b4da31d281@mail.gmail.com> (raw)
In-Reply-To: <7082.1148521319@sss.pgh.pa.us>
References: <200605250052.k4P0qrT11965@panix3.panix.com>
	<7082.1148521319@sss.pgh.pa.us>

On 5/24/06, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> <kynn@panix.com> writes:
> >  Limit  (cost=19676.75..21327.99 rows=6000 width=84)
> >    ->  Hash Join  (cost=19676.75..1062244.81 rows=3788315 width=84)
> >          Hash Cond: (upper(("outer".id)::text) =
> upper(("inner".id)::text))
> >          ->  Seq Scan on huge_table h  (cost=0.00..51292.43 rows=2525543
> width=46)
> >          ->  Hash  (cost=19676.00..19676.00 rows=300 width=38)
> >                ->  Seq Scan on tiny_table t  (cost=0.00..19676.00rows=300 width=38)
>
> Um, if huge_table is so much bigger than tiny_table, why are the cost
> estimates for seqscanning them only about 2.5x different?  There's
> something wacko about your statistics, methinks.



You mean there's a bug in explain?  I agree that it makes no sense that the
costs don't differ as much as one would expect, but you can see right there
the numbers of rows for the two tables, which are exactly as I described.
At any rate, how would one go about finding an explanation for these strange
stats?

More bewildering still (and infuriating as hell--because it means that all
of my work for yesterday has been wasted) is that I can no longer reproduce
the best query plan, even though the tables have not changed at all.  (Hence
I can't post the explain analyze for the best query plan.)  No matter what
value I use for LIMIT, the query planner now insists on sequentially
scanning huge_table and ignoring the available index.  (If I turn off
enable_seqscan, I get the second worst query plan I posted yesterday.)

Anyway, I take it that there is no way to bypass the optimizer and instruct
PostgreSQL exactly how one wants the search performed?

Thanks!

kj

view thread (12+ messages)  latest in thread

Message-ID: <c2350ba40605250921m1d83299ah72ec8b4da31d281@mail.gmail.com>
Permalink:  ../c2350ba40605250921m1d83299ah72ec8b4da31d281@mail.gmail.com/
Also on:    postgresql.org/message-id/c2350ba40605250921m1d83299ah72ec8b4da31d281@mail.gmail.com

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: kynnjo@gmail.com, tgl@sss.pgh.pa.us
  Subject: Re: Optimizing a huge_table/tiny_table join
  In-Reply-To: <c2350ba40605250921m1d83299ah72ec8b4da31d281@mail.gmail.com>

* 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