I have a huge (millions of rows) table containing the following columns:
[When] datetime2(0), [What] tinyint, [Who] bigint
This is basically a table of events (βWhatβ) that happened to various objects (βWhoβ) at a time (βWhenβ). There are about 10 different meanings for βWhatβ - this is an enumeration. There are currently about 10,000 values ββfor Who.
I want to be able to query this table to ask if something happened to one or more objects between a certain time. For example, [What = 0, 1, 2, 3] happened with [Who = 0, 1, 2, 3] between [When = '2012-10-01' to '2012-11-01'].
I am looking for tips on how best to index this table. I'm sure a composite index is the way to go, but I'm not sure about the exact configuration. For example, what should be the order of the columns? I read that the "most selective" columns should go to the left, and I think that in this case there will be [When], [Who], [What]. Is it correct?
Sorry if this question seems vague, but I would be grateful for any input. I am using SQL Server 2012.
source share