Skip to content

How to read a query execution plan

A query execution plan describes the work a database chose for a SQL statement. Read it to find which tables are scanned, which indexes are searched, how joins are nested, and whether the database creates temporary work for sorting or grouping.

  • 3 minute read
  • Examples run in SQLite

Four SQLite plan records to know

A scan is not always a mistake. Reading a small table, or most of a table, can cost less than using an index. The plan gives you evidence to compare with the size and shape of the data.

  • SCAN means SQLite reads a table or an index from beginning to end.
  • SEARCH means SQLite uses an index to find a smaller set of rows.
  • USING COVERING INDEX means the index holds every column this query needs.
  • USE TEMP B-TREE means SQLite builds a temporary structure to sort rows, group them, or remove duplicates.

Key points

  • Match every plan record to a table or subquery in the SQL.
  • Check whether each filter appears in the chosen index search.
  • For joins, read the records in nesting order and ask how often each inner lookup runs.
  • Look for a temporary B-tree when the query sorts, groups, or removes duplicates.
  • Compare the plan with the table size and the share of rows the filter returns.
  • Run the query again after every change, and confirm the result first.

Plans are estimates and choices

SQLite EXPLAIN QUERY PLAN describes the chosen work, but it does not measure elapsed time. SQLite plan text does not report the same cost fields or node names as PostgreSQL or MySQL. A SEARCH record also does not prove that the query is fast. Data size, the share of rows a filter matches, caching, and repeated work still matter.

Practice this in Module 2: How queries run

Ten exercises on SCAN and SEARCH records.

See Module 2