View previous topic :: View next topic |
Author |
Message |
mainframes530 Beginner
Joined: 13 Mar 2008 Posts: 4 Topics: 1
|
Posted: Fri Mar 14, 2008 6:40 am Post subject: Need tips for tuning below mentioned queries |
|
|
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 |
|
 |
bauer Intermediate
Joined: 10 Oct 2003 Posts: 317 Topics: 50 Location: Germany
|
Posted: Sat Mar 15, 2008 2:23 pm Post subject: |
|
|
mainframes530,
try to use EXPLAIN command .....
Indexstructure ?
Runstatsdata ? |
|
Back to top |
|
 |
CraigG Intermediate
Joined: 02 May 2007 Posts: 202 Topics: 0 Location: Viginia, USA
|
Posted: Sat Mar 15, 2008 7:18 pm Post subject: |
|
|
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 |
|
 |
mainframes530 Beginner
Joined: 13 Mar 2008 Posts: 4 Topics: 1
|
Posted: Sun Mar 16, 2008 4:25 am Post subject: |
|
|
bauer,
thanks for your reply,
Could you please more specific about how to use explain?
provide material for the same. |
|
Back to top |
|
 |
mainframes530 Beginner
Joined: 13 Mar 2008 Posts: 4 Topics: 1
|
Posted: Sun Mar 16, 2008 4:27 am Post subject: |
|
|
CraigG,
thnks.table contains 7 million records.it is taking around 5-6 hrs. |
|
Back to top |
|
 |
Nic Clouston Advanced
Joined: 01 Feb 2007 Posts: 1075 Topics: 7 Location: At Home
|
Posted: Sun Mar 16, 2008 6:14 am Post subject: |
|
|
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 |
|
 |
dr_te_z Beginner
Joined: 08 Feb 2007 Posts: 18 Topics: 3
|
Posted: Mon Mar 17, 2008 2:57 am Post subject: Re: Need tips for tuning below mentioned queries |
|
|
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 |
|
 |
bauer Intermediate
Joined: 10 Oct 2003 Posts: 317 Topics: 50 Location: Germany
|
Posted: Mon Mar 17, 2008 4:00 am Post subject: |
|
|
Can anybody pls. explain, why the IN predicate in the shown situation is better than using the OR Syntax ? |
|
Back to top |
|
 |
CraigG Intermediate
Joined: 02 May 2007 Posts: 202 Topics: 0 Location: Viginia, USA
|
Posted: Mon Mar 17, 2008 7:16 am Post subject: |
|
|
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 |
|
 |
dr_te_z Beginner
Joined: 08 Feb 2007 Posts: 18 Topics: 3
|
Posted: Mon Mar 17, 2008 8:44 am Post subject: |
|
|
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 |
|
 |
mainframes530 Beginner
Joined: 13 Mar 2008 Posts: 4 Topics: 1
|
Posted: Tue Mar 18, 2008 12:44 pm Post subject: |
|
|
@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 |
|
 |
dr_te_z Beginner
Joined: 08 Feb 2007 Posts: 18 Topics: 3
|
Posted: Thu Mar 20, 2008 6:21 am Post subject: |
|
|
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 |
|
 |
bauer Intermediate
Joined: 10 Oct 2003 Posts: 317 Topics: 50 Location: Germany
|
Posted: Thu Mar 20, 2008 10:48 am Post subject: |
|
|
......and what about the explain results ? |
|
Back to top |
|
 |
haatvedt Beginner
Joined: 14 Nov 2003 Posts: 66 Topics: 0 Location: St Cloud, Minnesota USA
|
Posted: Sun Apr 13, 2008 11:29 pm Post subject: |
|
|
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 |
|
 |
subho Beginner
Joined: 19 Oct 2004 Posts: 13 Topics: 4 Location: Atlanta
|
Posted: Mon Apr 14, 2008 11:17 am Post subject: |
|
|
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 |
|
 |
|
|