Db2curiosity
Programmer
Hi,
I wrote last week about some costly queries and kind of tuned them by adding a NEW index with all your valuable help.
Looks like the story didn't end here. There are another set of queries [which is having SELF JOIN on a 25 MM table]Its picking up the NEW index,showing improvement in Explain Plan and Cost but the actual time taken is almost the same.
I'm giving the tables,query,plan cost and index structure that its picking up.
Please let me know if you have any new idea of tuning this specific set of queries. Any change that can speed up.
Table X has 25 MM rows (b and b1 are alias of X)
Table Y has 75k
select a.SOURCE_SYSTEM,a.COMPANY_CODE,a.SEPARATE_ACCT,a.MARGIN_CODE,a.FUND_NUMBER,a.VALUATION_DT,
a.PROCESS_DT,a.AGREEMENT_ID,a.FINCL_ASSET_ID,b.ACCOUNT_ID,b1.ACCOUNT_ID,'5',a.PLAN_NUM,
a.PART_NUM,a.FUND_SRC,a.FUND_IV,a.char_AGMT_ID,a.char_FINCL_ID,a.HIDDEN_FL,
char(a.VALUATION_DT)
from Y a,X b,X b1
Where b.SOURCE_SYSTEM_nm='DOUG'
and a.CHAR_AGMT_ID=b.LOAD_PROCESS_KEY_PART_01
and a.CHAR_FINCL_ID<>b.LOAD_PROCESS_KEY_PART_02
and a.FUND_IV=b.BUSINESS_KEY_PART_04
and char(a.VALUATION_DT)>=b.BUSINESS_KEY_PART_08
and a.VALUATION_DT<=coalesce(b.DELETE_DT,'9999-12-31')
and b1.SOURCE_SYSTEM_nm='DOUG'
and a.CHAR_AGMT_ID=b1.LOAD_PROCESS_KEY_PART_01
and a.CHAR_FINCL_ID=b1.LOAD_PROCESS_KEY_PART_02
and a.FUND_IV=b1.BUSINESS_KEY_PART_04
and (b.DELETE_DT=date(b1.BUSINESS_KEY_PART_08) or
(b.DELETE_DT + 1 day)=date(b1.BUSINESS_KEY_PART_08))
CREATE INDEX DB2DBA.NEW_IDX_ON_X
ON DB2DBA.X
(SOURCE_SYSTEM_NM ASC,
LOAD_PROCESS_KEY_PART_01 ASC,
LOAD_PROCESS_KEY_PART_02 ASC,
BUSINESS_KEY_PART_04 ASC,
BUSINESS_KEY_PART_08 ASC,
ACCOUNT_ID ASC,
DELETE_DT ASC
)
The plan & cost :-
Step Operation Object name Object Cost
---- ---------------------------- ------------------- ------------
1 Index Scan (No Table Access) DB2DBA.NEW_IDX_ON_X Index 220347.13
2 Table Queue 223945.03
3 Index Scan (No Table Access) DB2DBA.NEW_IDX_ON_X Index 220347.13
4 Table Queue 224524.34
5 SHIP GLOB.Y NK 4008.26
6 Sort 4156.59
7 Sorted Table Data Scan 4165.79
8 Filter Rows 4195.11
9 Merge Scan Join 245020.47
10 Temporary Table Construction 245020.48
11 Temp Table Data Scan 245020.53
12 Nested Loop Join 524686.13
13 Data Operation Complete 533043.44
By doing some minor tweaks the last 3 steps can be altered to the following,but is that of any help ? I mean i'm not very sure if HASH JOIN is better in DB2 or NESTED LOOP JOIN
10 Sort 245020.41
11 Sorted Table Data Scan 245020.41
12 Hash Join 1095881.00
INSTEAD of
11 Temp Table Data Scan 245020.53
12 Nested Loop Join 524686.13
13 Data Operation Complete 533043.44
I wrote last week about some costly queries and kind of tuned them by adding a NEW index with all your valuable help.
Looks like the story didn't end here. There are another set of queries [which is having SELF JOIN on a 25 MM table]Its picking up the NEW index,showing improvement in Explain Plan and Cost but the actual time taken is almost the same.
I'm giving the tables,query,plan cost and index structure that its picking up.
Please let me know if you have any new idea of tuning this specific set of queries. Any change that can speed up.
Table X has 25 MM rows (b and b1 are alias of X)
Table Y has 75k
select a.SOURCE_SYSTEM,a.COMPANY_CODE,a.SEPARATE_ACCT,a.MARGIN_CODE,a.FUND_NUMBER,a.VALUATION_DT,
a.PROCESS_DT,a.AGREEMENT_ID,a.FINCL_ASSET_ID,b.ACCOUNT_ID,b1.ACCOUNT_ID,'5',a.PLAN_NUM,
a.PART_NUM,a.FUND_SRC,a.FUND_IV,a.char_AGMT_ID,a.char_FINCL_ID,a.HIDDEN_FL,
char(a.VALUATION_DT)
from Y a,X b,X b1
Where b.SOURCE_SYSTEM_nm='DOUG'
and a.CHAR_AGMT_ID=b.LOAD_PROCESS_KEY_PART_01
and a.CHAR_FINCL_ID<>b.LOAD_PROCESS_KEY_PART_02
and a.FUND_IV=b.BUSINESS_KEY_PART_04
and char(a.VALUATION_DT)>=b.BUSINESS_KEY_PART_08
and a.VALUATION_DT<=coalesce(b.DELETE_DT,'9999-12-31')
and b1.SOURCE_SYSTEM_nm='DOUG'
and a.CHAR_AGMT_ID=b1.LOAD_PROCESS_KEY_PART_01
and a.CHAR_FINCL_ID=b1.LOAD_PROCESS_KEY_PART_02
and a.FUND_IV=b1.BUSINESS_KEY_PART_04
and (b.DELETE_DT=date(b1.BUSINESS_KEY_PART_08) or
(b.DELETE_DT + 1 day)=date(b1.BUSINESS_KEY_PART_08))
CREATE INDEX DB2DBA.NEW_IDX_ON_X
ON DB2DBA.X
(SOURCE_SYSTEM_NM ASC,
LOAD_PROCESS_KEY_PART_01 ASC,
LOAD_PROCESS_KEY_PART_02 ASC,
BUSINESS_KEY_PART_04 ASC,
BUSINESS_KEY_PART_08 ASC,
ACCOUNT_ID ASC,
DELETE_DT ASC
)
The plan & cost :-
Step Operation Object name Object Cost
---- ---------------------------- ------------------- ------------
1 Index Scan (No Table Access) DB2DBA.NEW_IDX_ON_X Index 220347.13
2 Table Queue 223945.03
3 Index Scan (No Table Access) DB2DBA.NEW_IDX_ON_X Index 220347.13
4 Table Queue 224524.34
5 SHIP GLOB.Y NK 4008.26
6 Sort 4156.59
7 Sorted Table Data Scan 4165.79
8 Filter Rows 4195.11
9 Merge Scan Join 245020.47
10 Temporary Table Construction 245020.48
11 Temp Table Data Scan 245020.53
12 Nested Loop Join 524686.13
13 Data Operation Complete 533043.44
By doing some minor tweaks the last 3 steps can be altered to the following,but is that of any help ? I mean i'm not very sure if HASH JOIN is better in DB2 or NESTED LOOP JOIN
10 Sort 245020.41
11 Sorted Table Data Scan 245020.41
12 Hash Join 1095881.00
INSTEAD of
11 Temp Table Data Scan 245020.53
12 Nested Loop Join 524686.13
13 Data Operation Complete 533043.44