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.
| id | user_id | event_name | created_at | properties |
|---|---|---|---|---|
| 1001 | 101 | signup | 2024-01-15 09:12:00+00 | {"source":"organic"} |
| 1002 | 101 | activated | 2024-01-16 14:25:00+00 | {"step":"workspace"} |
| 1003 | 102 | signup | 2024-02-10 11:08:00+00 | {"source":"paid"} |
| 1004 | 103 | report_viewed | 2024-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 field | representative value | how to read it |
|---|---|---|
| node | Seq Scan on growth.events | one scan node for this small fixture |
| filter | event_name = 'signup' AND created_at >= 2024-01-01 | predicate attached to the scan |
| estimated rows | planner dependent | cardinality estimate from statistics |
| cost | planner dependent | estimated 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.
Sign up free to try it on a real business scenario