Well, before I start, I want to say that I'm completely new to this Sql indexing.
I have a table that does 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 million rows in this table. And do a search on it very slowly, so I believe that I need to add some indexes.
I will only run the following queries:
Request 1
select * from Table where String1 = "Blah" and String 2 = "Blah" and DateTime1 <= {someTime1} and DateTime2 >= {someTime1}
Request 2
select * from Table where String1 = "Blah" and String 2 = "Blah" and DateTime2 >= {someTime1}
Request 3
select * from Table where String1 = "Blah" and String 2 = "Blah" and DateTime3 >= {someTime1}
Note that they represent almost the same query, except that they have a slightly different date comparison. In addition, sorting is not a problem.
So I tried adding a nonclustered index to the columns String1, String2, DateTime1, DateTime2. Fulfilling query 1 here, what I see:
- Now it is much faster, but loading takes about 20 seconds.
- I notice that for the 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 seconds to load.
- I noticed that my RAM rises and stays after the request.
So here are my questions:
- Am I doing it right? Why boot for 20 seconds? Isn't it really fast after adding an index?
- What does the Sql server do with my RAM? Do I need more RAM because I have a large 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
source share