IndexesdebuggingIntermediate
The index exists but the planner ignores it
Symptoms
- There is a composite index that "covers" the query, but EXPLAIN shows a Seq Scan.
- A similar query on the same table does use an index.
-- index present:
"users_city_country_idx" btree (city, country)
EXPLAIN SELECT id FROM users WHERE country = 'DE';
Seq Scan on users (rows=900)
Filter: (country = 'DE')Investigate
Inspect areas in any order (0/4 inspected). When you think you know the root cause, commit to it.
Column order in the index
Statistics freshness
Selectivity of country
The query that does use an index