The tools nobody teaches

Pro lesson All levels

Why is this query slow?

What a query plan is, how to read one from the bottom up, and how to find the step that is costing you.

12 min9 hands-on steps

In this lesson you will

  • Understand what a query plan is
  • Read a plan with EXPLAIN, from the bottom up
  • Use EXPLAIN ANALYZE to find the step that blows up, and fix it

Words you'll meet

Query plan
The database's step-by-step recipe for answering your query.
Operator
One step in a plan: read a table, filter, join, group.
EXPLAIN
Shows the plan, with estimated row counts, without running the query.
EXPLAIN ANALYZE
Runs the query and shows the plan with the real rows and time of every step.

The steps

Each step teaches one idea, then has you try it hands-on in your browser, and checks your work.

  1. 1What is a query plan?
  2. 2Your first plan
  3. 3Read it from the bottom
  4. 4It only reads what it needs
  5. 5Filters go down
  6. 6EXPLAIN ANALYZE
  7. 7Find the step that explodes
  8. 8Fix it and compare
  9. 9Challenge

This lesson is part of LearnDE Pro

$12 a month or $100 a year: every lesson, spaced-repetition flashcards, and Learn by teaching. Refund on request within 14 days.