Re: Query tuning help - Mailing list pgsql-performance

From Ulrich Wisser
Subject Re: Query tuning help
Date
Msg-id 4281FEE3.6080506@relevanttraffic.se
Whole thread Raw
In response to Query tuning help  (Dan Harris <fbsd@drivefaster.net>)
List pgsql-performance
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

pgsql-performance by date:

Previous
From: Christopher Kings-Lynne
Date:
Subject: Re: Partitioning / Clustering
Next
From: Tom Lane
Date:
Subject: Re: Partitioning / Clustering