skip to content

What does PEV2 show when you paste a PostgreSQL EXPLAIN ANALYZE plan into it, and why is that faster to read than the raw text?

level: juniorimportance: nice to knowfreq 18%

answer

  1. a tree, not indented text
  2. own time, not cumulative time
  3. coloured badges mark the outliers
  4. edge width follows rows
  5. Diagram, Grid, Raw, Query, Stats

basics

~20 s

PEV2 draws a PostgreSQL plan as a node tree, computes each node's own time, rows, cost and buffers, and badges the outliers, so the slow node, a large row misestimate or a wasteful filter stands out at a glance.

solid answer

~50 s

PEV2 is a plan visualiser: you paste the output of `EXPLAIN (ANALYZE, ...)`, as text or JSON, and it rebuilds the tree as boxes joined by edges whose width follows the number of rows. For every node it works out the **exclusive** figures that EXPLAIN does not print. These are the node's own time and cost with its children subtracted, and time is shown as a share of total execution. Badges then mark nodes that are slow, costly, badly estimated, or throwing away most of the rows they read. Around the tree there is a Diagram pane that ranks nodes by time, rows, estimate error, cost, buffers or I/O. There are also a Grid table, the Raw input, the Query text and Stats grouped per table, node type, function and index. From raw text you would do that arithmetic in your head. PEV2 does it for you.

go deeper

for a junior

Recall that PEV2 only parses EXPLAIN output you paste and draws it as a tree with badges. It never touches the database, and ANALYZE is what gives it real times and rows.

for a middle

Explain what it computes that EXPLAIN does not print: exclusive time and cost, rows across loops, the estimate factor and each node's own buffers. Name the Diagram metrics and the highlight options.

for a senior

Show that you triage with it. Start at the strongest badge rather than the top node, and distrust ratios on never-executed or tiny nodes. It finds the problem; the diagnosis is still yours.

for a principal

Treat it as team tooling. A shared visual vocabulary speeds up plan reviews, but decide where plans may be pasted, and keep raw EXPLAIN skills so nobody reasons from colours alone.

## What PEV2 is PEV2 (Postgres EXPLAIN Visualizer 2) is an open-source **Vue 3 component** that turns the output of PostgreSQL's `EXPLAIN` into an interactive picture. It rewrites the earlier *pev* project, which was abandoned. PEV2 does not connect to a database and does not run anything. You give it the plan (and, if you like, the query text and a comment), it **parses** that text in the browser and renders it. Everything it shows was either printed by PostgreSQL or computed from what PostgreSQL printed. So what you feed it matters. A plain `EXPLAIN` contains only the planner's estimates. `EXPLAIN ANALYZE` adds what actually happened: real time, real rows, loop counts and, with buffers, block counts. PEV2 earns its keep on the second kind. ## What it derives that raw EXPLAIN does not print Raw `EXPLAIN ANALYZE` output is an indented list, and its numbers are awkward to compare. Time is **inclusive**: a node's figure contains all of its children. Time and rows are **averages per loop**. PEV2 does the arithmetic a reviewer would otherwise do by hand: | Raw EXPLAIN gives | PEV2 shows | |---|---| | inclusive actual time, per loop | **exclusive** time: times loops, minus the children, as a % of execution | | total cost including the children | the node's own exclusive cost | | actual rows per loop and planned rows | rows across all loops, plus an under- or over-estimate **factor** | | buffer counts that include the children | each node's **own** shared, temp and local blocks | | `Rows Removed by Filter` | the percentage of rows read that the filter threw away | The tree is drawn as boxes, and the **width of each edge** follows the number of rows the child passed up. A fat pipe feeding a small result is visible before you read a single number. ## The badges A node box gets small badges when one of its figures crosses a threshold, and the badge gets stronger as the figure gets worse: - a **clock** ("Slow") when the node's exclusive time is above about 10% of execution time, stronger above 40% and 90%; - a **dollar sign** ("Cost is high") for the same bands of exclusive cost against the plan's largest total cost; - a **thumbs-down** ("Bad estimation for number of rows") when actual and planned rows differ by more than 10x, stronger past 100x and 1000x; - a **filter** icon when a filter removed more than half of the rows the node read, stronger above 90%; - an **exchange** icon when an index-only scan still reports heap fetches, stronger as they approach its row count. A node that never ran is greyed out and labelled "Never executed". ## The views around the tree The Plan tab has a **highlight** switch with four settings: none, duration, rows or cost. It draws a green-to-red bar on every node, scaled to the largest value in the plan. Beside the tree, a **Diagram** pane lists every node as a row with a bar for one chosen metric: time, rows, estimation, cost, buffers or I/O. The other tabs are: 1. **Grid**: the plan as a table, with time, rows, estimate, cost, loops, filter and block columns. 2. **Raw**: the pasted input, untouched. 3. **Query**: the SQL text, if you supplied it. 4. **Stats**: time aggregated per table, per node type, per function and per index. A header strip shows execution and planning time. When the input contains them, it also shows triggers, JIT, serialization and the planner settings. ## What it does not do PEV2 finds problems; it rarely tells you the fix. It offers a few hints. Several hash batches suggest looking at `work_mem` or `hash_mem_multiplier`. Fewer workers launched than planned points at `max_parallel_workers` or `max_parallel_workers_per_gather`. Deciding why a node is slow, and what to change, is still your reading of the plan. PEV2 also cannot invent data the input lacks: without `ANALYZE` there are no actual times, and without `track_io_timing` there are no I/O times. ## Where it runs The same component is available in three forms: - the hosted service at explain.dalibo.com, which saves and shares plans; - a single self-contained `pev2.html` file that works offline; - the `pev2` package, for embedding in your own web application. Which one to use is a data-handling decision. A plan can contain names and literal values from production.

  • What can PEV2 show if you paste a plain EXPLAIN without ANALYZE?
    Only the shape and the estimates. PEV2 checks for actual rows to decide whether a plan was analysed. Without them there are no times, no estimate factors, no row-weighted edges and no buffer data from execution, and it warns that execution time is not available. Exclusive cost and the cost highlight still work, because those come from the planner's numbers.
  • Does PEV2 tell you how to fix the slow node it highlights?
    Mostly not. It points to where the time, the rows or the misestimate is, and it gives a few hints: several hash batches point at `work_mem` or `hash_mem_multiplier`, and missing parallel workers point at the worker limits. Why the node is slow and what to change still depend on your understanding of the plan and the statistics.

  • PEV2 runs the query against the database itself to measure the timings
  • The node with the largest actual time in the text is always the slowest one
  • PEV2 can show actual times from a plain EXPLAIN without ANALYZE
  • Edge width in PEV2 shows the cost flowing from child to parent
  • PEV2 is a server extension you install with CREATE EXTENSION