Optimization
- SQL course
- Advanced
- Lesson 81/81
- 6 min
Read a plan with EXPLAIN and improve the query.
Optimization
In this challenge you will read a query plan with EXPLAIN and add an index.
EXPLAIN SELECT * FROM products WHERE price > 100;
-- Seq Scan → CREATE INDEX → Index ScanRead plan, add index.
All columns are selected from products. WHERE keeps only the rows where price > 100 holds.
Practice Optimization
See the plan with EXPLAIN SELECT * FROM products WHERE price > 100.
Starter code
-- optimization
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 Add EXPLAIN
____ SELECT * FROM products WHERE price > 100;
EXPLAIN SELECT * FROM products WHERE price > 100;
Explanation: EXPLAIN is the right answer.
2 How is a Seq Scan fixed?
- Delete the table
- Create a view
- Write a trigger
- Add an index Correct answer
Explanation: A Seq Scan is fixed by adding an index.