Optimization

Avoiding Index Killers

Senior Data Analyst
March 16, 2026
5 min read

The Killers

1. Functions on the Indexed Column

-- BAD: Index on 'order_date' won't help

WHERE DATE_TRUNC('month', order_date) = '2026-01-01'

-- GOOD: Use a range instead

WHERE order_date >= '2026-01-01' AND order_date < '2026-02-01'

2. Implicit Type Conversion

-- BAD: 'customer_id' is INT, but you're comparing to a string

WHERE customer_id = '100'

-- GOOD

WHERE customer_id = 100

3. OR conditions

`OR` often prevents index use. Consider `UNION ALL` instead.

*Day 76: Optimizing JOINs.*

Ready to put your knowledge into practice?

Join SQL Mastery and learn through interactive exercises.