I've got an SQL-table with some million entries and I tried to query how much entries are older than 60 days (Oracle 11.2.0.1.0).
For this experiment I used 3 different versions of the select-statement:
(The cost-value is given by TOAD for Oracle V. 9.7.2.5)
select count(*) from fman_file
where dateadded >= (select sysdate - 60 from dual)
Cost: 65select count(*) from fman_file
where dateadded >= sysdate - 60
Cost: 1909select count(*) from fman_file
where dateadded >= sysdate - numtodsinterval(60,'day')
Cost: 1884select count(*) from fman_file where dateadded >= '10.10.2009'
Cost: 1823
(The 10.10.2009 is just an example-date!!!)
I don't have the accurate time-values for all queries in mind, but the first one really was the fastest.
So I tried some more select-queries with other subselects (like (Select 1000 from dual)) and they were (sometimes WAY) faster than the others with constant-values. It even seems that this "WHATEVER" (Bug/Feature) is happening in MySQL too.
So can anyone tell me why the first query is (way) faster that the others?
Greetz
P.S.: This ain't about the sydate! The question is WHY IS THE VARIATION WITH THE (Select) FASTER THAN THE OTHERS? (with a little focus on Select-Variation(1.) vs. Constant-Variation (4.))