Selectivity describes how effectively a condition reduces the number of matching rows. Highly selective conditions usually identify fewer rows.
Understanding selectivity helps explain why some JOINs and filters perform better than others.
A JOIN using a unique CustomerID generally has different behavior from a JOIN using a common Country value.
SELECT
c.CustomerID,
c.CustomerName,
o.OrderID
FROM Customers c
INNER JOIN Orders o
ON c.CustomerID = o.CustomerID
WHERE c.CustomerID = 1001;
Used in database optimization, index design, query tuning, and performance troubleshooting.
- Selective conditions reduce matching rows.
- Unique keys are generally highly selective.
- Low-selectivity columns may match many rows.
- Data distribution influences optimizer decisions.
- Indexes are more useful for some selective workloads than others.
What is selectivity in SQL?
Selectivity describes how much a condition narrows the possible rows.
Why does selectivity matter for JOIN performance?
Highly selective conditions can reduce the amount of data the database needs to process.