The index selectivity is not the only criterion for deciding whether a table column makes an effective index. Also consider the types of queries that you want to run against the index. Use these examples to help you decide which table columns to index.
The following example would return a high selectivity rating: A table with 30000 rows, with column (A) containing values of between 1 and 15000, where none of the values occur more than twice.
Note how the usage of queries against the index can determine the effectiveness of the index.
For example, if the following WHERE clause is used in a query to access the rows of the table, the result is a high selectivity rating and the query makes good use of the index:
where A = 5 or A = 10
However, if the following WHERE clause is used to access the rows in the table, only two rows from the 30000 rows would be ignored by the index. This would therefore be a poor candidate for an index.
where A > 1
The following example would return a low selectivity rating: A table with 20000 rows, with column (B) containing values of either 1 or 2.
Note how the usage of queries against the index can determine the effectiveness of the index.
For example, if the following WHERE clause is used to access the rows in the table, all values are matched, and so there is no benefit from creating an index.
where B = 1 or B = 2
However, if the following WHERE clause is used to access the rows in the table, the effectiveness of the index depends on the distribution of the value 1:
where B = 1
The factors for determining the effectiveness of an index are as follows: