Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

optimization of DB2 query

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 147
Location: Coimbatore

PostPosted: Thu Apr 07, 2011 5:01 am    Post subject: optimization of DB2 query
Reply with quote

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
View user's profile Send private message

prino

Senior Member


Joined: 07 Feb 2009
Posts: 1027
Location: Oostende, Belgium

PostPosted: Thu Apr 07, 2011 5:13 am    Post subject:
Reply with quote

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
View user's profile Send private message
chandracdac

New User


Joined: 15 Jun 2007
Posts: 92
Location: bangalore

PostPosted: Wed Apr 13, 2011 2:48 pm    Post subject: Reply to: optimization of DB2 query
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Wed Apr 13, 2011 4:33 pm    Post subject:
Reply with quote

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
View user's profile Send private message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 147
Location: Coimbatore

PostPosted: Fri Apr 15, 2011 3:30 am    Post subject: Reply to: optimization of DB2 query
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Fri Apr 15, 2011 9:45 am    Post subject:
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Omegamon for DB2 query ashek15 DB2 0 Wed Feb 15, 2017 11:25 am
No new posts Query on DB2 WLM stored procedures ashek15 DB2 8 Sun Feb 12, 2017 11:13 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us