X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id AD81B537E0 for ; Sun, 8 May 2005 23:49:14 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 74178-08 for ; Mon, 9 May 2005 02:49:06 +0000 (GMT) Received: from crestone.coronasolutions.com (crestone.coronasolutions.com [66.45.104.24]) by svr1.postgresql.org (Postfix) with ESMTP id D7EA852AA9 for ; Sun, 8 May 2005 23:49:05 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by crestone.coronasolutions.com (Postfix) with ESMTP id A94E36440DF for ; Sun, 8 May 2005 20:49:02 -0600 (MDT) Received: from crestone.coronasolutions.com ([127.0.0.1]) by localhost (crestone.coronasolutions.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 26395-05 for ; Sun, 8 May 2005 20:49:01 -0600 (MDT) Received: from [192.168.1.3] (c-24-9-111-5.hsd1.co.comcast.net [24.9.111.5]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by crestone.coronasolutions.com (Postfix) with ESMTP id D913F6440C9 for ; Sun, 8 May 2005 20:49:01 -0600 (MDT) Mime-Version: 1.0 (Apple Message framework v622) In-Reply-To: <200505091232.05495.mr-russ@pws.com.au> References: <924ac6c029f5453c442eacdda06b132c@drivefaster.net> <200505091051.14689.mr-russ@pws.com.au> <6f4a543a2fbd348c7e82876b8e477600@drivefaster.net> <200505091232.05495.mr-russ@pws.com.au> Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: <93c69c01ae38d2b95c902e05da1ffe19@drivefaster.net> Content-Transfer-Encoding: 7bit From: Dan Harris Subject: Re: Query tuning help Date: Sun, 8 May 2005 20:49:07 -0600 To: pgsql-performance@postgresql.org X-Mailer: Apple Mail (2.622) X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at drivefaster.net X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200505/97 X-Sequence-Number: 12261 On May 8, 2005, at 8:32 PM, Russell Smith wrote: >> I have run this, and while it is very fast, I'm concerned it's not >> doing what I need. > How fast is very fast? > It took 35 seconds to complete versus ~450 my old way. > > select distinct em.incidentid, ea.recordtext as retdata, eg.long, > eg.lat > FROM em JOIN ea ON (em.incidentid = ea.incidentid AND em.entrydate >= > '2005-1-1 00:00' > AND em.entrydate <= '2005-5-9 00:00' AND (ea.recordtext like '%RED%' > OR ea.recordtext like '%CORVETTE%')) > JOIN eg ON em.incidentid = eg.incidentid WHERE > em.incidentid IN > (select distinct em.incidentid, ea.recordtext as retdata, eg.long, > eg.lat > FROM em JOIN ea ON (em.incidentid = ea.incidentid AND em.entrydate >= > '2005-1-1 00:00' > AND em.entrydate <= '2005-5-9 00:00' AND ea.recordtext like > '%CORVETTE%')) > JOIN eg ON em.incidentid = eg.incidentid) AND > em.incidentid IN > (select distinct em.incidentid, ea.recordtext as retdata, eg.long, > eg.lat > FROM em JOIN ea ON (em.incidentid = ea.incidentid AND em.entrydate >= > '2005-1-1 00:00' > AND em.entrydate <= '2005-5-9 00:00' AND ea.recordtext like '%RED%')) > JOIN eg ON em.incidentid = eg.incidentid) > Yes, it is nasty, but so was my previous query :) So long as this is faster, I'm ok with that. I'll see if i can make this work. Thank you very much. -Dan