PostgreSQL EXPLAIN visualizer
Type a query and see the plan PostgreSQL chooses for it, as a tree: what each node reads and how, how many rows the planner expected and how many came, and where the time went. This is real PostgreSQL 19.0, compiled to WebAssembly (PGlite), running in this page.
The sample database
A music catalogue, built in your browser when the page starts, then vacuumed and analyzed so the planner has statistics:
| Table | Rows | Columns |
|---|---|---|
| artists | 2,000 | id, name, country |
| albums | 20,000 | id, artist_id, title, released |
| tracks | 100,000 | id, album_id, name, genre, ms, price, plays |
| playlists | 500 | id, name |
| playlist_tracks | 50,000 | playlist_id, position, track_id |
Each table has a primary key on id (playlist_tracks on (playlist_id, position)), and there are indexes on albums(artist_id), tracks(album_id), tracks(genre) and tracks(ms). The view album_lengths sums each album's tracks.
The script that builds it
CREATE TABLE artists (id int PRIMARY KEY, name text NOT NULL, country text); CREATE TABLE albums (id int PRIMARY KEY, artist_id int NOT NULL REFERENCES artists, title text NOT NULL, released date); CREATE TABLE tracks (id int PRIMARY KEY, album_id int NOT NULL REFERENCES albums, name text NOT NULL, genre text, ms int NOT NULL, price numeric(4,2), plays bigint NOT NULL DEFAULT 0); CREATE TABLE playlists (id int PRIMARY KEY, name text NOT NULL); CREATE TABLE playlist_tracks (playlist_id int NOT NULL REFERENCES playlists, position int NOT NULL, track_id int NOT NULL REFERENCES tracks, PRIMARY KEY (playlist_id, position)); INSERT INTO artists SELECT i, 'Artist ' || i, (ARRAY['US','UK','DE','JP','BR','FR','SE','NG'])[1 + i % 8] FROM generate_series(1, 2000) i; INSERT INTO albums SELECT i, 1 + (i * 7) % 2000, 'Album ' || i, DATE '1960-01-01' + (i * 13) % 23000 FROM generate_series(1, 20000) i; INSERT INTO tracks SELECT i, 1 + (i * 31) % 20000, 'Track ' || i, (ARRAY['rock','jazz','pop','pop','pop','classical','metal','blues'])[1 + i % 8], 60000 + (i * 7919) % 480000, (0.69 + (i % 4) * 0.3)::numeric(4,2), (i::bigint * 104729) % 1000000 FROM generate_series(1, 100000) i; INSERT INTO playlists SELECT i, 'Playlist ' || i FROM generate_series(1, 500) i; INSERT INTO playlist_tracks SELECT 1 + i % 500, i / 500, 1 + (i * 37) % 100000 FROM generate_series(0, 49999) i; CREATE INDEX albums_artist ON albums (artist_id); CREATE INDEX tracks_album ON tracks (album_id); CREATE INDEX tracks_genre ON tracks (genre); CREATE INDEX tracks_ms ON tracks (ms); CREATE VIEW album_lengths AS SELECT album_id, sum(ms) AS ms, count(*) AS tracks FROM tracks GROUP BY album_id; VACUUM ANALYZE;
Reading a plan
- Rows flow upwards: each node takes its children's rows and passes its own to its parent. The top node returns the result.
- rows is what came out of the node, per loop; estimated is what the planner expected. A badge marks estimates off by 10× or more: the usual reason for a bad plan.
- A node with loops ran several times, once per row of a Nested Loop's outer side, say; its rows and time are per loop, and the bar shows the total.
- The bar is the node's own share of the time, without its children. Buffers are 8 KB pages: hit in shared memory, read from the files.
- cost is the planner's estimate, startup..total, in units where reading one page sequentially costs 1. It is how the planner chose this plan over others.
PGlite is single-user and single-process: parallel plans (Gather) are never chosen, and times are those of WebAssembly in your browser, slower than a native server. Plans otherwise are what PostgreSQL 19.0 chooses for these tables and statistics.