What is index selectivity and why does it matter?

Answer

Selectivity measures how unique the values in an indexed column are — the ratio of distinct values to total rows. High selectivity (many distinct values, like email or UUID) means the index is very effective at narrowing down results quickly. Low selectivity (few distinct values, like a boolean is_active or a status column with 3 values) means the index returns a large fraction of rows — the query planner may choose a full table scan instead since following index pointers for 50% of rows is slower. Rule: indexes work best on high-cardinality columns. Index a low-selectivity column only in composite indexes where high-selectivity columns lead.