I have created script to find selectivity of each column for all tables. In some tables with less than 100 rows, selectivity of a column is more than 50%.
Where Selectivity = Distinct Values / Total Number Rows. Are those columns eligible for an index? Or, can you tell me the minimum requirement for number of rows to create an index?
I have created script to find selectivity of each column for all tables. In
Share
You can index on any column – the question is whether it makes any sense and whether that index will be used….
Typically, a selectivity of less than 1-5% might work – the smaller that percentage, the better. The best is single values out of a large population, e.g. a single customer ID out of hundreds of thousands – those indices will definitely be used.
Things like gender (only 2 values) or other things that only have a very limited number of possible values typically don’t work well on an index. At least on their own – these columns might be ok to be included into another index as a second or third column.
But really, the only way to find out whether or not an index makes sense is to
There’s no golden rule as to when an index will be used (or ignored) – too many variables play into that decision.
For some expert advice on how to deal with indices, and how to find out which indices might not get used, and when it makes sense to create an index, see Kimberly Tripp’s blog posts: