0
0
PostgreSQLquery~10 mins

EXPLAIN output reading in PostgreSQL - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - EXPLAIN output reading
Start Query
Run EXPLAIN
Get Query Plan
Read Plan Nodes
Understand Cost & Rows
Interpret Output
Optimize Query if needed
The EXPLAIN command runs a query plan without executing it, showing how PostgreSQL plans to run the query step-by-step.
Execution Sample
PostgreSQL
EXPLAIN SELECT * FROM employees WHERE salary > 50000;
Shows the query plan for selecting employees with salary over 50000.
Execution Table
StepPlan NodeCost (Start..End)Rows EstimatedDescription
1Seq Scan on employees0.00..35.5010Scan all rows in employees table
2Filter--Only rows where salary > 50000
3Output--Return selected rows
4End--Query plan complete
💡 All plan nodes processed; EXPLAIN output fully read.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
Current Plan NodeNoneSeq Scan on employeesFilter appliedOutput preparedComplete
Rows EstimatedUnknown1010 filtered10 output10 final
Key Moments - 3 Insights
Why does the cost show two numbers like 0.00..35.50?
The first number is the startup cost before output begins, the second is the total cost to finish scanning. See execution_table row 1.
What does 'Rows Estimated' mean in the EXPLAIN output?
It is PostgreSQL's guess of how many rows each step will process or output, not the actual count. See execution_table rows 1 and 2.
Why is there a 'Filter' step after the scan?
Because the scan reads all rows, then the filter removes rows not matching the condition. This is shown in execution_table row 2.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the estimated number of rows after the Seq Scan?
A10
B35.50
C0.00
DUnknown
💡 Hint
Check the 'Rows Estimated' column in execution_table row 1.
At which step does the filter condition get applied according to the execution_table?
AStep 3
BStep 1
CStep 2
DStep 4
💡 Hint
Look at the 'Plan Node' column for the 'Filter' entry in execution_table.
If the query had an index scan instead of a sequential scan, which plan node would change in the execution_table?
AFilter
BSeq Scan on employees
COutput
DEnd
💡 Hint
The scan method is shown in the first plan node in execution_table row 1.
Concept Snapshot
EXPLAIN shows how PostgreSQL plans to run a query.
It lists plan nodes like scans, filters, outputs.
Costs show startup and total effort estimates.
Rows estimated are guesses, not actual counts.
Reading EXPLAIN helps find slow parts to optimize.
Full Transcript
The EXPLAIN command in PostgreSQL shows the query plan without running the query. It lists steps like scanning tables, filtering rows, and outputting results. Each step has a cost estimate showing how much work it takes. The plan also estimates how many rows each step will handle. By reading EXPLAIN output, you can understand how the database will execute your query and find ways to make it faster.