PrepZone Logo
PrepZone
Back to Database

Database · Medium

What are selectivity and cardinality? How do they decide whether an index is used?

DatabaseIndexingSeniorPerformance

Answer preview

Cardinality is the number of distinct values in a column; selectivity is the fraction of rows a predicate returns. The optimizer uses statistics to estimate selectivity and only picks an index when the estimated fraction is small enough that random I/O beats a sequential scan.…