Home›Practice›Query coach
Practice · Query coach

Query coach

Is there anything wrong with this query before I run it?

Paste a query. Add the table definitions and an EXPLAIN plan if you have them. The coach lists what I would look at in a review: what is risky, what will be slow, and small fixes, each with the reason and a link to the lesson behind it. It runs in your browser. Nothing you paste is sent anywhere or stored.

Engine
Try an example:
Add the table definitions (optional)

The CREATE TABLE and CREATE INDEX statements for the tables the query uses. In PostgreSQL, pg_dump --schema-only -t orders; in MySQL, SHOW CREATE TABLE orders. With them, the coach checks indexes, join columns and types.

Add an EXPLAIN plan (optional)

PostgreSQL: the text output of EXPLAIN (ANALYZE, BUFFERS). MySQL: EXPLAIN in table format, or EXPLAIN ANALYZE. ANALYZE runs the query, so use a copy or a replica for writes.

What it checks

The patterns behind the findings

The query

  1. UPDATE or DELETE that changes every row; TRUNCATE
  2. Functions, casts and arithmetic on a filtered column
  3. LIKE with a leading wildcard
  4. OFFSET paging, with a keyset rewrite
  5. NOT IN with a subquery (the NULL trap)
  6. Read, then write: lost updates across statements
  7. Queue reads without SKIP LOCKED
  8. SELECT *, ORDER BY random, comma joins, UNION, HAVING, long IN lists, single-row inserts, retention deletes

With table definitions

  1. No index starting with a filtered column, and the column order of the ones that exist
  2. ORDER BY with LIMIT that has to sort everything first
  3. Join columns without an index
  4. Text columns compared with numbers
  5. No primary key, UUID strings as an InnoDB key, foreign keys without an index
  6. Money in floating point, timestamps without a time zone, redundant indexes

Migrations and plans

  1. CREATE INDEX without CONCURRENTLY, type changes, volatile defaults, constraints without NOT VALID, SET NOT NULL, lock_timeout (PostgreSQL)
  2. ALTER algorithms, metadata locks, MODIFY COLUMN copies (MySQL)
  3. In a plan: full scans with the rows thrown away, estimates far from actual rows, sorts and hashes spilling to disk, nested loops run thousands of times, pages read from disk

It is a set of pattern checks and a light parser, not an optimizer, and it does not see your data. A query with no findings can still be slow; the plan is the real answer. For a line-by-line reading of a PostgreSQL plan, use the annotated EXPLAIN on Reference. Building with an AI assistant? The same checks are a tool in the MCP server.

Connected

Where this shows up

The same mechanism, indexes and plans, concurrent writes and isolation, elsewhere on the site: in real incidents, in measurements, and in designs.

Part 2 of 4 · Practice · 9 pagesAll pages

Can I see it happen? Simulations, an index you build yourself, a real PostgreSQL in your browser, experiments run on real servers, and tools for your own database: a query coach, an EXPLAIN reader, a config checker and a health check.