Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+21 more

    SQL Query Clinic Planner

    2

    Diagnose slow SQL, interpret execution plans, and rewrite queries for better performance and correctness.

    $5

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    SQL Query Clinic Planner

    SQL Query Clinic Planner

    Example session with this skill installed

    Analyze this PostgreSQL query and EXPLAIN output. It is taking 5 seconds to run on a table with 10M rows.
    SELECT * FROM orders WHERE DATE(created_at) = '2023-01-01';
    Plan: Seq Scan on orders (cost=0.00..254.00 rows=50000 width=120) Filter: (date(created_at) = '2023-01-01'::date)

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

    I have analyzed the query and execution plan. The primary bottleneck is a non-sargable predicate preventing index usage.

    Diagnosis

    IssueEvidenceSeverityConfidence
    Index SuppressionFunction DATE() on column created_atP1High
    Full Table ScanSeq Scan in EXPLAIN planP1High

    Correctness Issues

    No correctness issues found. The query logic is sound but inefficient for large datasets.

    Performance Bottlenecks

    The use of the DATE() function on the created_at column makes the expression non-sargable (Search ARGumentable). Even if an index exists on created_at, the database must perform a full sequence scan to apply the function to every row before filtering.

    Index Advice

    • Table: orders
    • Candidate Column: created_at
    • Expected Benefit: Transform Seq Scan to Index Strategy Seek/Scan.
    • Risk: Minimal; standard B-tree index.

    Recommended Rewrite

    Original
    SELECT * FROM orders WHERE DATE(created_at) = '2023-01-01';
    
    Revised
    SELECT * FROM orders 
    WHERE created_at >= '2023-01-01 00:00:00' 
      AND created_at < '2023-01-02 00:00:00';
    
    Why

    By using a range comparison on the raw column, the database can use a standard B-tree index on created_at. This avoids the O(N) cost of the function call per row.

    Validation Checks

    1. Verify if an index exists on created_at. If not, run: CREATE INDEX idx_orders_created_at ON orders(created_at);
    2. Run EXPLAIN ANALYZE with the revised query to confirm an Index Scan or Index Only Scan is used.
    3. Compare Buffers (I/O) between the two versions.

    Next steps

    • Check if there are other queries using functions on created_at.
    • Verify the distribution of data for Jan 1st to ensure index selectivity.
    • Apply the range-based rewrite in the application code.

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

    About this skill

    The problem

    Slow or broken SQL queries often result in guessing games involving trial-and-error indexing and rewrites that may change query semantics. Without an execution plan analysis, developers risk introducing production regressions or technical debt through redundant indexes.

    What it does

    • Analyzes EXPLAIN and EXPLAIN ANALYZE output to identify table scans, join algorithms, and cardinality misestimations.
    • Performs correctness audits for NULL behavior, JOIN conditions, and three-valued logic to fix bug-prone queries.
    • Audits existing indexes for redundancy, overlap, and sargability to minimize write overhead.
    • Proposes semantically equivalent rewrites for correlated subqueries, non-selective predicates, and inefficient pagination.
    • Classifies bottlenecks by severity (P0-P3) based on CPU, I/O, and locking contention evidence.

    Frameworks & tools

    Supports PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, SQLite, Snowflake, BigQuery, and Redshift.

    Why this beats prompting it yourself

    Generic LLM prompts often hallucinate performance gains or suggest destructive changes without considering write costs. This skill follows a strict evidence-based workflow that distinguishes between confirmed bottlenecks and hypotheses, ensuring rewrites preserve original query semantics.

    Use cases

    • Diagnosing a sudden spike in CPU or I/O caused by a specific production query.
    • Refactoring complex legacy CTEs and subqueries for better maintainability and plan stability.
    • Auditing a table's index strategy to remove low-value indexes that slow down inserts.
    • Debugging silent data loss or row multiplication in complex multi-way joins.

    Known limitations

    Requires user-supplied schema or execution plans for high-confidence advice. Cannot execute SQL or access live databases directly.

    Requires manually provided schema, execution plans, or statistics for accurate diagnosis. Does not execute destructive SQL or connect to live production environments.

    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 any payment.

    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 1 month ago

    Permissions

    No special permissions declared or detected

    Listed1 month ago

    What's inside

    Frequently Asked Questions

    The planner analyzes your schema and EXPLAIN outputs to identify bottlenecks like sequential scans or join issues, then provides optimized, semantically identical rewrites to boost performance without changing results.

    Yes, the skill is compatible with all major relational and analytical engines, including PostgreSQL, MySQL, SQL Server, Oracle, Snowflake, BigQuery, and Redshift.

    For the most accurate diagnosis, you should provide the query text, the table schema (DDL), and the execution plan (EXPLAIN ANALYZE) for the specific query you are troubleshooting.

    No, the skill operates on a zero-access model for maximum security; it only analyzes the text and execution plans you provide and never requires direct connection to your production environment.

    This skill uses a structured, evidence-based workflow to categorize bottlenecks by severity (P0-P3), ensuring that suggested index changes or rewrites are based on actual execution data rather than generic best practices.

    Your purchase includes the full SQL Query Clinic Planner skill configuration, detailed documentation on usage, and access to any future updates or dialect improvements released by the developer.

    New in Data & Databases