MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Need tips for tuning below mentioned queries

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
mainframes530
Beginner


Joined: 13 Mar 2008
Posts: 4
Topics: 1

PostPosted: Fri Mar 14, 2008 6:40 am    Post subject: Need tips for tuning below mentioned queries Reply with quote

Hi.
my cobol pgm contains 2 cursors which are taking lot of time to execute.could any one help me in optimizing the below queries.
Code:

1) SELECT A.ZDS_SP,                                 
       A.ZRC_ID,                             
       SUM(B.AMT)                       
  FROM ZLS_PER A, Z_TRAN B       
 WHERE  B.EFCT_DATE < :HV-END-DATE               
   AND  B.EFCT_DATE > :HV-BGN-DATE               
   AND  B.ZC_YS_ODE  <> 'ADC'                   
   AND  (B.ZSST_TYPE_CDE = 'AO'                 
    OR   B.ZSST_TYPE_CDE = 'PU'                 
    OR   B.ZSST_TYPE_CDE = 'RP'
    OR   B.ZSST_TYPE_CDE = 'SA'
    OR   B.ZSST_TYPE_CDE = 'SP')
   AND  B.ZURR_SP_ID = A.ZDS_SP           
  GROUP BY  A.ZDS_SP, A.ZRC_ID           
  ORDER BY  A.ZDS_SP, A.ZRC_ID   

2) SELECT A.ZDS_SP,                             
       A.ZRC_ID,                         
       SUM(B.ZRAN_AMT)                   
  FROM   ZLS_PER A, ZRAN B,   
         ZRODUCT C                     
 WHERE  B.EFCT_DATE < :HV-END-DATE           
   AND  B.EFCT_DATE > :HV-BGN-DATE           
   AND  B.ZC_YS_ODE <> 'TDC'               
   AND  (B.ZSST_CDE = 'AO'             
    OR   B.ZSST_CDE = 'PU'             
    OR   B.ZSST_CDE = 'RP'
    OR   B.ZSST_CDE = 'SA'
    OR   B.ZSST_CDE = 'SP')
   AND  B.ZDS_SP   = A.ZDS_SP       
   AND  B.ZS_OD_ID = C.ZS_OD_ID         
   AND  (C.ZDAS_CODE = '001'             
    OR   C.ZDAS_CODE = '002'             
    OR   C.ZDAS_CODE = '003'             
    OR   C.ZDAS_CODE = '005'             
    OR   C.ZDAS_CODE = '007'             
    OR   C.ZDAS_CODE = '008'             
    OR   C.ZDAS_CODE = '009'             
    OR   C.ZDAS_CODE = '010'             
    OR   C.ZDAS_CODE = '011'             
    OR   C.ZDAS_CODE = '013'             
    OR   C.ZDAS_CODE = '014'             
    OR   C.ZDAS_CODE = '015'             
    OR   C.ZDAS_CODE = '016'             
    OR   C.ZDAS_CODE = '017'             
    OR   C.ZDAS_CODE = '018'             
    OR   C.ZDAS_CODE = '019'             
    OR   C.ZDAS_CODE = '021')           
  GROUP BY  A.ZDS_SP, A.ZRC_ID         
  ORDER BY  A.ZDS_SP, A.ZRC_ID         

If possible provide any kind of material or links available for tuning queries.
Back to top
View user's profile Send private message
bauer
Intermediate


Joined: 10 Oct 2003
Posts: 317
Topics: 50
Location: Germany

PostPosted: Sat Mar 15, 2008 2:23 pm    Post subject: Reply with quote

mainframes530,

try to use EXPLAIN command .....

Indexstructure ?

Runstatsdata ?
Back to top
View user's profile Send private message
CraigG
Intermediate


Joined: 02 May 2007
Posts: 202
Topics: 0
Location: Viginia, USA

PostPosted: Sat Mar 15, 2008 7:18 pm    Post subject: Reply with quote

How many rows in the tables? What is a lot of time?

I would suggest replacing this
Code:

 AND  (C.ZDAS_CODE = '001'             
    OR   C.ZDAS_CODE = '002'             
    OR   C.ZDAS_CODE = '003'             
    OR   C.ZDAS_CODE = '005'             
    OR   C.ZDAS_CODE = '007'             
    OR   C.ZDAS_CODE = '008'             
    OR   C.ZDAS_CODE = '009'             
    OR   C.ZDAS_CODE = '010'             
    OR   C.ZDAS_CODE = '011'             
    OR   C.ZDAS_CODE = '013'             
    OR   C.ZDAS_CODE = '014'             
    OR   C.ZDAS_CODE = '015'             
    OR   C.ZDAS_CODE = '016'             
    OR   C.ZDAS_CODE = '017'             
    OR   C.ZDAS_CODE = '018'             
    OR   C.ZDAS_CODE = '019'             
    OR   C.ZDAS_CODE = '021')           
 

with
Code:

 AND  C.ZDAS_CODE IN ('001', '002', '003',  '005' , '007', '008', '009'             
 '010', '011', '013', '014', '015', '016', '017', '018', '019', '021')           


or
Code:

AND C.ZDAS_CODE BETWEEN '001' AND '021'
Back to top
View user's profile Send private message
mainframes530
Beginner


Joined: 13 Mar 2008
Posts: 4
Topics: 1

PostPosted: Sun Mar 16, 2008 4:25 am    Post subject: Reply with quote

bauer,
thanks for your reply,
Could you please more specific about how to use explain?
provide material for the same.
Back to top
View user's profile Send private message
mainframes530
Beginner


Joined: 13 Mar 2008
Posts: 4
Topics: 1

PostPosted: Sun Mar 16, 2008 4:27 am    Post subject: Reply with quote

CraigG,
thnks.table contains 7 million records.it is taking around 5-6 hrs.
Back to top
View user's profile Send private message
Nic Clouston
Advanced


Joined: 01 Feb 2007
Posts: 1075
Topics: 7
Location: At Home

PostPosted: Sun Mar 16, 2008 6:14 am    Post subject: Reply with quote

EXPLAIN - is explained in the manuals link. Select DB2 programmers guide and do a search on EXPLAIN with the search criteria set to EXACT and the first link tells you how to code it and the second how to use the results.

5 hours and 7 million rows - not very long.
_________________
Utility and Program control cards are NOT, repeat NOT, JCL.
Back to top
View user's profile Send private message
dr_te_z
Beginner


Joined: 08 Feb 2007
Posts: 18
Topics: 3

PostPosted: Mon Mar 17, 2008 2:57 am    Post subject: Re: Need tips for tuning below mentioned queries Reply with quote

mainframes530 wrote:

Code:
 WHERE  B.EFCT_DATE < :HV-END-DATE               
   AND  B.EFCT_DATE > :HV-BGN-DATE

Yep, agree with previous posters. Use the "IN" and "BETWEEN" predicate where possible. So also in the above mentioned date range.
Back to top
View user's profile Send private message
bauer
Intermediate


Joined: 10 Oct 2003
Posts: 317
Topics: 50
Location: Germany

PostPosted: Mon Mar 17, 2008 4:00 am    Post subject: Reply with quote

Can anybody pls. explain, why the IN predicate in the shown situation is better than using the OR Syntax ?
Back to top
View user's profile Send private message
CraigG
Intermediate


Joined: 02 May 2007
Posts: 202
Topics: 0
Location: Viginia, USA

PostPosted: Mon Mar 17, 2008 7:16 am    Post subject: Reply with quote

Code:
 WHERE  B.EFCT_DATE < :HV-END-DATE           
   AND  B.EFCT_DATE > :HV-BGN-DATE           


is not the same as

Code:

 WHERE  B.EFCT_DATE BETWEEN :HV-BGN-DATE AND :HV-END-DATE           
Back to top
View user's profile Send private message
dr_te_z
Beginner


Joined: 08 Feb 2007
Posts: 18
Topics: 3

PostPosted: Mon Mar 17, 2008 8:44 am    Post subject: Reply with quote

No, I know. I did not say that. I just said that it can be re-coded that way.
You must look close at the content of you host-vars. Just add/subtrract 1 day where needed and you're done.
Back to top
View user's profile Send private message
mainframes530
Beginner


Joined: 13 Mar 2008
Posts: 4
Topics: 1

PostPosted: Tue Mar 18, 2008 12:44 pm    Post subject: Reply with quote

@Nic Clouston
Thanks a lot,i will definitely do some research on EXPLAIN

@ CraigG,
thanks a lot craig,i completely agree with what ever u said regarding Code:
WHERE B.EFCT_DATE < :HV-END-DATE
AND B.EFCT_DATE > :HV-BGN-DATE
you are correct

@bauer
even i found the same in one of the DB2 manual I.e IN is better than OR for similar pedicates.

@dr_te_z
Dude,Had it been a WHERE B.EFCT_DATE <= :HV-END-DATE
AND B.EFCT_DATE >= :HV-BGN-DATE
then you would've been corect.
Back to top
View user's profile Send private message
dr_te_z
Beginner


Joined: 08 Feb 2007
Posts: 18
Topics: 3

PostPosted: Thu Mar 20, 2008 6:21 am    Post subject: Reply with quote

So? Code like
Code:
Select DAT_GELDIG_TOT from whatever_table
 where DAT_GELDIG_TOT between (date (2007-03-20) + 1 day)
                          and (date (2008-04-26) - 1 day)

In your case this would be
Code:
 (date (:HV-whaterver-date) + 1 day)


and, dude, are you religious? I've got a new bible for you http://www.ibm.com/developerworks/db2/library/techarticle/0211yip/0211yip3.html
Back to top
View user's profile Send private message
bauer
Intermediate


Joined: 10 Oct 2003
Posts: 317
Topics: 50
Location: Germany

PostPosted: Thu Mar 20, 2008 10:48 am    Post subject: Reply with quote

......and what about the explain results ?
Back to top
View user's profile Send private message
haatvedt
Beginner


Joined: 14 Nov 2003
Posts: 66
Topics: 0
Location: St Cloud, Minnesota USA

PostPosted: Sun Apr 13, 2008 11:29 pm    Post subject: Reply with quote

Mainframes530,

I've used Platinum unloads with this size table to unload each table separately and then do the "joins" with COBOL programs having file matching logic. If the matches are one to one or on to many then its pretty straight forward. If the join is a cartesian join (many to many) then the COBOL program is a bit more complicated but can still be done if all the matching keys for one table can be loaded into an array. the array will hold all the rows for a single key value and will be reloaded each time a control break is encountered.

with this size of tables I would estimate that the entire process would take 20 to 30 minutes and that is a high estimate.

good luck

ps.. send me an email offline if you want to discuss this in more detail. the same process can be used for a 3 table join.
_________________
Chuck Haatvedt

email --> clastnameatcharterdotnet

(replace lastname, at, dot with appropriate
characters)
Back to top
View user's profile Send private message
subho
Beginner


Joined: 19 Oct 2004
Posts: 13
Topics: 4
Location: Atlanta

PostPosted: Mon Apr 14, 2008 11:17 am    Post subject: Reply with quote

Mainframes530,

Have you considered to add any more predicate? Have you considered to create a small set of table for the larger table? Have your SQL expedited using IN and BETWEEN?

Please let us know
1. Row count in ZLS_PER , Z_TRAN, ZRAN and ZRODUCT
2. Primary/clustered/secondary indexes for these table
3. Cardinality(1:1, 1:N, N:1) of these tables

This will help us to give the better solution.

Thanks,
Subho
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group