- 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.
- Heuristic advice, not the planner itself. Always verify with a new EXPLAIN ANALYZE on staging.
- Parses PostgreSQL 12+ and MySQL 8 output. MariaDB, SQL Server, Oracle and SQLite plans aren't supported.
- Suggests B-tree, expression and pg_trgm indexes. Partitioning, BRIN and JSONB/array GIN design are out of scope.
- The schema parser reads CREATE TABLE / CREATE INDEX and inline KEY definitions, not ALTER TABLE ADD INDEX.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before any payment.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by 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 scan
Security scan passed 29 days ago
Permissions
File Scopes
Fully offline. Scripts never import networking or subprocess modules, never read environment variables and never connect to a database. The user runs EXPLAIN and supplies the output. Suggested DDL is written to a file for review and never executed.