slow query doctor

    by Sewing by Marlin's

    1

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

    $5

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI Agents 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

    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

    ComponentDetails
    FactsTable orders, 250k rows, Filter status = 'pending' AND created_at > '2023-01-01'
    AnalysisSeq Scan dominates cost. The filter is applied post-fetch, discarding most rows.
    AssumptionsAssumes PostgreSQL 12+. Assumes 'pending' status has high selectivity (< 10% of rows).
    PrescriptionCreate 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 CONCURRENTLY to avoid locking the table in production.

    Next steps

    1. Run the CREATE INDEX CONCURRENTLY statement provided above.
    2. Re-run EXPLAIN ANALYZE to confirm the optimizer is now using the Index Scan.
    3. 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. 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. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 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

    Listed2 months ago

    What's inside

    Frequently Asked Questions

    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.

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

    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.

    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.

    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.

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

    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.