View previous topic :: View next topic
|
Author |
Message |
abdulrafi
Active User
Joined: 14 Sep 2009 Posts: 184 Location: Coimbatore
|
|
|
|
Hi,
I have a select query like the one below,
SELECT A.Q_COLOR_PNTDSQFT
,A.I_PMIT_GRP
,A.I_PMIT
,A.I_CORPLOC
,A.I_YR
,A.I_MO
,A.I_DAY
,A.I_PMIT_CMPLNC
,A.C_BDY
,A.C_COLOR
FROM P.PDCRPT A
WHERE
A.I_PMIT_GRP = 'TOPCOAT DAILY COMPLIANCE '
AND A.I_PMIT > X'00' AND A.I_PMIT < X'FF'
AND A.I_CORPLOC >= ' '
AND A.I_YR >= ' '
AND A.I_MO >= ' '
AND A.I_DAY >= ' '
AND A.I_PMIT_CMPLNC >= ' '
AND A.C_BDY >= ' '
AND A.C_COLOR >= ' '
ORDER BY A.I_CORPLOC,A.I_YR,A.I_MO,A.I_DAY
;
it takes nearly 126 qunits and 0.00500 of cpu time which is very high. i have 10 more queries like these. when moved to production it runs for 4 hrs. i tried my level best to optimize it, but even then i am not able to. for the values which i can, i have given values for it. I have provided all indexes too.
please help me out If there is any solution to reduce the cpu time and run the query effectively. |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
Wow, maybe next time you can also give the definition of the table and indices. We can only read minds on leap days in century years. |
|
Back to top |
|
|
chandracdac
New User
Joined: 15 Jun 2007 Posts: 92 Location: bangalore
|
|
|
|
Hi
as per my knowledge and my observation if there are more conditions in where clause it will take more time to execute the query. pls try to reduce that no of condition in ur where clause as per your requirement.
Thanks,
Chandra |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
use between for things like this:
AND A.I_PMIT > X'00' AND A.I_PMIT < X'FF'
AND A.I_PMIT BETWEEN X'01' AND X'FE'
chandracdac wrote: |
as per my knowledge and my observation if there are more conditions in where clause it will take more time to execute the query |
The quantity of WHERE clause conditions is not the problem.
you can have a large quantity of quality predicates that will enhance the query.
depends on the predicate stage.
Stage 1 predicates function better than Stage2.
Stage 2 precludes the use of indexes.
The idea of WHERE clause is to reduce the result set. |
|
Back to top |
|
|
abdulrafi
Active User
Joined: 14 Sep 2009 Posts: 184 Location: Coimbatore
|
|
|
|
Hi,
I tried BETWEEN option(A.I_PMIT BETWEEN X'01' AND X'FE'), but it dint make a difference. I am investigating still on how i could reduce the CPU usage time.
If any help it would be appreciable. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
you should start with an EXPLAIN which,
among other things,
will help you identify index opportunities.
The between usage will aid in using indexes, if they are available. |
|
Back to top |
|
|
|