Re: Help optimize view

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>>> On Fri, Aug 10, 2007 at 11:57 AM, in message
<1806D1F73FCB7F439F2C842EE0627B18065BEC18@xxxxxxxxxxxxxxxxxxxxxxxx>, "Relyea,
Mike" <Mike.Relyea@xxxxxxxxx> 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
 



---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match


[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux