2
Assuming I have a database table with 10000 data and each record is registered with dates between 2013 and 2014.
A query like this:
SELECT CAMPO_DATA FROM TABELA WHERE CAMPO_DATA BETWEEN '2013-01-01' AND '2014-12-31'
will be faster than:
SELECT CAMPO_DATA FROM TABELA WHERE CAMPO_DATA BETWEEN '2000-01-01' AND '2100-12-31'
?
If I use the second way this can greatly affect the speed of the query if the table has many items?
I am in doubt because I do not know if sql first sees what range of dates the table has or if it goes through according to the limits I established.
A small table like this the BD probably "eats with flour" but if the table is large (millions of records) then the figure changes. In the second case maybe it was the case of not even having Where condition but it can be a case of a parameterized Usta and then worth having a single SELECT.
– Motta