I have an SQL table with several million records, and I tried to query how many records are older than 60 days (Oracle 11.2.0.1.0).
For this experiment, I used 3 different versions of select-statement:
(Cost value is indicated by TOAD for Oracle V. 9.7.2.5)
select count(*) from fman_file
where dateadded >= (select sysdate - 60 from dual)
Cost: 65
select count(*) from fman_file
where dateadded >= sysdate - 60
Cost: 1909
select count(*) from fman_file
where dateadded >= sysdate - numtodsinterval(60,'day')
Cost: 1884
select count(*) from fman_file where dateadded >= '10.10.2009'
Cost: 1823
(10.10.2009 - just an example-date !!!)
I don't have exact time values ββfor all requests, but the first one was really the fastest.
So, I tried some more select queries with other subqueries (e.g. (Select 1000 from dual)), and they were (sometimes WAY) faster than others with constant values. It seems that this "WHATEVER" (Bug / Feature) also happens in MySQL.
So can someone tell me why the first request (path) is faster than the others?
Greetz
PS: This is not about sidate! Question: WHY IS CHANGE WITH (SELECT) QUICKLY THAN OTHERS? (with a slight focus on Select-Variation (1.) versus constant variation (4.))
sql oracle oracle11g toad
Husky110
source share