Consider the following two queries on a table where datecolumn is indexed -
Q1: select * from table where datecolumn > sysdate - 5;
Q2: select * from table where datecolumn > sysdate - 5 and datecolumn < sysdate - 1;
Q1 uses the index. But, Q2 somehow does a full table scan. Is it because oracle somehow chooses to execute "datecolumn < sysdate - 1" first ? In that case, is there a way to enforce order of execution of where clauses involving one column ?
You could specify an index hint, something like this:
select /*+ INDEX (table datecolumn_ix)*/
*
from table
where datecolumn > sysdate - 5 and datecolumn < sysdate - 1;
See Oracle Index Hint for more details.