How can I use EXPLAIN QUERY PLAN to inspect a SQLite index choice?
Quick answer
Put EXPLAIN QUERY PLAN before the SELECT you want to inspect. Read the result as a high-level description: SCAN and SEARCH describe table-read strategies, and the details may identify an index. Compare the same query before and after creating a candidate index. Treat the output as a debugging aid, not a stable format or proof that an index will always be chosen. [S1]
The question, the details, the next step.
A practical checklist
Choose the SELECT statement and WHERE condition you want to inspect.
Run EXPLAIN QUERY PLAN on that query before changing indexes.
Record the broad table-read detail and any index named.
Create a candidate index relevant to the query, then run the same plan query again.
Compare meanings rather than exact output text; note that SQLite may choose not to use the index.
A few more useful answers
Does SEARCH always mean the query will be faster?
No. It describes the plan’s lookup strategy; it does not establish performance for your particular data and workload.
Can I write a script that depends on a particular EXPLAIN QUERY PLAN line?
Avoid relying on fixed output wording. SQLite documents the output as an interactive debugging aid and warns that its format may change between releases. [S1]
Will creating an index make SQLite use it?
Not necessarily. Index selection depends on the query and database, so compare the resulting plan instead of assuming it will change. [S1]
Sources
References used for this guide.
- [S1] SQLite EXPLAIN QUERY PLAN: reading scans and index use sqlite.org · Checked
