IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Performance issue & DB2 Access path


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
unniK

New User


Joined: 05 Feb 2008
Posts: 2
Location: USA

PostPosted: Tue Feb 05, 2008 11:07 pm
Reply with quote

I have a cursor as mentioned below:
DECLARE AUT-ADR-C2 CURSOR FOR
SELECT
U5TAXYR,
U5ADACCT,
U5STRNO,
U5STRNM,
U5UNIT,
U5CITY,
U5STATE,
U5ZIP,
U5ATYPCD
FROM AUT_MVADDR_T
WHERE ( U5ADACCT = :U5ADACCT )
AND
( U5TAXYR = :WW-TAXYR )
AND
( U5PRYRIN = :MAP-D-PRIOR-YR-IND )
AND
( U5ATYPCD = :WK01-AUT-MAIL
OR
U5ATYPCD = :WK01-TAX-ADDR )
ORDER BY U5ATYPCD

The indexes on AUT_MVADDR_T table are as follows

1) AUT_MVADDR_I
U5ATYPCD ASC
U5CRCTYR ASC
U5CRCTNO ASC
U5TAXYR DESC
U5ADACCT ASC
U5PRYRIN ASC
2) AUT_MVADDR_ALT2_I
U5CRCTYR ASC
U5TAXYR ASC
U5CRCTNO ASC
U5ADACCT ASC
3) AUT_MVADDR_ALT1_I
U5CRCTYR ASC
U5CRCTNO ASC
Basically the index AUT_MVADDR_I has 5 matching columns and the index AUT_MVADDR_ALT2_I has 2 matching columns. When I checked the DB2 access path in Plan_table , the SELECT statement is picking up AUT_MVADDR_ALT2_I. Can someone explain me why DB2 doesn't pick up the primary index AUT_MVADDR_I as it has more number of matching columns?

Thanks & Regards,
Unni
Back to top
View user's profile Send private message
bbessa

New User


Joined: 03 Aug 2006
Posts: 13
Location: Brazil

PostPosted: Thu Feb 07, 2008 1:25 am
Reply with quote

It could be many things but I'll try to help. The DB2 optimizer chooses one index over another by comparing, basically, the filter factor and cluster ratio (even when it's not defined as a clustering index).

The filter factor is calculated based on the FULL KEY CARDINALITY, the number of distinct values for the combined entire key. The DB2 optimizer divides the full key cardinality by the number of total rows in the table. If that value is close to 0, it means the index does not filter really well, thus DB2 will not use it. On the other hand, a good filter factor has a value close to 1.

On the cluster ratio. I don't really know how it functions internally, but I know DB2 physically organizes data based on the clustering index. If you haven't defined a clustering index, DB2 will use the first index created on the table. Was AUT_MVADDR_ALT2_I created before AUT_MVADDR_I? If so, AUT_MVADDR_ALT2_I's cluster ratio should be higher then AUT_MVADDR_I, which affects the DB2 optimizer choice.

You may check cluster ratio and fullkeycard by running this query:

Code:
SELECT NAME, CLUSTERING,
CLUSTERED, CLUSTERRATIOF*100 AS CLUSTERRATIO, FULLKEYCARDF
FROM SYSIBM.SYSINDEXES
WHERE NAME = 'AUT_MVADDR_ALT2_I' OR NAME = 'AUT_MVADDR_I'


So... the solution you ask? Run statistics on AUT_MVADDR_I and AUT_MVADDR_ALT2_I and on the columns that composes the indexes. It might help. You can also 'cheat' the DB2 optimizer by setting CLUSTERRATIOF for AUT_MVADDR_I to 1. Or you can define AUT_MVADDR_I as a clustering index and run a REORG on the tablespace.


I hope this helps,

Bernardo
Back to top
View user's profile Send private message
unniK

New User


Joined: 05 Feb 2008
Posts: 2
Location: USA

PostPosted: Fri Feb 08, 2008 12:24 am
Reply with quote

Hi Bernardo,

Thank you so much for providing wonderful explanation.

The "AUT_MVADDR_I" is the first index created and defined as clustered.
Below is the result of your query.

NAME CLUSTERING CLUSTERED CLUSTERRATIO FULLKEYCARDF
------------------ ---------- --------- ------------ ------------
AUT_MVADDR_I Y Y 9.99980E+01 5.29384E+06
AUT_MVADDR_ALT2_I N Y 9.99912E+01 4.84196E+06

Regards,
Unni
Back to top
View user's profile Send private message
bbessa

New User


Joined: 03 Aug 2006
Posts: 13
Location: Brazil

PostPosted: Fri Feb 08, 2008 9:57 pm
Reply with quote

unniK wrote:

The "AUT_MVADDR_I" is the first index created and defined as clustered.
Below is the result of your query.

NAME CLUSTERING CLUSTERED CLUSTERRATIO FULLKEYCARDF
------------------ ---------- --------- ------------ ------------
AUT_MVADDR_I Y Y 9.99980E+01 5.29384E+06
AUT_MVADDR_ALT2_I N Y 9.99912E+01 4.84196E+06


Now that's odd. Both cluster ratio and filter are better for AUT_MVADDR_I than for AUT_MVADDR_ALT2_I. Maybe the DB2 optimizer can do a better job using U5TAXYR ASC over U5TAXYR DESC?

Try this:

1. Save the cluster ratio value of AUT_MVADDR_I
2. Set the cluster ratio to 1.
Code:
UPDATE SYSIBM.SYSINDEXES SET CLUSTERRATIOF = 1
WHERE NAME = 'AUT_MVADDR_I'

3. Run the query and check it's access path. DB2 Should choose AUT_MVADDR_I. But I can't guarantee you that the query will see a increase in performance.

By the way, you indexes have low cluster ratios. It is a inherent characteristic of using multiple indexes. You may improve the cluster ratio if you drop a index or two and do a REORG on the tablespace and indexes.

You may also consider using just one index:

U5ATYPCD ASC
U5CRCTYR ASC
U5CRCTNO ASC
U5TAXYR ASC
U5ADACCT ASC
U5PRYRIN ASC

Unless you are using multiple indexes to avoid SORT in other queries.

Bernardo
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Access to non cataloged VSAM file JCL & VSAM 18
No new posts How to access web services/website? Mainframe Interview Questions 4
No new posts SET PATH in View DDL DB2 2
No new posts exploiting Z16 performance PL/I & Assembler 2
Search our Forums:

Back to Top