I have a table with around 15 columns which can be queried with different combination. The table columns for instance is UserID, LocationID, DepartmentID, CoOrdinate1, CoOrdinate2, CoOrdinate3…CoOrdinate15.
To speed up the retrieval of combination of data we have created a Computed field where we are storing the values of these columns in the format :UserID::LocationID::DepartmentID::CoOrdinate1:…:CoOrdinate15: – a sample value would look like :1:100:20:22:39:94:29:..:9:
While this is fine for retrieving data where the index key matches (= operator) we are exploring the best method to fetch combinations.
For instance if the user queries for UserID = 1 and CoOrdinate = 15 we plan to build a Like condition ‘%:1::%::%::%::%::%::%::%::%::15:%’.
SQL Server is doing an Index Scan to retrieve the data. From a performance point of view – is there a better way to approach this problem.
let me sum this up:
In general, the solution to this problem is having bitmap indexes on each columns, because bitmap indexes can be combined. Unfortunately SQL Server does not support bitmap indexes but I’ve heard it has some similar feature. I suggest you look into that:
http://msdn.microsoft.com/en-us/library/bb522541.aspx
(This article discuss the usage of bitmap indexes when joining tables, but dont let that confuse you, they can be useful in your use case as well, when you query a single table.)