Consider a table 'Orders' with 4 columns
OrderNumber : DealerNumber : Code : Time
There's a non clustered index on OrderNumber, DealerNumber and Code. Time does not have on
So
select * from Orders where OrderNumber = 10 and DealerNumber = 20
is pretty fast. But the bigger the table gets the more duplicates are retrieved. An order from 2010 can be found and one from 2014. So I changed the query into
select *
from Orders
where OrderNumber = 10 and DealerNumber = 20 and [Time] > getdate() - 180
But this will change the execution time of the query from < 1 second to >30 minutes so thats not an option.
I heard something about filtered indexes. Would it be wise to put a filtered index on [Time] column? If so will generating the index take a long time?
Or are there better options to let the second query run very fast?