0PricingLogin
SQL Academy · Lesson

Reading EXPLAIN and EXPLAIN ANALYZE

Read the plan tree, understand cost vs actual time, and pick out the heavy nodes.

Why EXPLAIN?

EXPLAIN shows the planner's strategy for executing a query — without running it. EXPLAIN ANALYZE runs the query AND shows actual timings.

Basic EXPLAIN

Show the estimated plan:

EXPLAIN SELECT * FROM orders WHERE user_id = 42;
--                            QUERY PLAN
-- ---------------------------------------------------------------
-- Index Scan using orders_user_id_idx on orders
--   (cost=0.43..8.45 rows=5 width=120)
--   Index Cond: (user_id = 42)

All lessons in this course

  1. Reading EXPLAIN and EXPLAIN ANALYZE
  2. Sequential Scans vs Index Scans
  3. Hash Join vs Merge Join vs Nested Loop
  4. Identifying and Fixing Slow Queries
← Back to SQL Academy