1. A function applied to the indexed column
Symptom
`created_at` is indexed. EXPLAIN still shows a sequential scan.
The pattern
SELECT * FROM events
WHERE DATE(created_at) = '2026-07-21';Why it bites
The index stores `created_at`, not `DATE(created_at)`. Wrapping the column in a function means the planner cannot map the predicate onto the index, so it evaluates the expression for every row in the table.
The fix
-- Keep the column bare; make the predicate a range.
SELECT * FROM events
WHERE created_at >= '2026-07-21'
AND created_at < '2026-07-22';
-- Or index the expression itself if the query shape is fixed:
CREATE INDEX idx_events_day ON events (DATE(created_at));