Loose Ends

Reading EXPLAIN ANALYZE without panic

24 August 2026

A plan looks intimidating, but most slow queries show up in the same few places. Start by running the query with buffers enabled:

EXPLAIN (ANALYZE, BUFFERS) SELECT * FROM orders WHERE customer_id = 42;

First, compare estimated rows with actual rows. A difference of several orders of magnitude means the planner is working with bad statistics, and running ANALYZE on the table is the first thing to try.

Second, look for a sequential scan on a large table that returns few rows. That is usually a missing index, or an index that cannot be used because the query wraps the column in a function.

Third, check the loops value. A node that looks cheap but runs a hundred thousand times is where the time went.