If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > db2 indexes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-27-04, 13:47
ksexton ksexton is offline
Registered User
 
Join Date: May 2002
Posts: 47
Wink db2 indexes

I want to know when an index is not used.
I have a composite index on columns abc.

I run several queries that attempt to scan the following columns:

a,b,c (of course the index is used)
a,b (still uses index)
a,c (I don't think the index will be used)
b,c (I don't think the index will be used)
Reply With Quote
  #2 (permalink)  
Old 02-27-04, 14:00
Marcus_A Marcus_A is online now
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
There is no guarantee that DB2 will use any particular index, but if there is only one index on a table and it is on columns (a, b, c) then the following predicates will use the index as follows:

a,b,c - matching index scan on 3 columns using b-tree

a,b - matching index scan on 2 columns using b-tree

a,c - matching index scan on 1 columns using b-tree

b,c - non-matching index scan (reads entire index sequentially)

Note that on (a,c) that it depends on what the cardinality (number of unique values) of what the first column is. If there are only a few unique values of column a, then DB2 might choose not to use the index because it would not likely reduce the number of (usually 4K) data pages in the table that have to be accessed.

DB2 keeps statistics in the catalog (updated with runstats) on the cardinality of the columns and of the index taken as a whole (fullkeycard), and the first column of a multi-column index (firstkeycard).
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 02-27-04, 14:15
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Re: db2 indexes

Quote:
Originally posted by ksexton
I want to know when an index is not used.
I have a composite index on columns abc.

I run several queries that attempt to scan the following columns:

a,b,c (of course the index is used)
a,b (still uses index)
a,c (I don't think the index will be used)
b,c (I don't think the index will be used)
Your guesses are correct.

Use dynexpln utility to generate expain plans and see for yourself. It's described in detail in "Administration guide: Performance".
Reply With Quote
  #4 (permalink)  
Old 02-27-04, 14:29
Marcus_A Marcus_A is online now
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
Your guesses are not necessarily correct, because they depend on the cardinality of the columns, the distribution of the data (number of occurrences of each value), and the clustering of the table.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #5 (permalink)  
Old 02-27-04, 14:37
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally posted by Marcus_A
Your guesses are not necessarily correct, because they depend on the cardinality of the columns, the distribution of the data (number of occurrences of each value), and the clustering of the table.
That's right. I'm sounding a bit peremptory on Fridays
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On