Index selectivity is the measure of how effectively an index narrows a search, usually expressed as the ratio of distinct key values to total rows or as the fraction of rows a predicate returns. In databases and in indexing practice, it is the single most important property deciding whether an index is worth reading at all, because the query planner compares the estimated cost of an index lookup with the cost of a full table scan.
A highly selective index points to a small slice of the table, such as one customer by email address, while a low-selectivity index points to a large share of rows, such as all orders with status ‘shipped’. The distinction drives index design, column order in composite indexes and plan choice, and misjudging it is one of the most common causes of slow queries.
How index selectivity is calculated
Index selectivity is calculated in two related ways, and practitioners should know which one a tool reports. Column selectivity (sometimes called index cardinality ratio) divides the number of distinct values by the total number of rows, giving a value between near zero and exactly 1.0 for a unique index. Predicate selectivity is the estimated fraction of rows that a specific condition returns, so a lower number means a more selective filter.
The two views can disagree. A column with many distinct values can still produce a poorly selective predicate when the data is skewed, for example when 60% of rows share one value and the rest are spread thinly. For this reason, modern optimizers rely on histograms and most-common-value lists, not only on distinct counts, to estimate how many rows each predicate will return.
The table below shows typical selectivity values for common column types in a table of one million rows.
| Column type | Distinct values | Column selectivity | Index usefulness |
|---|---|---|---|
| Primary key | 1,000,000 | 1.0 | Excellent for point lookups |
| Email address | About 999,000 | Close to 1.0 | Excellent |
| Customer ID on orders | About 50,000 | 0.05 | Good for equality filters |
| Country code | About 200 | 0.0002 | Depends on skew |
| Boolean flag | 2 | 0.000002 | Usually poor unless skewed |
Why the query planner depends on selectivity
The query planner uses selectivity to estimate row counts, and row counts drive every cost decision in a plan. An index lookup through a non-clustered or secondary B-tree index requires random I/O for each matching row, because the table rows live elsewhere, while a sequential scan reads pages in order and benefits from prefetching and larger reads.
As a result, there is a break-even point beyond which an index scan becomes more expensive than reading the whole table. This threshold is not a fixed constant; it depends on storage type, row width, clustering of the data on disk and memory caching. On spinning disks the crossover was often a few percent of rows, while on SSDs with a warm buffer cache it can be considerably higher.
The following table summarizes the factors that shift the break-even point.
| Factor | Effect on threshold | Reason |
|---|---|---|
| Correlation of key and physical order | Raises it | Matching rows sit on fewer pages |
| Covering index | Raises it sharply | No table lookups are needed |
| Fast random I/O on SSD | Raises it | Random reads cost less |
| Wide rows | Lowers it | Fewer rows fit on each page |
| Cold cache | Lowers it | Each lookup may hit storage |
Because the planner relies on estimates, stale statistics produce wrong selectivity numbers and therefore wrong plans. Running the engine’s statistics collection, such as ANALYZE or UPDATE STATISTICS, after large data changes is a basic part of index maintenance.
Selectivity in composite and specialized indexes
In a composite index, selectivity applies to the combination of leading columns, not to each column alone. Two columns that are individually weak, such as region and product category, can together form a highly selective prefix. Optimizers that assume column independence often underestimate this combined effect, which is why several engines support extended or multi-column statistics.
Column order also matters. A common rule places equality-filtered columns first and range-filtered columns last, and among equality columns it often favors the more selective one. However, the rule is secondary to matching real query patterns: a leading column that queries rarely filter on makes the index unusable for them regardless of its selectivity.
Different index types respond to selectivity in different ways, as the comparison below shows.
| Index type | Preferred selectivity | Typical use |
|---|---|---|
| B-tree index | High | Point lookups and narrow ranges |
| Hash index | Very high | Exact equality on unique-like keys |
| Bitmap index | Low | Analytical filters on few distinct values |
| Partial index | High within subset | Rare values in a skewed column |
| Unique index | Maximum | Integrity and single-row access |
The partial index deserves special attention. When only 1% of orders have status ‘pending’, an index restricted to that status is small and extremely selective, while the remaining 99% of rows never enter the index at all.
Designing indexes with selectivity in mind
Good index design starts from the queries, then checks selectivity to confirm that an index will actually be used. Practitioners typically inspect distinct counts, value distribution and execution plans before creating an index, because an unused index still costs write overhead and storage on every insert, update and delete.
The decision table below captures common situations.
| Situation | Recommended choice | Reason |
|---|---|---|
| Filter returns well under 1% of rows | Standard B-tree index | Lookups are cheap and few |
| Filter targets one rare value in a skewed column | Partial index | Small index with high selectivity |
| Two weak columns always filtered together | Composite index | Combined prefix is selective |
| Filter returns a large share of rows | No index or covering index | Scan is usually cheaper |
| Low-cardinality columns in analytics | Bitmap or columnar storage | Built for bulk filtering |
Common mistakes and misconceptions
Several errors recur in production systems, and most come from treating selectivity as a static property of a column rather than of a predicate on real data.
- Assuming that every filtered column needs an index, which adds write cost without improving reads.
- Indexing a boolean or status column without checking skew, so the planner ignores the index.
- Ignoring parameter-sensitive plans, where a cached plan built for a rare value is reused for a common one.
- Forgetting that functions on indexed columns, such as wrapping a column in
LOWER(), prevent the index from being used unless an expression index exists. - Trusting outdated statistics after bulk loads, which leads to severe misestimates.
A related misconception holds that low selectivity always makes an index useless. In practice, a covering index or an index that supports ordering and grouping can still pay off, because it avoids sorting or table access even when many rows qualify.
Stripped to the essentials
Index selectivity tells you how much an index helps you skip. Imagine a phone book. Looking up one exact name takes you straight to a single line, so the index is very selective. Looking up everyone whose name starts with a common letter gives you thousands of entries, so you might as well read the whole section.
A database makes the same judgment. If an index leads to just a few rows, the database uses it. If it leads to a large part of the table, the database usually reads everything in order because that is faster. The fewer rows an index points to, the more useful it is.
Where it is applied
A support team at an online retailer complains that the ticket dashboard loads slowly. The tickets table holds about 8 million rows, and the dashboard filters on status = 'open'. A developer had added a regular index on the status column, but the execution plan shows a full table scan. Checking the data reveals only five status values, with ‘closed’ covering 97% of rows.
Because open tickets make up only about 2% of the table, the team replaces the general index with a partial index on open tickets, ordered by creation time. The new index is roughly one fiftieth of the original size, the planner now chooses it, and the dashboard query drops from several seconds to under 50 milliseconds. The team also schedules statistics updates after nightly imports so the estimates stay accurate.