In SQL Server 2008,
select * from OneTable
compare to
select * from OneTable where OneTable.SomeDate between 'MINDATE' and 'MAXDATE'
which one is fast or they are same fast?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Those queries are only functionally equivalent if you’re retrieving the entire table in which case providing an extra clause which in no way limits the data being retrieved is unlikely to be any faster. It may be slower (a) by virtue of the fact that you access the data via an index. With the full table scan option, you don’t ever need to touch the index.
It will certainly be faster to limit the rows retrieved at the server side rather than get everything and then filter at the client side (assuming of course that you have an index on your
SomeDatecolumn).But that’s only for the case where you’re not retrieving every row.
(a) Or your DBMS may figure out early that you’ve asked for everything and do a full table scan anyway, minimising the impact.
But it will probably still be marginally slower just because this check needs to be done up front.