Re: Can someone explain the problem with this select

From: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
To: Richard Ray <rray(at)mstc(dot)state(dot)ms(dot)us>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Can someone explain the problem with this select
Date: 2006-12-05 21:15:28
Message-ID: 159771.63914.qm@web31810.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> 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);

This query is preforming the join on all records of your two tables. After all of the that
exhaustive work is done, it this filter out the records you want. you should preform a filtered
select first and then use those results in you left join. I guess the lesson you can learn from
this example is that you should try to filter your data set to get it as small as possible before
you do anything else with it.

select
*

from
(
select doc_num from documents limit 10
) as D1
left outer join
comments
on
(D1.doc_num = comments.doc_num)
;

Regards,

Richard Broersma Jr.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Ray 2006-12-05 21:21:41 Re: Can someone explain the problem with this select
Previous Message Tom Lane 2006-12-05 21:14:23 Re: Can someone explain the problem with this select