Re: Help optimize view

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: <pgsql-performance(at)postgresql(dot)org>, "Mike Relyea" <Mike(dot)Relyea(at)xerox(dot)com>
Subject: Re: Help optimize view
Date: 2007-08-19 01:01:50
Message-ID: 46C7502D.EE98.0025.0@wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

>>> On Fri, Aug 10, 2007 at 11:57 AM, in message
<1806D1F73FCB7F439F2C842EE0627B18065BEC18(at)usa0300ms01(dot)na(dot)xerox(dot)net>, "Relyea,
Mike" <Mike(dot)Relyea(at)xerox(dot)com> wrote:
> I'm have the following view as part of a larger, aggregate query that is
> running slower than I'd like.
> . . .
> HAVING "PrintSamples"."MachineID" = 4741 OR "PrintSamples"."MachineID" =
> 4745 AND "AnalysisModules"."AnalysisModuleName" = 'NMF' AND
> "ParameterNames"."ParameterName" = 'NMF' AND "tblColors"."ColorID" <> 3
> AND "PrintSamples"."TestPatternName" LIKE 'IQAF-TP8%';

First off, let's make sure we're optimizing the query you really want to run.
AND binds tighter than OR, so as you have it written, it is the same as:

HAVING "PrintSamples"."MachineID" = 4741
OR ( "PrintSamples"."MachineID" = 4745
AND "AnalysisModules"."AnalysisModuleName" = 'NMF'
AND "ParameterNames"."ParameterName" = 'NMF'
AND "tblColors"."ColorID" <> 3
AND "PrintSamples"."TestPatternName" LIKE 'IQAF-TP8%';
)

I fear you may really want it evaluate to:

HAVING ("PrintSamples"."MachineID" = 4741 OR "PrintSamples"."MachineID" = 4745)
AND "AnalysisModules"."AnalysisModuleName" = 'NMF'
AND "ParameterNames"."ParameterName" = 'NMF'
AND "tblColors"."ColorID" <> 3
AND "PrintSamples"."TestPatternName" LIKE 'IQAF-TP8%';

-Kevin

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Kevin Grittner 2007-08-19 01:11:59 Re: Help optimize view
Previous Message Henrik 2007-08-18 11:11:58 Re: Fwd: Table Partitioning