Menu

5 Reasons Your SQL Index Is Being Ignored (and How to Fix Them)
πŸ“°

5 Reasons Your SQL Index Is Being Ignored (and How to Fix Them)

DEV Community: databaseΒ·Muiduzzaman LipuΒ·about 3 hours ago
#4UjEf9l4
#devtodatabase#devto#dev#index#users
Reading 0:00
15s threshold

You added an index, but the query is still slow. The database may be ignoring the index completely and reading every row. Here are the five most common reasons, and how to fix each one.

I checked every query plan below in SQLite on a 100,000-row table. The same rules apply to PostgreSQL and MySQL.

Video version:

First: ask the database with EXPLAIN

Don't guess. Put EXPLAIN in front of the query ( EXPLAIN QUERY PLAN in SQLite, EXPLAIN or EXPLAIN ANALYZE in Postgres and MySQL):

EXPLAIN QUERY PLAN SELECT * FROM users WHERE email = '[email protected]' ; SEARCH users USING INDEX idx_email ( email =? ) βœ… index used

EXPLAIN QUERY PLAN SELECT * FROM users WHERE DATE ( created_at ) = '2025-06-01' ; SCAN users ❌ reads every row

Enter fullscreen mode

Exit fullscreen mode

SEARCH … USING INDEX (or Index Scan in Postgres) means the index is working. SCAN (or Seq Scan ) means a full table scan.

1.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.