IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Need to help to fine tune my Query.


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sreejeshcs

New User


Joined: 28 May 2007
Posts: 31
Location: Pune

PostPosted: Mon Jun 04, 2012 11:04 am
Reply with quote

Hi Below SQL is taking huge CPU time. Can some help me to fine tune it?

Code:
SELECT A.INTCMNBR               
FROM TABLE1 A   
WHERE A.CID = 12345           
AND A.CTRY = 263               
AND A.CMNBR NOT IN           
( SELECT B.CM_NO           
  FROM TABLE2 B         
  WHERE B.CTRY_CD='263'     
  AND B.CORP=12345           
  AND B.CM_NO=A.CMNBR)
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Mon Jun 04, 2012 11:09 am
Reply with quote

what have you tried so far?

Did you try executing an EXPLAIN??
Back to top
View user's profile Send private message
sreejeshcs

New User


Joined: 28 May 2007
Posts: 31
Location: Pune

PostPosted: Mon Jun 04, 2012 11:21 am
Reply with quote

No...
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Mon Jun 04, 2012 11:23 am
Reply with quote

Please try that

In order to do that first create a plan_table
Back to top
View user's profile Send private message
sreejeshcs

New User


Joined: 28 May 2007
Posts: 31
Location: Pune

PostPosted: Mon Jun 04, 2012 11:25 am
Reply with quote

I dint get. can u explain in details reg plan_table?
Back to top
View user's profile Send private message
Prakash J

New User


Joined: 23 May 2012
Posts: 14
Location: India

PostPosted: Mon Jun 04, 2012 12:20 pm
Reply with quote

Sree,

1. Create the PLAN_TABLE with your User ID.

CREATE TABLE Userid.PLAN_TABLE LIKE DEFAULT.PLAN_TABLE;

2. EXPLAIN PLAN SET QUERYNO = 1 FOR [SQL Query];

3. Retrieve the information from PLAN_TABLE using
SELECT * FROM PLAN_TABLE WHERE QUERYNO = 1 and check for the information ACCESSTYPE, MATCHCOLS, ACCESSNAME PREFETCH etc.

For more information about these columns, please check out DB2 for z/OS Performance Monitoring and Tuning Guide.

- Prakash
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Mon Jun 04, 2012 12:40 pm
Reply with quote

try this for both tables and show us the output:
Code:
SELECT
I.TBCREATOR, I.TBNAME, I.CREATOR, I.NAME
, I.UNIQUERULE,  I.CLUSTERRATIO
, I.FIRSTKEYCARD, I.FULLKEYCARD, K.COLSEQ,
     K.COLNAME,k.ordering
FROM SYSIBM.SYSINDEXES I
INNER JOIN SYSIBM.SYSKEYS K
ON I.CREATOR = K.IXCREATOR AND I.NAME = K.IXNAME
WHERE (I.TBCREATOR = &creator) AND (I.TBNAME like &tblike)
ORDER BY i.tbcreator, i.tbname, i.name, k.colseq
Back to top
View user's profile Send private message
Santhosh Menon

New User


Joined: 19 Jun 2012
Posts: 4
Location: USA

PostPosted: Wed Jun 20, 2012 7:19 am
Reply with quote

Sree,

Explain would be the best option.....

Also for a quick hit... try the below 2 options if u see a diff.
1) Changing Not IN to Not EXISTS
2) Changing the Query to a Left join.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Jun 20, 2012 7:52 am
Reply with quote

Hello,

Did you notice that Sree has not provided the requested info and most likely has this running or moved on to something else.

Also, notice that Explain was mentioned above and the way to get started.

Lastly, if he cannot get an Explain, running the query provided by GuyC and posting the result would be helpful.
Back to top
View user's profile Send private message
Santhosh Menon

New User


Joined: 19 Jun 2012
Posts: 4
Location: USA

PostPosted: Wed Jun 20, 2012 8:21 am
Reply with quote

My bad. Just trying to help ! Will be more careful the next time
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Jun 20, 2012 8:41 am
Reply with quote

Hi Menon,

Quote:
My bad.
Nah, not so bad - no foul icon_smile.gif

It is good to want to help - we appreciate this!

Just wanted to mention that some topics are better candidates for a reply than others.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts Issue with EXEC CICS QUERY SECURITY c... CICS 6
Search our Forums:

Back to Top