SQL EXPLAIN

Ask Postgres to show you the plan before you spend any time guessing.

What & Why

Prefixing any query with EXPLAIN shows the planned execution tree without actually running the query — the fastest way to see how a query will be handled.

See How It Works

BUSINESS QUESTION

Inspect how PostgreSQL filters recent growth events for one event name.

iduser_idevent_namecreated_atproperties
1001101signup2024-01-15 09:12:00+00{"source":"organic"}
1002101activated2024-01-16 14:25:00+00{"step":"workspace"}
1003102signup2024-02-10 11:08:00+00{"source":"paid"}
1004103report_viewed2024-03-12 16:40:00+00{"report":"retention"}
Read a representative EXPLAIN node field by fieldField 1 of 3
growth.events · event_name = 'signup' · created_at >= 2024-01-01
plan fieldrepresentative valuehow to read it
nodeSeq Scan on growth.eventsone scan node for this small fixture
filterevent_name = 'signup' AND created_at >= 2024-01-01predicate attached to the scan
estimated rowsplanner dependentcardinality estimate from statistics
costplanner dependentestimated work, not milliseconds

A small table may use one sequential-scan node; that plan choice is not automatically a problem.

EXAMPLE QUERY
EXPLAIN
SELECT
  user_id,
  event_name,
  created_at
FROM growth.events
WHERE event_name = 'signup'
  AND created_at >= TIMESTAMPTZ '2024-01-01 00:00:00+00';

This lesson's practice is part of Pro.

Advanced business practice

Sign up free to try it on a real business scenario