Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+22 more

    SQL Query Review

    1

    Diagnose slow SQL queries, optimize composite indexes, and verify performance gains using execution plans.

    $7.99

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    SQL Query Review

    SQL Query Review

    Example session with this skill installed

    The monthly report query in reports.sql is taking 15 seconds. Why is it slow and how do I fix it? Use app.sqlite to check the plan.

    • Read your context and instructions
    • Compiled the sql query review

    The performance bottleneck for the monthly report has been identified. The execution plan confirms a full table scan because the predicate uses a function on the created_at column, which prevents the engine from using the existing index.

    SQL Performance Review

    MetricBeforeAfter
    PlanSCAN TABLE transactionsSEARCH TABLE transactions USING INDEX idx_created_at
    StructureUSE TEMP B-TREE FOR ORDER BY(Removed)
    LogicPredicate: date(created_at) = ?Predicate: created_at >= ? AND created_at < ?

    Analysis

    The original query performed a full table scan because the date() function was applied to the created_at column. This makes the column "un-indexed" for that specific read. Additionally, the engine was forced to create a temporary B-Tree in memory to handle the ORDER BY clause.

    Proposed Fix

    1. Rewrite Predicate: Change the WHERE clause to use a bare column with a range comparison.
    2. Index Optimization: The existing index on created_at is now usable.
    -- REWRITTEN QUERY
    SELECT id, amount, status
    FROM transactions
    WHERE created_at >= '2024-01-01 00:00:00' 
      AND created_at < '2024-02-01 00:00:00'
    ORDER BY created_at DESC;
    

    Next steps

    • Apply the predicate rewrite to the application code.
    • Run sqlreview.py plan app.sqlite reports.sql in the staging environment to verify the SEARCH plan holds with production-scale data.
    • Monitor INSERT latency to ensure the existing index overhead remains acceptable.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Slow queries and unexplained table scans stall production performance and bloat cloud costs. This skill provides a systematic, plan-first methodology for identifying bottlenecks, verifying index efficiency, and proving performance fixes before code is shipped.

    What it does

    • Query plan analysis interprets SQLite and SQL engine execution plans to identify scans, temp b-trees, and materialization.
    • SQL linting flags dialect-agnostic anti-patterns like leading wildcards, function-wrapped predicates, and implicit type conversions.
    • Schema auditing inventories existing indexes to prevent redundant or overlapping index creation.
    • Index optimization recommends composite index column ordering based on equality, range, and sort requirements.
    • Verification reporting generates before-and-after execution plans to prove that a proposed change actually resolves the bottleneck.

    How it works

    1. Analyze the plan using sqlreview.py plan to see how the engine reads the data before forming an opinion.
    2. Scan for defeaters with the lint command to find high-cost patterns like SELECT * or OR across columns.
    3. Audit existing schema via schema and indexes to check column affinity and ensure a new index won't duplicate an existing one.
    4. Apply and verify the smallest possible change, then re-run the plan to confirm the SCAN changed to a SEARCH.

    Frameworks & tools

    This skill uses a Python 3 helper script (sqlreview.py) that relies on the standard library. It is designed for SQLite environments but the optimization logic transfers to other SQL engines.

    Why this beats prompting it yourself

    Generic AI often guesses at missing indexes without looking at the execution plan. This skill forces a "plan-first" workflow, ensuring every recommendation is backed by evidence and verified with a re-run to avoid adding useless write overhead.

    Use cases

    • Debugging a report query that suddenly slowed down from 1 second to 20 seconds.
    • Reviewing a database migration PR to ensure new indexes are correctly ordered for specific predicates.
    • Identifying why a query is ignoring an existing index due to collation or type mismatches.

    Known limitations

    Execution plans and planner rules vary by engine; SQLite plans should not be quoted verbatim for PostgreSQL or MySQL. It cannot explain queries with active placeholders; literal values must be used.

    How to use

    Skills on Agensi run inside your AI agent. Copy the prompt, paste it into your agent, and it connects to Agensi and installs this skill for you. If a payment is needed, your agent shows it to you first.

    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

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scanned

    Verified clean 4 days ago

    • Passed all security checks, Safe to install

    Listed4 days ago

    What's inside

    Frequently Asked Questions