!=, <>, NOT IN, NOT EXISTS, NOT LIKE |
Negations typically match most of the table, defeating B-Tree narrowing. |
Use positive ranges, explicit IN (...) sets, or LEFT JOIN … IS NULL where appropriate. |
Implicit type conversion
WHERE name = 1 (when name is VARCHAR) |
MySQL casts every stored string to a number (CAST(name AS DOUBLE) = 1), making the index unusable. |
Always match literal types to column types: WHERE name = '1'. |
Leading wildcard
LIKE '%abc%' |
B-Tree keys are ordered from the leftmost character, so an unknown prefix forces a full scan. |
Use prefix search LIKE 'abc%' (uses index) or a full-text / Elasticsearch index for substring search. |
Calculations / functions on column
WHERE id + 10 < 20 |
The engine must evaluate the function on every row before comparing. |
Move all arithmetic and date math to the constant side: WHERE id < 10. |
Unindexed OR
WHERE name = '1' OR created = '2021-05-02' |
If either branch lacks a usable index, MySQL falls back to a full table scan. |
Index both columns (allowing index_merge) or split into two indexed queries combined with UNION ALL. |