Srikanth Bandaru

Beat the Planner

Race the Postgres query planner, running for real in your tab. It usually wins.

Drag the tables into a join tree and race the plan Postgres picks.

About 10 MB, downloaded only when you press it.

The game needs a desktop browser, because the tables are dragged with a mouse.

Open full page

Real PostgreSQL 18 runs in your browser tab, compiled to WebAssembly by PGlite. You get a query and its tables, drag the tables into a join tree, and race the plan Postgres picked. Both plans really run, and a count of the rows each one touched decides who won. That count is the plan’s work.

Postgres usually wins. On the 110 benchmark queries where its plan finished, 1,965 of the 2,280 trees a player could draw (86%) did at least as much work as Postgres’s plan or didn’t finish. The levels are the exceptions, found by measuring every possible plan offline. On Level 1, Postgres expected 66,902,688,802 rows at its top join. There are 16,698.

The queries and data are the STATS-CEB benchmark’s. The format, playing one component of a system against it, is The Deadlock Empire’s.

Why the race is fair

Your tree runs exactly as you drew it, because of one setting, join_collapse_limit = 1. Postgres still picks each join’s method from its own estimates.

The referee doesn’t use a stopwatch. For each step of a plan it counts the rows the step produced or threw away, multiplies by how often the step ran, and adds the steps up. The same plan on the same data gives the same count on any machine. Time is shown with ≈.

Every run gets 8 seconds. If Postgres’s plan doesn’t finish, the game stops it and shows each join’s estimate beside its true size.

Your tab plans the same way the levels were measured. The page restores the exact planner statistics from that run and never runs ANALYZE, because ANALYZE samples at random and every tab would plan differently.