After running a fairly hefty query, the execution plan gave me a missing index suggestion which was of the form:
(Timestamp) INCLUDE (CustomerID, EventID, ID, EmployeeID)
Which seems to be a covering index (the INCLUDE column are all either primary keys (ID) or foreign keys). However, my querys WHERE clause is filtering by Timestamp, CustomerID, and EventID. I don't know why these weren't included in the main part of the index.
So my question is, is there any difference in using the suggested index above, or what I think is a better alternative;
(Timestamp, CustomerID, EventID) INCLUDE (ID, EmployeeID)
My understanding is that this will still allow Timestamp-only index seeking, but will also further assist my query by having the customer and event IDs (which are filtered) in the main part.
I think this was something to do with the width of the 'main' part - FYI, Timestamp is a datetime2(0), CustomerID is an int, and EventID is a byte.
I am testing this myself at the moment, but this is a HUGE table - over 1,000,000,000 rows - and it is taking time to compare the indexes. That, and I'd like to learn more about this.
Thanks.
Timestamp
by itself might be selective enough to filter out 90% of the results, how much data do you change?ID
column) is automatically part of every nonclustered index - so you really don't need to specify that again yourself in the list of included columns