- 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
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
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.
Connects securely to your tools. The creator never sees your data.
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 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 buying a skill.
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 2 months ago
Permissions
No special permissions declared or detected
What's inside
Frequently Asked Questions
New in Data & Databases
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Data & Databases.