Queries
The Queries page lists every query Query Doctor has captured for a project and what it found when it costed each one. Queries reach it two ways: the analyzer pushes what it reads from pg_stat_statements on a connected database, and CI runs contribute the queries your tests exercised. The source and branch filters separate the two.
This page covers what the numbers mean. The controls themselves are on screen.
In production
Section titled “In production”The Production column says whether your production database runs the query. Query Doctor reads it from production’s pg_stat_statements only, so a CI run or a staging database never makes a query look like it runs in production.
| Production | Meaning |
|---|---|
| In production | Production’s call count for it went up within the last 7 days |
| No production calls for … | Production lists it, and its call count hasn’t moved for that long |
| Not in production | Production has never listed it. Only CI or a non-production database has seen it |
A database counts as production when its connection’s role is production. A Collector that names no connection never counts, because nothing says which database it read.
pg_stat_statements keeps listing a query after it stops running, so a query production lists reads “No production calls for …” until its count moves. A query whose SQL changed gets a new hash, so its new version reads “Not in production” until production runs the new code.
Status
Section titled “Status”Every query lands in one of seven states.
| Status | Meaning |
|---|---|
| Waiting | Captured, not yet costed |
| Optimizing | Being costed now |
| Improvements available | A set of new indexes or a rewrite of the query lowers its cost |
| No improvement found | Costed, and no candidate index or rewrite it tried beat the current plan |
| Not supported | Outside what the optimizer can cost (see below) |
| Timeout | Costing ran past its limit |
| Error | Costing failed |
In a CI run and in optimize_query, a rewrite doesn’t wait on the index search. When the search runs past its limit, Query Doctor still costs the query’s rewrites against its current plan, and one that lowers the cost by 5% or more puts the query in Improvements available. That result says no index was costed, because none was.
Not supported is a statement about the query, not a failure. Three things trigger it:
- System queries — anything against
pg_*orinformation_schema, andSET/SHOWstatements. - Non-
SELECTqueries. The optimizer costs reads. AnINSERTorUPDATEnever reaches it. SELECTs that read no table, such asSELECT 1. There is nothing to index.
Cost is PostgreSQL’s own plan cost, not milliseconds. It is what the planner used to choose this plan over the alternatives, so it compares two plans for the same query well and says nothing about wall-clock time on its own.
Only three states carry a cost: improvements available, no improvement found, and timeout. A waiting, optimizing, not supported or errored query has none.
Where an improvement exists, the reduction is the drop from the current plan’s cost to the cheapest improvement’s: the suggested indexes in place, or the rewritten query. An index reduction belongs to the whole recommended set, not to any one index in it. See how optimization works.
Why a query ranks where it does
Section titled “Why a query ranks where it does”The default sort is Relevance. Queries with an Improvement come first, the ones Query Doctor can fix, and each group is ordered by the query’s priority, the same number a CI run’s queries and the MCP tools are ordered by. Priority multiplies two things:
- Severity, from 0 to 1: the query’s plan cost on a log scale, and how much of it the best Improvement removes. A query costing under 100 has no severity, whatever its Improvement.
- Traffic: production calls per day, from the last two
pg_stat_statementsreadings of a connected database, on a log scale. A query missing from the newest readings is treated as not running since, so its rate falls the longer it stays away.
A query with no traffic rate, such as one only seen in CI, is weighted as if it ran as often as the median measured query. Two kinds of query get no weight and sort last instead, because they have stopped running: a CI-only query the latest CI run no longer reads, and a query read only once that hasn’t run for over a day. A query Query Doctor hasn’t planned has no severity and sorts last too.
Findings don’t move a query: how many a query has says nothing about how much fixing it is worth.
Filters worth explaining
Section titled “Filters worth explaining”Most filters say what they do. Three don’t:
- Production filters by the Production column. While it’s set, it replaces Source and Branch: Source is whichever of CI or a connected database saw a query last, so a query production runs every minute can sit under CI.
- Exclude targetless queries hides
SELECTs with noFROMclause. They are already reported as not supported, so this mostly removes noise. - Branch applies to queries that arrived from CI. Live queries from a connected database aren’t attached to a branch.