Filtering on Calculated Values
Why functions on columns kill index usage and how interviewers probe this.
Why This Question Separates Levels
The prompt sounds innocent: this query is correct but slow, why? Often the answer is that the WHERE clause wraps an indexed column in a function. That makes the predicate non-sargable: the optimizer can no longer use the index and must scan every row.
This lesson explains sargability, shows the rewrites interviewers want, and covers where a calculated filter actually belongs.
Sargable in One Definition
Sargable (Search ARGument ABLE) means a predicate can use an index to seek directly to matching rows. The rule of thumb: the indexed column must appear bare on one side of the comparison, not buried inside a function or expression.
- Sargable:
col = 5,col > 100,col LIKE 'abc%' - Non-sargable:
FUNC(col) = 5,col + 1 > 100
All lessons in this course
- AND/OR Precedence and Parenthesization
- BETWEEN, IN, and Inclusive Boundaries
- LIKE, Wildcards and Escaping
- Filtering on Calculated Values