SQL EXPLAIN QUERY PLAN
Show how the database will run a query.
Syntax
EXPLAIN QUERY PLAN SELECT …;
SCAN reads every row; SEARCH … USING INDEX jumps straight to the matches.
Example
Query (on the shop database used in the SQL course)
EXPLAIN QUERY PLAN SELECT * FROM orders WHERE order_id = 10;
Result
| id | parent | notused | detail |
|---|---|---|---|
| 2 | 0 | 0 | SEARCH orders USING INTEGER PRIMARY KEY (rowid=?) |
1 row
Good to know. PostgreSQL: EXPLAIN (or EXPLAIN ANALYZE to also run it and show times).
Related
Learn it step by step in the free lesson Designing a Database, with exercises that check your queries.