Sobes.tech
Junior — Middle

Explain the principle of index selectivity in an SQL database and why it is important for query optimization.

sobes.tech AI

Answer from AI

Index selectivity in a database is a measure of how effectively the index filters rows from the table. It is defined as the ratio of the number of unique values in a column to the total number of rows.

High selectivity means the index helps quickly find a small number of rows, speeding up query execution. Low selectivity (e.g., when many values are repeated) makes the index less useful, and the optimizer may ignore it.

The query optimizer uses selectivity to decide whether to use an index for data retrieval or to perform a full table scan. Proper use of high-selectivity indexes significantly improves query performance.