# slow query doctor

> SQL performance specialist that reads execution plans to prescribe exact index DDL and query rewrites.

slow query doctor is a paid AI agent skill on Agensi by Sewing by Marlin's, in Data & Databases. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $5 (one-time purchase)
- Creator: [Sewing by Marlin's](https://www.agensi.io/creators/sewing-by-marlin-s)
- Category: [Data & Databases](https://www.agensi.io/skills/data-databases)
- Version: 1.0
- Last updated: 2026-09-14
- Security: scan passed (2026-09-14); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/slow-query-doctor
- Tags: database, sql, postgresql, performance-tuning, backend

## 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 this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the slow query doctor skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### What specific information do I need to provide for the 'Slow Query Doctor' to work?

You need to provide the raw text output of your database's EXPLAIN or EXPLAIN ANALYZE command along with the query itself; the skill then parses these to identify the specific performance bottlenecks.

### Which database engines are supported by this skill?

The skill is optimized for PostgreSQL, MySQL, and MariaDB, handling engine-specific nuances like index types and optimizer behaviors for these systems.

### How does this skill differ from simply asking a standard LLM to optimize my SQL?

Unlike generic AI prompts, this skill uses a specialized triage logic that prioritizes execution plan analysis over generic best practices, ensuring recommendations actually influence the query optimizer.

### What is included in the purchase of this skill?

You receive the core logic for the 'Slow Query Doctor' skill, ready for deployment within your AI agent, along with documentation on how to input execution plans for the best results.

### Does the skill ensure that query rewrites won't change my data results?

The skill provides a 'correctness gate' check, which includes specific notes on how proposed query rewrites handle edge cases like NULL values and duplicates to ensure data parity.

### How are updates and improvements to the optimization logic delivered?

Updates are handled through the marketplace platform, and you will receive notifications when improved optimization logic or support for additional SQL dialects is released.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
