I have roughly 365 Million Rows inside my tables and each day we add an additional Million rows after the data is a year old it gets moved to a different table that archives our data.
I have a PK Clustered index on DataCollectionID.
I have one other index: a Unique Nonclusted index on AssetID, DataPointID, and DatapointDate
I need to run multiple select queries against the table pretty quickly… here is my select Query:
SELECT [DataPointID]
,[SourceTag]
,[DatapointDate]
,[DataPointValue]
FROM DataCollection
Where
DatapointDate >= '2012-09-07' AND
DatapointDate < '2012-09-08' AND
DataPointID = 1100
ORDER BY DatapointDate
This query should return 8,640 rows which it does but it takes 00:00:08 (8 seconds) to execute. Even if I said give me top 10 it still takes 8 seconds. Can someone please help me speed up this process?
I think a more effective index to help this query would be on DataPointID, DataPointDate, in that order. This will allow the optimizer to quickly narrow down the field with an equality operator on the first index column, then find the date range within that set.
There are some good examples of indexes and similar queries here:
http://sqlserverpedia.com/wiki/Index_Selectivity_and_Column_Order