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
 

 

Problem with Query.

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

New User


Joined: 05 Aug 2009
Posts: 44
Location: Hyderabad

PostPosted: Wed May 19, 2010 11:03 pm    Post subject: Problem with Query.
Reply with quote

Hi,

I have a query which I'm using in a cursor in a PL1 program. I see that the job is taking lot of time (more than 2hrs) to execute.

Query:
--------
SELECT B.ICUSABI, B.ICUSAB, B.ICUSCCC
FROM MCDVSAL A , MCDV014 B
WHERE A.CMECSTY = :DCLMCDVSAL.CMECSTY
AND B.IOPUCTY = '103'
AND (B.ICININO= :DCLMCDVSAL.ICININO AND A.CMECSTY = '10' AND
B.DCINISS= :DCLMCDVSAL.DCINYMM OR
B.IICPBVY= :DCLMCDVSAL.ICININO AND A.CMECSTY = '41' AND
B.DIEIDEY= :DCLMCDVSAL.DCINYMM )
AND A.CCINSCE IN ('MCD','DIS');

As this is the new query which I'm inserting in the program, I had created indexes on the fields used in WHERE condition above. But this didnt make my program run faster. Later, I had contacted a DB2 guy who said that the problem is with the query and to be more specific with the 'OR' clause used in the above query. I had tried to modify the above query as below-

SELECT B.ICUSABI, B.ICUSAB, B.ICUSCCC
FROM MCDVSAL A , MCDV014 B
WHERE A.CMECSTY IN ('10','41')
AND A.CMECSTY = :DCLMCDVSAL.CMECSTY
AND B.IOPUCTY = '103'
AND A.CCINSCE IN ('MCD','DIS')
AND ((B.ICININO= :DCLMCDVSAL.ICININO AND A.CMECSTY = '10' AND
B.DCINISS= :DCLMCDVSAL.DCINYMM) OR
(B.IICPBVY= :DCLMCDVSAL.ICININO AND A.CMECSTY = '41' AND
B.DIEIDEY= :DCLMCDVSAL.DCINYMM ));

But even this didnt make my program execute faster.

Can any one suggest/advice the efficient way in which the above query can be written?

Please let me know in case any additional info is required.

Thanks alot in advance.
KC.
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed May 19, 2010 11:54 pm    Post subject:
Reply with quote

Code:

SELECT B.ICUSABI,
       B.ICUSAB,
       B.ICUSCCC
FROM MCDVSAL A ,
     MCDV014 B
WHERE A.CMECSTY IN ('10','41')
  AND A.CMECSTY = :DCLMCDVSAL.CMECSTY
  AND B.IOPUCTY = '103'
  AND A.CCINSCE IN ('MCD','DIS')
  AND (
        (       B.ICININO   = :DCLMCDVSAL.ICININO
            AND A.CMECSTY   = '10'
            AND B.DCINISS   = :DCLMCDVSAL.DCINYMM)
       OR
        (       B.IICPBVY   = :DCLMCDVSAL.ICININO
            AND A.CMECSTY   = '41'
            AND B.DIEIDEY   = :DCLMCDVSAL.DCINYMM )
      );


well, what does the EXPLAIN say?
what is the dcl gen for all the columns referenced say?

and this is a little silly:
WHERE A.CMECSTY IN ('10','41')
AND A.CMECSTY = :DCLMCDVSAL.CMECSTY
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Thu May 20, 2010 12:02 am    Post subject:
Reply with quote

Hello,

I am probably missing something, but why is this (MCDVSAL A) in the code? What joins A rows to B rows? The data selected is from only B columns.

How did the host variables for the A table get populated for use in this query?

What appears to be happening is that you are generating a Cartesian product which is going to be the worst possible performance. As i mentioned - i may be missing something.
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 SYMNAMES problem jacobdng DFSORT/ICETOOL 7 Thu Dec 22, 2016 7:47 am
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am


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