I am trying to figure out why selecting rows within a time-range takes too much time.
I have one database table with more than 5 million rows.
There is a Non-Unique, Non-Clustered Index on the FooTimestamp column which is type of DateTimeOffset.
When I try to retrieve some rows within a time-range, it takes more than 2 minutes. (When I run it again it is relatively faster due to caching capabilities of MS-SQL Server 2008, I guess)
DECLARE @since datetimeoffset
DECLARE @before datetimeoffset
SET @since ='2013-03-20 00:00:00 +02:00'
SET @before ='2013-03-27 00:00:00 +02:00'
SELECT *
WHERE ([FooTimestamp] >= @since AND [FooTimestamp] <= @before)
Question: When it comes to retrieve rows from a table having millions of records, what should I do to get the query results faster? (I think 2 minutes for such a straight-forward query is too much)