From: Richard Ray <rray@mstc.state.ms.us>
To: pgsql-sql@postgresql.org
Subject: Re: Can someone explain the problem with this select
Date: Tue, 5 Dec 2006 15:21:41 -0600 (CST)
Message-ID: <Pine.LNX.4.64.0612051519450.20963@rray.drdc.mstc.ms.gov> (raw)
In-Reply-To: <11220.1165353263@sss.pgh.pa.us>
References: <Pine.LNX.4.64.0612051316260.20963@rray.drdc.mstc.ms.gov>
<11220.1165353263@sss.pgh.pa.us>
I've been foolin with this for a couple of days
Sometimes you just have to ask
Thanks gentlemen
On Tue, 5 Dec 2006, Tom Lane wrote:
> Richard Ray <rray@mstc.state.ms.us> writes:
>> dcc=# EXPLAIN ANALYZE select * from documents left outer join comments on
>> (documents.doc_num = comments.doc_num) where documents.doc_num in (select
>> doc_num from documents limit 10);
>> [ is slow ]
>
> This isn't your fault, it's an optimizer limitation: PG < 8.2 can't
> reorder outer joins relative to regular joins, and the IN with a
> sub-select is a kind of regular join. So it's forming the whole
> outer-join result and then joining to the sub-select :-(
>
> This is fixed in 8.2, released today, so perhaps upgrading is the
> thing for you to do. Alternatively, you can contort the query to
> get the IN restriction inside the outer join:
>
> select * from
> (select * from documents
> where documents.doc_num in (select doc_num from documents limit 10)) ss
> left outer join comments on (ss.doc_num = comments.doc_num);
>
> 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-sql@postgresql.org
Cc: rray@mstc.state.ms.us
Subject: Re: Can someone explain the problem with this select
In-Reply-To: <Pine.LNX.4.64.0612051519450.20963@rray.drdc.mstc.ms.gov>
References: <Pine.LNX.4.64.0612051316260.20963@rray.drdc.mstc.ms.gov> <11220.1165353263@sss.pgh.pa.us> <Pine.LNX.4.64.0612051519450.20963@rray.drdc.mstc.ms.gov>
* 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