I have a query:
select min(timestamp) from table
This table has 60+million rows, and daily I delete a few off the end. To determine whether or not there is any data old enough do delete I run the query above. There is an index on timestamp ascending, containing only one column, and the query plan in oracle causes this to be a full index scan. Should this not be the definition of a seek?
edit including plan:
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 2 | INDEX FULL SCAN (MIN/MAX)| NEVENTS_I2 | 1 | 8 | 4 (100)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 8 | | |
| 0 | SELECT STATEMENT | | 1 | 8 | 4 (0)| 00:00:01 |
At first I thought that the index would only be used if the column is declared NOT NULL. I tested with the following setup:
Here we notice that the index is used, but all rows from the index are read. If we specify that the column is not null we get a much better plan:
In fact this is the same plan that is also used if we add a WHERE clause (Oracle will read a single row from the index):
This last plan shows (line 2) that Oracle is indeed performing a “seek”.