If you get all the rows from a table, why do you think it should use an index? A full table scan is the most effective way to return all values. It has nothing to do with zeros that are not in the index, and everything related to the optimizer choosing the most efficient ways to retrieve data.
@ABCade: Perhaps the optimizer can use the index, but hardly. Say you have a table with an indexed table with 100 rows, but only 10 values. If the optimizer uses an index, it should get 10 rows from the index, and then expand it to 100 rows, while when scanning at full table, it gets all 100 rows from get-go. Here is an example:
create table test1 (blarg varchar2(10)); create index ak_test1 on test1 (blarg); insert into test1 select floor(level/10) from dual connect by level<=100; exec dbms_stats.gather_table_stats('testschema','test1'); exec dbms_stats.gather_index_stats('testschema','ak_test1'); EXPLAIN PLAN FOR select * from test1;
My point of view basically lies in the fact that this question is mainly based on an erroneous premise: indexed crawls are inherently better than crawling a full table. This is not always the case as this scenario demonstrates.
Allan
source share