Why Postgres ignores your index
The planner skips an index when it expects it to be slower. EXPLAIN tells you which of the usual reasons applies.
You added an index and the query still does a sequential scan. Postgres is not broken: the planner estimated that the index would cost more. Start with the plan.
explain (analyze, buffers)
select * from orders where lower(email) = 'ana@example.com';
The usual reasons
- The expression does not match. An index on
emailcannot servelower(email). Index the expression itself:create index on orders (lower(email)). - The filter is not selective. If the condition matches a large part of the table, reading it sequentially is cheaper than jumping through the index.
- Stale statistics. After a bulk load, run
analyze ordersso the planner knows the real row counts. - Type mismatch. Comparing a
bigintcolumn with anumericparameter forces a cast that the index cannot use.
Measure again after each change; the plan, not intuition, decides.