- Home
- Skills
- Data & Databases
- sql explain plan doctor
More screenshots
Works with the AI Agents you already use
sql explain plan doctor
Paste a PostgreSQL or MySQL EXPLAIN plan; get the slow node, ranked fixes, schema-checked CREATE INDEX and before/after proof.
$5
sql explain plan doctor
Example session with this skill installed
This orders query takes almost 2 seconds. Here's the EXPLAIN (ANALYZE, BUFFERS) output, the query and our schema. What index do I need?
- Read your context and instructions
- Compiled the sql explain plan
Answer: The Seq Scan on orders takes 81% of the 1,846 ms. Add one composite index: CREATE INDEX CONCURRENTLY idx_orders_status_created_at ON orders (status, created_at DESC);
HIGH full scan: reads 2.0M rows to keep 181k (9.1% selectivity) on status = 'pending' AND created_at >= now() - 7 days
HIGH sort spill: external merge, 17.3 MB on disk for ORDER BY created_at DESC. With LIMIT 50 the new index makes the sort unnecessary
MEDIUM misestimate: expected 5,388 rows, got 181k (34x). Run ANALYZE orders; and consider CREATE STATISTICS ON (status, created_at) FROM orders;
Schema check: existing idx_orders_status(status) starts with the same column (extend it if writes are heavy). idx_orders_customer is a redundant prefix of idx_orders_customer_created
Before → after (plan captured after adding the index on staging):
1,846.0 ms → 0.7 ms (2,818x faster), buffers 41k → 207, seq scans 2 → 0, same 50 rows, 0 HIGH/MEDIUM findings left
Deliverables: terminal diagnosis, report.md, suggested.sql, report.json.
Next steps: create the index on staging (CONCURRENTLY can't run in a transaction), re-run EXPLAIN ANALYZE, then roll it out. Consider dropping the redundant index.
(Real run on the bundled sample plans.)
Connects securely to your tools. The creator never sees your data.
About this skill
Find out why the query is slow and which index fixes it, then prove the fix.
Reads PostgreSQL EXPLAIN (ANALYZE, BUFFERS) text or FORMAT JSON, and MySQL 8 EXPLAIN ANALYZE tree or EXPLAIN FORMAT=JSON. It computes exclusive time per node, so you see where the milliseconds actually go, then ranks findings:
- full scans that throw away most rows
- 10x+ row misestimates
- sorts spilling to disk, multi-batch hashes, lossy bitmaps
- nested loops with a scanning inner side, join-filter waste
- functions and casts on indexed columns, leading-wildcard LIKE
- filesort and temporary tables
- stale visibility maps (heap fetches), JIT overhead, cold reads
You get ready-to-review statements:
CREATE INDEX CONCURRENTLYor MySQL onlineALTER TABLE ... ALGORITHM=INPLACE, LOCK=NONE(column order: equality first, then ORDER BY with LIMIT)- expression and pg_trgm indexes
CREATE STATISTICS- session
work_mem
Each is checked against your existing indexes (from schema DDL) so it never suggests one you already have, and redundant prefix indexes are flagged. Query lint catches OFFSET paging, NOT IN, SELECT * and OR. --after compares runtime, buffers, seq scans and result size to prove the fix.
What's included
SKILL.md, scripts/sqlplan.py, 4 sample plans (PG text before/after, PG JSON, MySQL tree, MySQL JSON) with query and schema files, sample reports, check reference, sources (PostgreSQL and MySQL 8 official docs), tests.
How to use
Skills on Agensi run inside your AI agent. Copy the prompt, paste it into your agent, and it connects to Agensi and installs this skill for you. If a payment is needed, your agent shows it to you first.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill passes our trust checks below.
Security scanned
Passed our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scanned
Verified clean 1 day ago
- Passed all security checks, Safe to install