EXPLAIN
A command placed before a query that shows the plan the database would use instead of running it normally.
In more detail
In SQLite, EXPLAIN QUERY PLAN prints a short tree of SCAN and SEARCH steps. PostgreSQL's EXPLAIN shows estimated costs and row counts, and EXPLAIN ANALYZE actually runs the query and adds real row counts and timings. Measure first, then read the plan.
Example
EXPLAIN QUERY PLAN SELECT id, ordered_on FROM orders WHERE customer_id = 3 ORDER BY ordered_on;Related terms
- query plan — The step-by-step route the database has chosen to answer a query: which tables to read, in what order, and with which indexes.
- query planner — The part of the database that turns a SQL query into a plan, choosing among indexes, scans and join orders.
- row estimate — The planner's guess at how many rows a step of a query will produce, used to choose the plan.
Taught in
- Reading An EXPLAIN Plan — PostgreSQL, Indexing & Relational Data Modeling