Lesson 3.3

Reading EXPLAIN ANALYZE

EXPLAIN shows the plan; adding ANALYZE runs the query and reports what actually happened.

32mIntermediate9.7k students

Overview

The plan is the evidence

EXPLAIN shows the plan; adding ANALYZE runs the query and reports what actually happened. Guessing at query performance without it is guesswork, and the guess is usually wrong.

Read from the innermost nodes outward — those run first — and find where the time accumulates. Note that costs shown are cumulative, so the interesting number is the node exclusive time.

A sequential scan is not automatically bad; on a small table it is the fastest option. The red flag is a sequential scan over a large table where you expected an index, which usually means the index cannot serve the predicate as written.

In this lesson you will:

  • Read a plan from the inside out
  • Compare estimated and actual rows
  • Spot the node that dominates the time

Resources

Previous Lesson
Next Lesson
Reading EXPLAIN ANALYZE — PostgreSQL for Application Developers — Vertex