EXPLAIN ANALYZE — Complete Guide
EXPLAIN ANALYZE — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of PostgreSQL Tutorial on Toolliyo Academy.
On this page
PostgreSQL Tutorial · Lesson 27 of 100
EXPLAIN ANALYZE
SQL → Advanced
SQL · 1 — Queries · ~6 min · PostgreSQL — Indexing & Performance
What is this?
EXPLAIN shows the planner chosen path; ANALYZE actually executes the query and prints real row counts and timings. BUFFERS adds cache hit statistics.
Why should you care?
Before shipping a Swiggy report SQL to production, EXPLAIN ANALYZE on PostgresVerse staging catches seq scans that looked fine on 1000 rows.
See it live — copy this example
Run in pgAdmin or psql.
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT)
SELECT o.order_id, c.email
FROM orders o
JOIN customers c ON c.customer_id = o.customer_id
WHERE o.created_at >= now() - interval '1 day';
What happened?
- Planner picks join order and scan types.
- Actual rows vs estimated rows reveal bad stats.
- Buffers shows shared hit/read — disk reads hurt latency.
Practice next
- Run EXPLAIN without ANALYZE first — no execution cost.
- Add ANALYZE on staging copy with realistic data volume.
- Compare estimated rows vs actual in each plan node.
- Use FORMAT JSON and paste into explain.dalibo.com visualizer.
- Compare plans before/after adding a composite index.
Remember
EXPLAIN = plan only; ANALYZE = plan plus execution stats. Mismatch in row estimates signals stats or stats target issues. BUFFERS highlights I/O bottlenecks.
PostgresVerse release gate
PR checklist requires EXPLAIN ANALYZE screenshot for any new JOIN report query.
Outcome: Bad join order caught before merge to main.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!