Why MySQL Is Not Using My Index? (Beginner-Friendly Fix Guide)
🧠 Introduction
One of the most confusing problems for beginners is:
“I already created an index…
Why is MySQL still not using it?”
You check your table.
You confirm your index exists.
Yet, when you run the query with EXPLAIN, MySQL says:
Meaning: full table scan.
Not using your index.
Ignoring your hard work.
Don’t worry. This is extremely common — and very fixable.
Let’s walk through why MySQL ignores indexes and how to fix each cause, with simple explanations that even total beginners will love.
🔍 Step 1: Check If Index Really Exists
First things first.
Run:
Make sure your index is truly there.
Why this matters:
You’d be surprised how often developers think they created an index, but didn’t.
❌ Problem #1: You Used a Function in the WHERE Clause
Example:
MySQL cannot use an index if you wrap the column in:
-
LOWER()
-
UPPER()
-
DATE()
-
YEAR()
-
CAST()
-
TRIM()
-
etc.
✔️ Fix:
Transform the value, not the column.
❌ Problem #2: Data Type Mismatch
Example:
If id is INT but you compare with a string → index may be skipped.
✔️ Fix:
Always match data types.
❌ Problem #3: Index Field Not in the Leftmost Position
For composite indexes, MySQL only uses the “leftmost prefix”.
Example index:
This index can optimize:
-
name
-
name + email
But NOT email alone.
❌ Slow:
✔️ Fix:
Add a dedicated index:
❌ Problem #4: Low Selectivity (Too Many Rows Have Same Value)
If your column has values like:
-
status = 'active'on 98% of rows -
type = 'user'on 90% of rows
MySQL knows the index is pointless.
✔️ Fix:
Index more specific fields
OR use composite index:
Now the index becomes selective.
❌ Problem #5: Leading Wildcard Makes Index Useless
Beginners often write:
If it starts with %, MySQL cannot use index.
✔️ Fix:
Use this:
Or use full-text search:
❌ Problem #6: OR Condition Without Proper Index
Example:
If both columns are not indexed → slow.
✔️ Fix:
Add indexes for both:
❌ Problem #7: Sorting (ORDER BY) on Unindexed Column
Example:
If created_at has no index → full table scan + slow sort.
✔️ Fix:
❌ Problem #8: Table Is Too Small — Index Not Used By Design
If your table only has:
-
20 rows
-
50 rows
-
even 100 rows
MySQL may prefer a full scan.
This is normal.
✔️ Fix:
Don’t worry — this is not an error.
❌ Problem #9: Using Functions in JOIN
Example:
This destroys index usage.
✔️ Fix:
Compare raw values:
❌ Problem #10: Statistics Need Updating
Sometimes MySQL simply guesses wrong.
Run:
This refreshes table statistics so MySQL can choose a better execution plan.
🧪 Bonus: Use EXPLAIN to Check Index Usage
Example:
You want to see:
You don’t want:
Which means “full table scan”.
🎉 Conclusion
When MySQL ignores your index, it's not being stubborn — it’s following strict rules.
Most of the time, the fixes are simple:
-
Don’t wrap columns in functions
-
Use the right data types
-
Avoid leading
% -
Use composite indexes correctly
-
Keep table statistics fresh
Once you understand why the index is skipped, optimizing becomes easy and logical.