🗃️Query Plan
Also known as Execution Plan, EXPLAIN, Query Execution Plan
The steps a database picks to answer a query. EXPLAIN shows them.
Think of it like
Think of it like the route a sat nav picks before you drive. You can look at it and see if it is a good one.
Example
Jack's search takes 3 seconds. EXPLAIN shows a scan of all 2 million rows, so he adds an index and the plan switches to a search.
Why it matters
You cannot fix a slow query by guessing. The plan shows where the time goes.
Definition
Example code
sql
EXPLAIN QUERY PLAN SELECT * FROM customers WHERE city = 'London';
-- SCAN customersCommon mistake
Key takeaways
- 1The chosen steps. How the database will answer.
- 2EXPLAIN shows it. Put it before the query.
- 3Look for scans. Full scans of big tables are slow.