Database Reference
In-Depth Information
Case 2
We're using a SELECT COUNT(*) FROM T query (or something similar) and we have a B*Tree index on table T . However,
the optimizer is full scanning the table, rather than counting the (much smaller) index entries. In this case, the index
is probably on a set of columns that can contain Nulls. Since a totally Null index entry would never be made, the count
of rows in the index will not be the count of rows in the table. Here the optimizer is doing the right thing—it would get
the wrong answer if it used the index to count rows.
Case 3
For an indexed column, we query using the following and find that the index on INDEXED_COLUMN is not used:
select * from t where f(indexed_column) = value
This is due to the use of the function on the column. We indexed the values of INDEXED_COLUMN , not the value of
F(INDEXED_COLUMN) . The ability to use the index is curtailed here. We can index the function if we choose to do it.
Case 4
We have indexed a character column. This column contains only numeric data. We query using the following syntax:
select * from t where indexed_column = 5
Note that the number 5 in the query is the constant number 5 (not a character string). The index on INDEXED_COLUMN
is not used. This is because the preceding query is the same as the following:
select * from t where to_number(indexed_column) = 5
We have implicitly applied a function to the column and, as noted in case 3, this will preclude the use of the index.
This is very easy to see with a small example. In this example, we're going to use the built-in package DBMS_XPLAN .
This package is available only with Oracle9 i Release 2 and above (in Oracle9 i Release 1, we will use AUTOTRACE
instead to see the plan easily, but we will not see the predicate information—that is only available in Oracle9 i
Release 2 and above):
EODA@ORA12CR1> create table t ( x char(1) constraint t_pk primary key,
2 y date );
Table created.
EODA@ORA12CR1> insert into t values ( '5', sysdate );
1 row created.
EODA@ORA12CR1> explain plan for select * from t where x = 5;
Explained.
EODA@ORA12CR1> select * from table(dbms_xplan.display);
 
Search WWH ::




Custom Search