Index selectivity
- SQL course
- Expert
- Lesson 10/45
- 5 min
Learn selectivity and cardinality.
Index selectivity
Selectivity is the ratio of rows matching a condition. High selectivity (few rows) uses the index well; low selectivity (many rows) skips the index and scans the table.
-- seçicilik = eşleşen / toplam
-- 0.01 yüksek, 0.9 düşükHigh selectivity is good for indexes.
Index selectivity — details
The optimizer computes selectivity from statistics gathered by ANALYZE. Stale statistics give wrong plans; that is why ANALYZE runs after big changes.
Practice Index selectivity
Run ANALYZE to refresh statistics for the products table.
Starter code
-- gather statistics
ANALYZESample solution
ANALYZE products;Expected output
ANALYZE
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What does high selectivity mean?
- Many rows match
- The whole table is scanned
- The index is skipped
- Few rows match Correct answer
Explanation: High selectivity means few rows match.
2 Gather statistics
ANALYZE ____
ANALYZE products
Explanation: products is the right answer.
3 Index selectivity: match the terms
| Term | Meaning |
|---|---|
selectivity |
selectivity |
high |
high |
few rows |
few rows |
ANALYZE |
statistics |