From: John A Meinel <john@arbash-meinel.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Dan Harris <fbsd@drivefaster.net>
Cc: pgsql-performance@postgresql.org
Subject: Re: slow joining very large table to smaller ones
Date: Thu, 14 Jul 2005 18:39:58 -0500
Message-ID: <42D6F7CE.5010007@arbash-meinel.com> (raw)
In-Reply-To: <5708.1121383802@sss.pgh.pa.us>
References: <46AF8F35-B735-4DFA-BA0A-AC82B5DA3CCE@drivefaster.net>
<42D687E5.7080202@arbash-meinel.com>
<C3470621-9DB0-444A-BAD1-F9995E0142FB@drivefaster.net>
<42D6F177.3000002@arbash-meinel.com>
<5708.1121383802@sss.pgh.pa.us>
Tom Lane wrote:
> John A Meinel <john@arbash-meinel.com> writes:
>
>>What I don't understand is that the planner is actually estimating that
>>joining against the new table is going to *increase* the number of
>>returned rows.
>
>
> It evidently thinks that incidentid in the k_r table is pretty
> nonunique. We really need to look at the statistics data to
> see what's going on.
>
> regards, tom lane
>
Okay, sure. What about doing this, then:
EXPLAIN ANALYZE
SELECT recordtext FROM eventactivity
JOIN (SELECT DISTINCT incidentid FROM k_r JOIN k_b USING (incidentid)
WHERE k_r.id = ?? AND k_b.id = ??)
USING (incidentid)
;
Since I assume that eventactivity is the only table with "recordtext",
and that you don't get any columns from k_r and k_b, meaning it would be
pointless to get duplicate incidentids.
I may be misunderstanding what the query is trying to do, but depending
on what is in k_r and k_b, is it possible to use a UNIQUE INDEX rather
than just an index on incidentid?
There is also the possibility of
EXPLAIN ANALYZE
SELECT recordtext FROM eventactivtity
JOIN (SELECT incidentid FROM k_r WHERE k_r.id = ??
UNION SELECT incidentid FROM k_b WHERE k_b.id = ??)
USING (incidentid)
;
But both of these would mean that you don't actually want columns from
k_r or k_b, just a unique list of incident ids.
But first, I agree, we should make sure the pg_stats values are reasonable.
John
=:->
Attachments:
signature.asc (application/pgp-signature, 252B) download
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: john@arbash-meinel.com, tgl@sss.pgh.pa.us, fbsd@drivefaster.net
Subject: Re: slow joining very large table to smaller ones
In-Reply-To: <42D6F7CE.5010007@arbash-meinel.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