What is EXPLAIN?
- SQL course
- Advanced
- Lesson 66/81
- 4 min
See the query plan.
What is EXPLAIN?
EXPLAIN shows how a query will run. It displays the execution plan.
EXPLAIN SELECT * FROM products WHERE price > 100;This query shows the query plan.
All columns are selected from products. WHERE keeps only the rows where price > 100 holds.
What is EXPLAIN? — details
EXPLAIN gives the plan without running the query. It shows which index is used.
EXPLAIN ANALYZE actually runs the query and shows estimated and actual time side by side; it is the first step in finding a slow query.
Practice What is EXPLAIN?
Show the query plan with EXPLAIN SELECT * FROM products WHERE price > 100.
Starter code
-- show plan
EXPLAINSample solution
EXPLAIN SELECT * FROM products WHERE price > 100;Expected output
Seq Scan on products
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What does EXPLAIN show?
- The execution plan Correct answer
- The result
- An error
- An index
Explanation: EXPLAIN shows the execution plan.
2 Add EXPLAIN
____ SELECT * FROM products WHERE price > 100;
EXPLAIN SELECT * FROM products WHERE price > 100;
Explanation: EXPLAIN is the right answer.
3 What is EXPLAIN: match the terms
| Term | Meaning |
|---|---|
EXPLAIN |
show plan |
index |
speed |
Seq scan |
scan |
Index scan |
indexed |