Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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: 6970
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 How to query MAXGENS of an existing P... Chuchulo Hatyzak JCL & VSAM 4 Wed Nov 22, 2017 10:23 pm
No new posts Native SQL Query kishpra DB2 1 Wed Nov 22, 2017 8:38 pm
No new posts Having a problem FTP'ng to the MF pahiker All Other Mainframe Topics 2 Fri Nov 10, 2017 8:20 pm
No new posts Query on IEFBR14 with GDG Ashishpanpaliya JCL & VSAM 4 Tue Nov 07, 2017 8:34 pm
No new posts Query on XMITIP abdulrafi All Other Mainframe Topics 1 Wed Oct 25, 2017 6:54 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us