Read EXPLAIN QUERY PLAN output in SQLite
SQLite's EXPLAIN QUERY PLAN is a short report: SCAN means a full pass over a table, SEARCH means an index lookup, TEMP B-TREE means an extra sort.
The task
SQLite usually runs inside an application, often on a phone, where a query that scans a 200,000-row table on every screen load is the difference between instant and visibly slow. EXPLAIN QUERY PLAN prints how SQLite will access each table, one line per step, and four phrases cover most of what you need: SCAN, SEARCH, USING INDEX and USE TEMP B-TREE.
The snippet
Written for SQLite.
EXPLAIN QUERY PLAN
SELECT o.id, o.total, c.name
FROM orders o
JOIN customers c ON c.id = o.customer_id
WHERE o.created_at >= '2026-01-01'
ORDER BY o.total DESC;
So funktioniert es
For a join, the table lines appear at the same level in loop order: the first is the outer loop and each later line runs once per row of the lines above it. Subqueries and CTEs are the parts drawn as indented children. With an index on orders.created_at, the output here is SEARCH o USING INDEX idx_orders_created (created_at>?), then SEARCH c USING INTEGER PRIMARY KEY (rowid=?), then USE TEMP B-TREE FOR ORDER BY. SCAN o would mean SQLite reads every row of o. A rowid lookup is the cheapest access there is. The temp B-tree means the ORDER BY does not match an index, so SQLite collects the rows and sorts them: fine for 100 rows, slow for a million. A SCAN on any table after the first is the line to fix, because it repeats once per outer row.
Variations
Plain EXPLAIN for the low-level opcodes
EXPLAIN
SELECT o.id, o.total
FROM orders o
WHERE o.customer_id = 42;
Gather statistics, then check the plan again
ANALYZE;
EXPLAIN QUERY PLAN
SELECT * FROM orders WHERE customer_id = 42 AND status = 'paid';
Questions that come up
SCAN shows up even though I created an index. Why?
Common causes: the WHERE clause wraps the column in a function (upper(status) = 'X' gives SCAN even with an index on status), the index does not lead with the filtered column, the column and the value have different type affinities, or the planner has no statistics. SQLite only knows how selective an index is after ANALYZE (or PRAGMA optimize) fills sqlite_stat1, so run it after creating indexes or loading data.
What does USING COVERING INDEX mean?
Every column the query needs is in the index, so SQLite answers from the index and skips the lookup into the table for each row. SQLite has no INCLUDE clause, so you get it by adding the selected columns to the end of the index key: with CREATE INDEX ix_cc ON orders(customer_id, created_at), SELECT customer_id, created_at FROM orders WHERE customer_id = 5 shows SEARCH orders USING COVERING INDEX ix_cc.
Keep reading
Run these with autocomplete that knows your tables
SQLly is a native SQL workbench for macOS, Windows and Linux. Paste a snippet into a live connection and you get schema-aware IntelliSense, a plan viewer and guards against unsafe edits.