Why Your Index Isn't Being Used: Functions, Casts, LIKE and Low Selectivity
The common reasons a database ignores an index: non-sargable predicates, functions on columns, implicit casts, leading wildcards, OR, low selectivity and sta...
Published November 27, 2026
You added the index, but EXPLAIN still shows a full table scan. This is one of the most common frustrations in database work, and there are only a handful of usual causes. Most of them come down to one idea: the database can use an index only if the condition can be turned into a seek on the stored, sorted values. Such conditions are called sargable (Search ARGument ABLE).
The concept
An index stores the raw column values in sorted order. A condition like created_at >= '2026-01-01' maps directly onto that order. A condition like DATE(created_at) = '2026-01-01' does not: the index is not sorted by DATE(created_at), so the database would have to compute the function for every row. The same applies to arithmetic (price * 1.18 > 100), string functions (LOWER(email)), and implicit type conversions the database inserts silently.
The other big category is the optimizer deciding that the index is not worth it. If a condition matches a large fraction of the table, reading the table sequentially is cheaper than tens of thousands of random index lookups. That is a correct decision, not a bug, though it can also happen wrongly when statistics are stale.
Rewrites that make indexes usable
| Non-sargable (index ignored) | Sargable rewrite |
|---|---|
| WHERE DATE(created_at) = '2026-11-27' | WHERE created_at >= '2026-11-27' AND created_at < '2026-11-28' |
| WHERE LOWER(email) = 'a@b.com' | Expression index on lower(email), or store normalised |
| WHERE price * 1.18 > 118 | WHERE price > 100 |
| WHERE name LIKE '%sharma' | Trigram/full-text index, or a reversed-string column |
| WHERE phone = 9876543210 (phone is VARCHAR) | WHERE phone = '9876543210' |
| WHERE COALESCE(deleted_at, NOW()) > NOW() | WHERE deleted_at IS NULL OR deleted_at > NOW() |
The diagnosis checklist
- Is a function, cast or arithmetic applied to the indexed column?
- Is there a leading wildcard (LIKE '%x')?
- Do the column and literal types match (string vs number, collation)?
- Is it a leftmost prefix of the composite index?
- Does the condition match a large share of rows (low selectivity)?
- Are statistics fresh (ANALYZE)?
Selectivity changes the plan
The silent cast
Practical examples
Expression index for case-insensitive lookups
Index exactly the expression the query uses.
-- PostgreSQL
CREATE INDEX idx_users_lower_email ON users (lower(email));
SELECT * FROM users WHERE lower(email) = lower('Max@Example.com');
-- MySQL 8.0.13+
ALTER TABLE users ADD INDEX idx_users_lower_email ((lower(email)));OR across different columns
Rewrite as UNION ALL so each branch can use its own index (or rely on bitmap OR in PostgreSQL).
SELECT id FROM tickets WHERE assignee_id = 7
UNION ALL
SELECT id FROM tickets WHERE reporter_id = 7 AND assignee_id IS DISTINCT FROM 7;Parameter type mismatches in application code
ORM parameters bound as the wrong type cause the same silent cast.
// Bad: numeric binding against a VARCHAR column
db.query('SELECT * FROM users WHERE phone = ?', [9876543210])
// Good
db.query('SELECT * FROM users WHERE phone = ?', ['9876543210'])Common mistakes
- Wrapping indexed columns in functions in WHERE clauses.
- Comparing a string column with a number (or different collations in joins).
- Expecting LIKE '%term%' to use a B-tree index.
- Adding an index on a column where most rows share one value and expecting it to be used.
- Forcing an index with a hint when the optimizer correctly preferred a scan.
Key takeaways
- Sargable predicates compare the raw column to a value or range.
- Functions, arithmetic and implicit casts on the column disable the index.
- Low-selectivity conditions make scans legitimately cheaper.
- Use expression, trigram or full-text indexes when you cannot rewrite the predicate.
FAQ
What does sargable mean?
Search ARGument ABLE: a predicate the database can turn into an index seek or range scan.
Does LIKE 'abc%' use an index?
Yes, a trailing wildcard is a prefix range. In PostgreSQL with a non-C collation, use text_pattern_ops or the C collation for the index.
Can I force the index?
MySQL has FORCE INDEX and PostgreSQL has no built-in hints (pg_hint_plan adds them). Treat hints as a last resort after fixing statistics and predicates.