0Pricing
SQL Interview Prep · Lesson

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

  1. AND/OR Precedence and Parenthesization
  2. BETWEEN, IN, and Inclusive Boundaries
  3. LIKE, Wildcards and Escaping
  4. Filtering on Calculated Values
← Back to SQL Interview Prep