Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 5B46F1337BC4 for ; Thu, 3 Mar 2011 05:19:29 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 24748-03 for ; Thu, 3 Mar 2011 09:19:22 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sam.nabble.com (sam.nabble.com [216.139.236.26]) by mail.postgresql.org (Postfix) with ESMTP id 44B18133655C for ; Thu, 3 Mar 2011 05:19:21 -0400 (AST) Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.69) (envelope-from ) id 1Pv4gq-0000il-9A for pgsql-performance@postgresql.org; Thu, 03 Mar 2011 01:19:20 -0800 Date: Thu, 3 Mar 2011 01:19:20 -0800 (PST) From: sverhagen To: pgsql-performance@postgresql.org Message-ID: <1299143960277-3407689.post@n5.nabble.com> In-Reply-To: <4D6F054A.2090208@squeakycode.net> References: <1299024855300-3405914.post@n5.nabble.com> <4D6DBC63.7080109@squeakycode.net> <1299111156142-3407330.post@n5.nabble.com> <4D6F054A.2090208@squeakycode.net> Subject: Re: Performance trouble finding records through related records MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.422 tagged_above=-10 required=5 tests=BAYES_00=-1.9, SARE_BAYES_5x7=0.6, SARE_BAYES_6x7=0.6, URI_HEX=1.122 X-Spam-Level: X-Archive-Number: 201103/35 X-Sequence-Number: 42714 Andy Colson wrote: > > For your query, I think a join would be the best bet, can we see its > explain analyze? > Here is a few variations: SELECT events_events.* FROM events_events WHERE transactionid IN ( SELECT transactionid FROM events_eventdetails customerDetails WHERE customerDetails.keyname='customer_id' AND substring(customerDetails.value,0,32)='1957' AND transactionid IS NOT NULL ) ORDER BY id LIMIT 50; -- http://explain.depesz.com/s/Pnb explain analyze SELECT events_events.* FROM events_events, events_eventdetails customerDetails WHERE events_events.transactionid = customerDetails.transactionid AND customerDetails.keyname='customer_id' AND substring(customerDetails.value,0,32)='1957' AND customerDetails.transactionid IS NOT NULL ORDER BY id LIMIT 50; -- http://explain.depesz.com/s/rDh explain analyze SELECT events_events.* FROM events_events JOIN events_eventdetails customerDetails ON events_events.transactionid = customerDetails.transactionid AND customerDetails.keyname='customer_id' AND substring(customerDetails.value,0,32)='1957' AND customerDetails.transactionid IS NOT NULL ORDER BY id LIMIT 50; -- http://explain.depesz.com/s/6aB Thanks for your efforts! -- View this message in context: http://postgresql.1045698.n5.nabble.com/Performance-trouble-finding-records-through-related-records-tp3405914p3407689.html Sent from the PostgreSQL - performance mailing list archive at Nabble.com.