Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 78EC41337B61 for ; Thu, 3 Mar 2011 10:55:51 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 02559-01 for ; Thu, 3 Mar 2011 14:55:43 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from marajade.localdomain (vcs5.camavision.com [63.228.164.252]) by mail.postgresql.org (Postfix) with ESMTP id 47984133655C for ; Thu, 3 Mar 2011 10:55:42 -0400 (AST) Received: from [192.168.10.84] (unknown [192.168.10.84]) (Authenticated sender: andy) by marajade.localdomain (Postfix) with ESMTPA id B3F83407E8; Thu, 3 Mar 2011 08:55:42 -0600 (CST) Message-ID: <4D6FABF1.50206@squeakycode.net> Date: Thu, 03 Mar 2011 08:55:45 -0600 From: Andy Colson User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.14) Gecko/20110221 Lightning/1.0b2 Thunderbird/3.1.8 MIME-Version: 1.0 To: sverhagen CC: pgsql-performance@postgresql.org Subject: Re: Performance trouble finding records through related records References: <1299024855300-3405914.post@n5.nabble.com> <4D6DBC63.7080109@squeakycode.net> <1299111156142-3407330.post@n5.nabble.com> <4D6F054A.2090208@squeakycode.net> <1299143960277-3407689.post@n5.nabble.com> In-Reply-To: <1299143960277-3407689.post@n5.nabble.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.7 tagged_above=-10 required=5 tests=BAYES_00=-1.9, SARE_BAYES_5x7=0.6, SARE_BAYES_6x7=0.6 X-Spam-Level: X-Archive-Number: 201103/38 X-Sequence-Number: 42717 On 3/3/2011 3:19 AM, sverhagen wrote: > > 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! > Huh. Pretty much exactly the same. I'm sorry but I think I'm at my limit. I'm not sure why the nested loop takes so long, or how to get it to use something different. -Andy