sql - Oracle Index is not used when compare timestamp with <= or >= -
i have indexes on 2 columns of type timestamp(2) start_date , end_date , query whare clause like:
where c.start_date <= sysdate , sysdate <= c.end_date
the explain plan makes table access full instead of index range scan.
-if change <=
=
index used.
-if change sysdate
systimestamp
it's worse in explain plan:
sys_extract_utc(internal_function(c.start_date))<=sys_extract_utc(systimestamp(6))
with full scan again.
-using to_timestamp
brings desired index range scan:
where c.start_date <= to_timestamp ('10-sep-02 14:10:10.123000', 'dd-mon-rr hh24:mi:ss.ff') , to_timestamp ('10-sep-02 14:10:10.123000', 'dd-mon-rr hh24:mi:ss.ff') <= c.end_date
but need use current date.
can explain why happens?
edit: these simplified versions of query, same behavior appears. explain plans.
explain plan select * communication c c.campaign_start_date <= sysdate , sysdate <= c.campaign_end_date;
plan hash value: 4120205924
------------------------------------------- | id | operation | name | ------------------------------------------- | 0 | select statement | | | 1 | table access full| communication | -------------------------------------------
.
explain plan select * communication c c.start_date = sysdate , sysdate = c.end_date;
plan hash value: 1474125303
------------------------------------------------------------------- | id | operation | name | ------------------------------------------------------------------- | 0 | select statement | | | 1 | table access index rowid | communication | | 2 | bitmap conversion rowids | | | 3 | bitmap , | | | 4 | bitmap conversion rowids| | | 5 | index range scan | communication_start_dt | | 6 | bitmap conversion rowids| | | 7 | index range scan | communication_end_td | -------------------------------------------------------------------
did try today day in timestamp? to_timestamp ('27-oct-15 14:10:10.123000'
? doesnt make sense compare query using 2 different days.
my guess using current date , <=
mean check of rows anyway. mean using index wont give benefit
try query.
select count(*)
and
select count(*) .... c.start_date <= sysdate , sysdate <= c.end_date
if both count(*)
similar mean there isnt benefit on using index because need scan full table anyway.
Comments
Post a Comment