I have this table:
create table demo (
key number(10) not null,
type varchar2(3) not null,
state varchar2(16) not null,
... lots more columns ...
)
and this index:
create index demo_x04 on demo(key, type, state);
When I run this query
select * from demo where key = 1 and type = '003' and state = 'NEW'
EXPLAIN PLAN
shows that it does a full table scan. So I dropped the index and created it again. EXPLAIN PLAN
still says full table scan. How can that be?
Some background: This is historical data, so what happens is that I look up a row with state CLEARED
and insert a new row with state NEW
(plus I copy a few values from the old row). The old row is then updated to USED
. So the table always grows. What I did notice is that the cardinality of the index is 0 (despite the fact that I have thousands of different values). After recreating, the cardinality grew but the CBO didn't like the index any better.
The next morning, Oracle suddenly liked the index (probably slept over it) and started to use it but not for long. After a while, the processing dropped from 50 rows/s to 3 rows/s and I saw again "FULL TABLE SCAN". What is going on?
In my case, I need to process about a million rows. I commit the changes in batches of ca. 50. Is there some command which I should run after a commit to update/reorg the index or something like that?
I'm on Oracle 10g.
[EDIT] I have 969'491 distinct keys in this table, 3 types and 3 states.