View previous topic :: View next topic |
Author |
Message |
Dip Beginner
Joined: 24 Mar 2006 Posts: 27 Topics: 14
|
Posted: Wed May 23, 2007 4:49 pm Post subject: INDEX scan or Table Scan |
|
|
We are planning to build a index on a date field (late say ABC_DT)in a table. AT the same time our anticipation is that most of the records (80%) will be having NULL populated in that Date field (i think NULL in a index field is possible).
In this scenario how the below queries will perform in a batch job?
Select FIELD1, FIELD2 from table where ABC_DT = 'XXXX-XX-XX-XX.XX.XX.XXXXXX' ;
Select FIELD1, FIELD2 from table where ABC_DT IS NOT NULL;
Will it go for a INDEX scan?
OR
DB2 will internally perform a table scan as most of the records are having NULL populated in the INDEX field? |
|
Back to top |
|
 |
videlord Beginner
Joined: 09 Dec 2004 Posts: 147 Topics: 19
|
Posted: Wed May 23, 2007 9:54 pm Post subject: |
|
|
based on the statistic information, if requested data are more than 25% of total records, DB2 optimizer will use table scan instead of index scan
in your case, all requested data are less than 20% , index will be used if the statistic information in catalog table is correct |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Thu May 24, 2007 5:44 am Post subject: |
|
|
Quote: |
Date field (i think NULL in a index field is possible).
|
you canNOT have NULLS if the index is a primary index.
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
Dip Beginner
Joined: 24 Mar 2006 Posts: 27 Topics: 14
|
Posted: Thu May 24, 2007 3:58 pm Post subject: |
|
|
Sorry.. didnt mention it.. It is not a primary index.. |
|
Back to top |
|
 |
pharia01 Beginner

Joined: 07 Sep 2006 Posts: 3 Topics: 0
|
Posted: Fri May 25, 2007 5:15 pm Post subject: |
|
|
Videlord,
Quote: |
based on the statistic information, if requested data are more than 25% of total records, DB2 optimizer will use table scan instead of index scan
|
just curious, where did you get info about 25% cutoff mark?
Thanks,
pharia01 |
|
Back to top |
|
 |
|
|