Oracle does not use a conditional index [message #638244] |
Mon, 08 June 2015 05:29 ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
iblazquez
Messages: 26 Registered: June 2007
|
Junior Member |
|
|
Hello, I have a table with this structure
Name Type
----------- --------------
ID NUMBER(5)
DATE DATE
TEXT VARCHAR2(500)
AUTHOR NUMBER(6)
THEME NUMBER(4)
LATEST VARCHAR2(1)
The field LATEST only can have two values 'S' or 'N'.
There are only a few records with the 'S' so I have created a index for those records
create index TABLE_IDX on TABLE (CASE LATEST WHEN 'S' THEN LATEST ELSE NULL END)
Why oracle does a full scan if I only want the records with the 'S' value
SELECT ID FROM TABLE WHERE LATEST='S'
|
|
|
|
|
|
|
|
Re: Oracle does not use a conditional index [message #639222 is a reply to message #639221] |
Fri, 03 July 2015 02:15 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
Roachcoach
Messages: 1576 Registered: May 2010 Location: UK
|
Senior Member |
|
|
mfarooq216 wrote on Fri, 03 July 2015 08:07Null values in a column which involve in idex will mark the index as unusable.
Always the column should be filled with data if part of index.
Regards,
This isn't the case.
A NULL value in all columns will not be stored in a B-Tree. It WILL be stored in a bitmap index.
Null values do not invalidate the index, they just are not listed, as others have said this can be done for space reasons or performance reasons.
Unless you meant in the query itself, in which case...it wont use a btree because the row isnt there, but a bitmap, or a composite b-tree where not all the columns are null is still a candidate.
|
|
|
|