Let's assume we have a table with name Tournament
and columns of this table are Id, Name, GameId, TypeId, cityId, Status, Format
. Except Id
and Name
columns I want to search this table with all of the combinations of these columns, I mean I can search with GameId & Status
or TypeId & CityId & Status
or Status & Format
.
As you can see all of the search options count is equal to
=C(5,1)+C(5,2)+C(5,3)+C(5,4)+C(5,5).
So here is my question,what is the best indexing scenario and why? I think the options are,
- Index for each column.
- Composite ındex for all columns.
I know composite index is really faster than single index but if you go correct order, I mean if I have a composite index on [GameId, TypeId, CityId, Status, Format]
columns and search like GameId = 1 & TypeId = 2 & CityId = 3 & Status = 5 & Format = 6
it will work great, but how about if I search GameId = 1 & Format = 6
I can not realize how this query will works fast enough, as I know SQL Server composite index is just a b-tree and the b-tree keys of composite index are ordered from left to right columns.