Re: Query tuning help

From: Dan Harris <fbsd(at)drivefaster(dot)net>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: Query tuning help
Date: 2005-05-09 02:49:07
Message-ID: 93c69c01ae38d2b95c902e05da1ffe19@drivefaster.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance


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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Klint Gore 2005-05-09 04:17:17 Re: Query tuning help
Previous Message Russell Smith 2005-05-09 02:32:05 Re: Query tuning help