Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 3A61C9FA173 for ; Tue, 5 Dec 2006 17:15:41 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 83742-10 for ; Tue, 5 Dec 2006 17:15:23 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from web31810.mail.mud.yahoo.com (web31810.mail.mud.yahoo.com [68.142.207.73]) by postgresql.org (Postfix) with SMTP id 0FF8E9FA4A5 for ; Tue, 5 Dec 2006 17:15:30 -0400 (AST) Received: (qmail 67498 invoked by uid 60001); 5 Dec 2006 21:15:28 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=0tXmhHo35tlmwRGjUEa2+rKwH4oSRmRLwMKruxgs2s7Rq9ufUGrkRdL3rRTFfhlXrDUthGZZ4N0QO0hGE3IifNJjpPIhpIOa6YFJz4S28tMdBEYvCOMHWriKazsCX/kZRjmRFL2FyME2QAjX2OBKoZUUA5OsxBwIlgcuw7JFII4=; X-YMail-OSG: qapCbH0VM1lVcFLEmBLevs3_a7DfpaGX1PCO.k08az0wv8q372PpR6UXmbg_XFCBsIloGm5MK9nANOMUFt9ElTXfcBUQPZn_zWMLbEYQEhXxncbQcYLWo10tlJNdLWmFqiBQQHmW9Y46VYI- Received: from [12.177.97.50] by web31810.mail.mud.yahoo.com via HTTP; Tue, 05 Dec 2006 13:15:28 PST Date: Tue, 5 Dec 2006 13:15:28 -0800 (PST) From: Richard Broersma Jr Subject: Re: Can someone explain the problem with this select To: Richard Ray , pgsql-sql@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <159771.63914.qm@web31810.mail.mud.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.51 tagged_above=0 required=5 tests=AWL, BAYES_50, DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST, DNS_FROM_RFC_WHOIS X-Spam-Level: * X-Archive-Number: 200612/60 X-Sequence-Number: 27016 > 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.