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 AF8BE54B1B for ; Wed, 11 May 2005 09:46:06 -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 02638-04 for ; Wed, 11 May 2005 12:46:04 +0000 (GMT) Received: from thor.netera.se (thor.netera.se [85.112.172.11]) by svr1.postgresql.org (Postfix) with ESMTP id 2039F54B1A for ; Wed, 11 May 2005 09:45:59 -0300 (ADT) Received: from [192.168.2.240] (1-1-1-41a.o.sth.bostream.se [81.26.246.14]) by thor.netera.se (Postfix) with ESMTP id D53D413AC07A; Wed, 11 May 2005 14:45:58 +0200 (CEST) Message-ID: <4281FEE3.6080506@relevanttraffic.se> Date: Wed, 11 May 2005 14:47:31 +0200 From: Ulrich Wisser Organization: Relevant Traffic AB User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Dan Harris Cc: pgsql-performance@postgresql.org Subject: Re: Query tuning help References: <924ac6c029f5453c442eacdda06b132c@drivefaster.net> In-Reply-To: <924ac6c029f5453c442eacdda06b132c@drivefaster.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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/199 X-Sequence-Number: 12363 Hi Dan, I tried to understand your query, but I couldn't get my understanding of the query and your description in sync. Why do you use sub selects? Wouldn't a simple "recordtext like '%RED%'" do the trick too? You combine all your where conditions with and. To me this looks like you get only rows with RED and CORVETTE. From your description I would rewrite the query as explain analyze select distinct em.incidentid, ea.recordtext as retdata, eg.long, eg.lat from ea join em using(incidentid) join eg using(incidentid) where em.entrydate >= '2005-1-1 00:00'::date and em.entrydate <= '2005-5-9 00:00'::date and ( recordtext like '%RED%' or recordtext like '%CORVETTE%' ) order by em.entrydate That should give you all rows containing one of the words. Does it work? Is is faster? Is it fast enough? Ulrich