slow query doctor

    1

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

    $5

    Secure checkout via Stripe

    30-day refund guarantee

    Converts to your local currency at checkout

    0 installsSecurity scanned

    Works with the AI tools you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIGitHub CopilotGitHub CopilotGemini CLIGemini CLI+20 more

    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

    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.

    slow-query-doctor.pdf

    PDF · document

    Generated

    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

    Identify bottlenecks in EXPLAIN ANALYZE output for slow production queries.Generate composite index DDL based on predicate selectivity and column order.Rewrite subqueries into joins or unions to optimize optimizer execution paths.Verify query rewrite correctness for edge cases like NULLs and empty sets.

    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.

    ~30 seconds
    1. 1

      Download the ZIP

      Free skills download straight away. Paid skills unlock right after purchase.

    2. 2

      Unzip into your skills folder

      Every agent reads skills from one folder on your machine. Drop the unzipped folder in there.

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

    Listed18 days ago

    What's inside

    Frequently Asked Questions