From: Tom Lane <tgl@sss.pgh.pa.us>
To: Dmitry Potapov <fortune.fish@gmail.com>
Cc: Guillaume Smet <guillaume.smet@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: planner chooses unoptimal plan on joins with complex key
Date: Thu, 24 Jan 2008 21:27:01 -0500
Message-ID: <21624.1201228021@sss.pgh.pa.us> (raw)
In-Reply-To: <878c83960801240803i3d94efc5n34160559bbd91aad@mail.gmail.com>
References: <878c83960801230548i6bee9353m19bcee7335220c9b@mail.gmail.com>
<1d4e0c10801230558i1e56a9dcgaa9e6c2fac6d0448@mail.gmail.com>
<22362.1201108676@sss.pgh.pa.us>
<878c83960801240803i3d94efc5n34160559bbd91aad@mail.gmail.com>
"Dmitry Potapov" <fortune.fish@gmail.com> writes:
> Sorry, it was just EXPLAIN. I can't run EXPLAIN ANALYZE on that
> (production) server, so I uploaded 3days old backup to a spare box and
> here's what I've got:
> -> Merge Join (cost=0.00..4955790.28 rows=1 width=59)
> (actual time=0.048..4575782.472 rows=30805113 loops=1)
> Merge Cond: ((t1.m1 = t2.m1) AND (t1.m2 = t2.m2) AND
> (t1.m3 = t2.m3))
Well, there's our problem: an estimate of 1 row for a join that's
actually 30805113 rows is uncool :-(.
It's hard to tell whether the planner is just being overoptimistic
about the results of ANDing the three join conditions, or if one or
more of the basic condition selectivities were misestimated. Could
you try
explain analyze select 1 from t1, t2 where t1.m1 = t2.m1;
explain analyze select 1 from t1, t2 where t1.m2 = t2.m2;
explain analyze select 1 from t1, t2 where t1.m3 = t2.m3;
and show the results? This will probably be slow too, but we don't
care --- we just need to see the estimated and actual rowcounts.
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 using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tgl@sss.pgh.pa.us, fortune.fish@gmail.com, guillaume.smet@gmail.com
Subject: Re: planner chooses unoptimal plan on joins with complex key
In-Reply-To: <21624.1201228021@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