Ok before I start I want to say, I am totally new to this Sql indexing thing.
I have a table that is not join to anything. It has the following columns:
Id (int)
String1 (nvarchar(10)
String2 (nvarchar(50)
DateTime1 (date)
DateTime2 (date)
DateTime3 (date)
I have about 100,000,000 of rows on that table. And doing a search on it is very slow, so I figure I have to add some indexes.
I will ONLY run the following queries:
Query 1
select * from Table
where String1 = "Blah" and
String 2 = "Blah" and
DateTime1 <= {someTime1} and
DateTime2 >= {someTime1}
Query 2
select * from Table
where String1 = "Blah" and
String 2 = "Blah" and
DateTime2 >= {someTime1}
Query 3
select * from Table
where String1 = "Blah" and
String 2 = "Blah" and
DateTime3 >= {someTime1}
Notice that they are pretty much the same query except they have a slightly different date comparison. Also, sorting is not an issue.
So I tried adding a non-clustered index on the column String1, String2, DateTime1, DateTime2. Running Query 1 here's what I see:
- It is a lot faster now, but still takes about 20 sec to load.
- I notice that for the same exact same query (with the same search parameters) if I call it again it will return data in less than a second.
- I notice that if I run query 1 with some other parameters, it will again take 20 secs to load.
- I notice that my RAM goes up and stays up after the query.
So here are my questions:
- Am I doing this right? Why does it take 20 secs to load? Shouldn't it be very fast after I added index?
- What is Sql server doing with my RAM? Do I need more RAM because I have a big table?
- Do I need to add new indexes for query 2 and query 3? Or is the index that I added already good enough for the other 2 queries?
Thanks,
Chi