- Home
- Skills
- Data & Databases
- slow query doctor
slow query doctor
SQL performance specialist that reads execution plans to prescribe exact index DDL and query rewrites.
$5
Works with the AI tools you already use
slow query doctor
Example session with this skill installed
My query on the 'orders' table is taking 8 seconds. Here is the EXPLAIN ANALYZE: Seq Scan on orders (cost=0.00..4521.00 rows=250000 width=54). Filter: (status = 'pending' AND created_at > '2023-01-01')
- Read your context and instructions
- Compiled the slow query doctor
- Generated the document
I have analyzed the execution plan. The optimizer is performing a full sequential scan on 250,000 rows because it lacks a path to filter by status or date efficiently.
Database Diagnostic Report
| Component | Details |
|---|---|
| Facts | Table orders, 250k rows, Filter status = 'pending' AND created_at > '2023-01-01' |
| Analysis | Seq Scan dominates cost. The filter is applied post-fetch, discarding most rows. |
| Assumptions | Assumes PostgreSQL 12+. Assumes 'pending' status has high selectivity (< 10% of rows). |
| Prescription | Create a composite index to allow an Index Scan or Index Only Scan. |
Recommended DDL
-- Target: status and created_at predicates
-- Column order: Equality first (status), Range second (created_at)
CREATE INDEX idx_orders_status_created_at
ON orders (status, created_at);
Plan Change Expectation
The optimizer should switch from Seq Scan to Index Scan using idx_orders_status_created_at. This removes the high-cost filter step and significantly reduces I/O by only reading relevant pages.
Correctness & Safety
- Results: Identical. No changes to query logic.
- Write Impact: Low. This is a standard B-Tree index.
- Deployment: Run
CREATE INDEX CONCURRENTLYto avoid locking the table in production.
Next steps
- Run the
CREATE INDEX CONCURRENTLYstatement provided above. - Re-run
EXPLAIN ANALYZEto confirm the optimizer is now using theIndex Scan. - If the plan hasn't changed, run
ANALYZE orders;to refresh stale statistics.
slow-query-doctor.pdf
PDF · document
Example file from a real run - the skill writes it into your workspace.
Connects securely to your tools. The creator never sees your data.
What you get
About this skill
The problem
Slow production queries cause timeouts and degrade user experience. Blindly adding indexes often fails to change the execution plan while increasing write overhead and storage costs.
What it does
- Identifies bottlenecks like SeqScans, sort spills, and row-estimate divergences from EXPLAIN ANALYZE output.
- Generates precise CREATE INDEX DDL with reasoned column ordering and covering-index options.
- Performs query rewrites, such as OR-to-UNION or keyset pagination, specifically to force better optimizer paths.
- Provides a correctness gate to ensure rewrites handle NULLs, duplicates, and edge cases identically to the original.
- Drafts rollback-safe deployment plans and transaction isolation notes for production migrations.
Frameworks & tools
SQL (PostgreSQL, MySQL, MariaDB). Works with standard EXPLAIN and EXPLAIN ANALYZE plan formats.
Why this beats prompting it yourself
Generic LLMs often suggest "best practice" indexes that the optimizer ignores. This skill follows a strict triage ladder, grounding every recommendation in the actual execution plan and explicitly labeling engine-specific assumptions to prevent production surprises.
Use cases
- Fixing long-running reports that are timing out in the web tier.
- Optimizing N+1 query patterns by converting them to efficient batch joins.
- Migrating legacy offset pagination to high-performance keyset pagination.
- Reducing database CPU load by fixing improper join orders and nested loops.
Known limitations
Requires the user to provide the execution plan output. Performance gains cannot be quantified without local before/after measurements.
How to install
Works the same in every agent - Claude, Cursor, Codex, Copilot and 20+ more.
- 1
Download the ZIP
Free skills download straight away. Paid skills unlock right after purchase.
- 2
Unzip into your skills folder
Every agent reads skills from one folder on your machine. Drop the unzipped folder in there.
- 3
Ask your agent to use it
Restart the agent if it was already running. It picks the skill up automatically - no config needed.
Skills folder by agent
Click the path to copy it. Create the folder if it does not exist yet.
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
30-day refund
Not a fit? Get your money back
Trust & safety
Security scanned
Verified clean 18 days ago
- Passed all security checks, Safe to install