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: 135
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

Active Member


Joined: 07 Feb 2009
Posts: 989
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: 6966
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: 135
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: 6966
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 Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


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