An index is only useful if the optimizer can use it for the query you wrote. Most "my index is ignored" cases come from a short list of causes. Check them in order, and confirm each with EXPLAIN before and after the change.
Functions wrapped around the column
An index is sorted by the stored value. If you apply a function to the column, MySQL would have to compute the function for every row to compare, so it cannot seek.
-- cannot seek on an index over created_at
SELECT * FROM payments WHERE DATE(created_at) = '2026-01-15';
-- same result, index friendly: compare the bare column with a range
SELECT * FROM payments
WHERE created_at >= '2026-01-15' AND created_at < '2026-01-16';If you must filter on an expression, MySQL 8.0.13 and later can index it directly with a functional index, for example CREATE INDEX idx_email_lower ON users ((LOWER(email)));, and queries that use the same expression can seek on it. A generated column with an ordinary index works on older versions too.
Type mismatches and implicit conversion
When the two sides of a comparison have different types, MySQL converts one side. If it has to convert the column, the index cannot be used. Comparing a varchar column with a number is the classic case: WHERE phone = 84901234567 converts every stored string to a number, while WHERE phone = '84901234567' seeks normally. The reverse is harmless, because comparing an integer column with a string literal converts the literal once. Keep parameter types equal to column types.
Leading wildcards and other pattern traps
LIKE 'abc%'can use an index because the prefix is known.LIKE '%abc'andLIKE '%abc%'cannot, since the sorted order says nothing about the end of a string. For real text search use a full-text index or a search engine.ORacross different columns often forces a scan, although MySQL can sometimes merge two indexes. Rewriting it as aUNION ALLof two indexed queries is often faster.!=,NOT INandNOT LIKEmatch most of the table, so the optimizer rarely finds an index worthwhile.
Collation and character set mismatches in joins
If two tables are joined on columns with different character sets or collations, for example utf8mb3 on one side and utf8mb4 on the other, MySQL must convert one column and cannot use its index for the join. Align the definitions of columns that are compared or joined. This is a common leftover from old schemas.
When the optimizer chooses a scan on purpose
Sometimes the index is usable and MySQL still ignores it, because it estimates that a scan is cheaper.
- The condition matches a large share of the table. Reading many rows through a secondary index, each with a lookup, costs more than reading the table in order.
- The table is tiny, so one page read beats any index.
- The statistics are stale. After large data changes,
ANALYZE TABLErefreshes them. - The query selects columns that are not in the index, forcing a lookup for each row.
You can compare the plans with an index hint such as FORCE INDEX, but use it as an experiment. If forcing the index is really faster, find out why the optimizer's estimate was wrong, and fix that.
A checklist. Work through these in order.
- Run
EXPLAINand look atkeyandrows. - Is the column wrapped in a function or arithmetic?
- Do the types of both sides of each comparison match?
- Is there a leading wildcard, an
ORor a negation? - Do joined columns share character set and collation?
- Is the index order right for the query, as covered in the previous article?
- Are the statistics fresh, and is the condition selective enough to justify an index?
Takeaway
Write predicates so the bare column is compared with a value of the same type, keep joined columns consistent, and treat an ignored index as a clue rather than a mystery. EXPLAIN tells you which of these causes is in play.
Comments