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: 6968
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 LMINIT problem - not finding DDNAME Danielle.Filteau CLIST & REXX 7 Tue Sep 19, 2017 9:57 pm
No new posts Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm
No new posts Can we limit length in concatenation ... balaji81_k DB2 7 Tue Aug 22, 2017 2:50 am
No new posts Problem commiting to DB2 from IMS MPP Ole Soerensen IMS DB/DC 2 Wed Jul 26, 2017 5:19 pm
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am

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