All projects

query-not

A PostgreSQL query optimiser that explains slow plans and tests proposed fixes with hypothetical indexes before you change the database.

Solo, Jul 2026

query-not demo

99.5%

lower estimated cost on the demo query, shown before any index was built

4,000,000

orders in the demo table, read in full to return 621 rows

979

checks: 514 unit, 270 against the API, 195 in a real browser

7

kinds of rewrite it writes for you, each checked to return the same rows

Why

Plan visualisers are a solved and crowded space. What nothing closes is the loop: read a plan, guess at an index, build it, wait, measure, repeat. I wanted a tool that proves the fix before you build anything.

It all reduces to one idea. Plan the query against a world, change one thing about that world (a hypothetical index, a setting, a rewritten query), plan it again, and compare the two plans.

How it works

There are three parts. The core is pure analysis with no I/O: it reads a plan, runs thirteen findings rules and compares two plans. The agent is the only part that holds a database connection, and everything it runs goes inside a read-only transaction with a time limit and is always rolled back. The web UI only ever talks to the agent.

Try a hypothetical index

Choose a query plan and an index to test.

HTTPsame codeplansrewritesEXPLAIN, rolled backhistorywhat ifWeb UIReact, ViteCLI and CI gateGitHub ActionCorePure TypeScript, no I/OAgentExpress, the only database connectionPostgres parserlibpg_query, as WebAssemblyStoreSQLite, beside the agentYour PostgreSQLRead-only sessionHypoPGHypothetical indexes

Decisions

Say exactly what was proved

A hypothetical index cannot be run against, so an index proof compares the planner's cost estimates, not time, and every result says so. A suggestion that does not move the plan is shown as unproven instead of as advice.

Hypothetical indexes outlive a rollback

HypoPG keeps its state for the session, not the transaction. A pooled connection handed back with a phantom index would quietly change every later plan, so cleanup always runs, with a savepoint around each EXPLAIN so one failed query cannot stop it.

Rewrites are checked by parsing them again

The parser counts positions in bytes and JavaScript counts in UTF-16 units, so a single é shifts everything after it by one. All splicing is done on bytes, and a rewrite is offered only if parsing it gives exactly the intended tree.

Equivalent means the same rows, checked

A rewrite is called proven only when the schema guarantees it and both versions return the same rows, compared in full within one statement. Under LIMIT, with volatile functions, or above 100,000 rows it refuses to judge.

Regressions are judged on the plan, not the clock

Three identical runs once produced two “the plan got worse” entries, because timing is noisy. History and the CI gate now look only at plan shape and estimated cost, which also keeps a committed baseline meaningful on another machine.

Four layers of safety

Measuring a query means running it, so no single check is trusted: a filter on the text, a read-only transaction, a time limit, and a read-only database role whose presence is reported. The code says plainly which layer is the weakest.

Built with

Query planner
  • PostgreSQL 16
  • HypoPG
  • pg_stat_statements
SQL analysis
  • TypeScript
  • libpg_query (WebAssembly)
Local agent
  • Node.js 22
  • Express
  • SQLite
Frontend
  • React
  • Vite
Testing & CI
  • Playwright
  • Docker
  • GitHub Actions