More screenshots

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 more

    Sql Query Optimizer

    0

    Turn a slow SQL query into a faster one: read the execution plan, find the missing index and rewrite it for Postgres, MySQL or SQL Server.

    Free

    6 usesSecurity scanned
    sql-query-optimizer

    sql-query-optimizer

    Example session with this skill installed

    "This query takes 12 seconds on our orders table (2.4M rows): sql SELECT id, title, status FROM orders WHERE EXTRACT(YEAR FROM created_at) = 2024 AND EXTRACT(MONTH FROM created_at) = 3 ORDER BY created_at DESC LIMIT 20; "

    • Read your context and instructions
    • Compiled the sql-query-optimizer

    "Diagnosis: Function-wrapped index column prevents index usage. EXTRACT() on created_at forces Seq Scan of 2.4M rows.

    Anti-pattern: SARGability violation — EXTRACT(YEAR FROM created_at) = 2024 makes the index on created_at unusable.

    Optimized query

    SELECT id, title, status FROM orders
    WHERE created_at >= '2024-03-01' AND created_at < '2024-04-01'
    ORDER BY created_at DESC LIMIT 20;
    

    Index recommendation

    CREATE INDEX idx_orders_created_status ON orders (created_at DESC, status);
    

    Expected improvement: Seq Scan (2.4M rows) → Index Scan (≈12K rows). Verify with:

    EXPLAIN (ANALYZE, BUFFERS) SELECT ...;
    

    Estimated time reduction: 12 seconds → <50ms."

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

    About this skill

    The Problem

    Your production dashboard takes 12 seconds to load. The slow query log shows a SELECT that examines 2.4 million rows to return 200. You added an index on created_at — it didn't help because the query wraps it in EXTRACT(YEAR FROM created_at), which makes the index useless. The query plan shows a Seq Scan, and your DBA is on vacation.

    What You Get

    • Anti-pattern detection — identifies function-on-indexed-column, SELECT *, accidental cross joins, NOT IN with nullable columns, LIKE '%prefix' searches, correlated subqueries, and OFFSET-based pagination on large result sets
    • EXPLAIN plan interpretation — reads PostgreSQL (Seq Scan → Index Scan analysis), MySQL (type: ALL, Using filesort), SQLite (SCAN TABLE), and SQL Server (Key Lookup, Table Scan) execution plans and translates them into actionable recommendations
    • Query rewriting engine — produces optimized queries with inline comments explaining each transformation, covering sargable predicates, JOIN restructuring, NOT EXISTS conversion, and keyset pagination
    • Index recommendation — generates exact CREATE INDEX statements with column order optimized for the identified access patterns, including composite indexes for multi-predicate queries
    • Cross-dialect awareness — handles dialect-specific optimizations (PostgreSQL window functions, MySQL implicit casts, SQLite query planner behavior, SQL Server key lookups)
    • Performance verification — generates EXPLAIN plan comparison scripts to validate that the optimized query actually performs better before deploying

    Why This Beats Prompting It Yourself

    You can paste a slow query and ask "optimize this." The agent will suggest an index or two. But it won't run EXPLAIN to verify the index actually helps, won't check if the query has three other anti-patterns you didn't notice, and won't catch the implicit type cast that makes your VARCHAR index invisible. This skill performs a systematic diagnosis — anti-pattern scan, EXPLAIN analysis, rewrite, verification — the same workflow a DBA follows, not the one-shot suggestion you get from a general-purpose agent.

    Example Session

    You: "This query takes 12 seconds on our orders table (2.4M rows):

    SELECT id, title, status FROM orders
    WHERE EXTRACT(YEAR FROM created_at) = 2024 AND EXTRACT(MONTH FROM created_at) = 3
    ORDER BY created_at DESC LIMIT 20;
    ```"
    
    Agent: "Diagnosis: Function-wrapped index column prevents index usage. EXTRACT() on created_at forces Seq Scan of 2.4M rows.
    
    Anti-pattern: SARGability violation — `EXTRACT(YEAR FROM created_at) = 2024` makes the index on created_at unusable.
    
    Optimized query:
    ```sql
    SELECT id, title, status FROM orders
    WHERE created_at >= '2024-03-01' AND created_at < '2024-04-01'
    ORDER BY created_at DESC LIMIT 20;
    

    Index recommendation:

    CREATE INDEX idx_orders_created_status ON orders (created_at DESC, status);
    

    Expected improvement: Seq Scan (2.4M rows) → Index Scan (≈12K rows). Verify with:

    EXPLAIN (ANALYZE, BUFFERS) SELECT ...;
    

    Estimated time reduction: 12 seconds → <50ms."

    Use Cases

    • Investigating slow queries flagged by production monitoring or slow query logs
    • Code review of SQL in PRs for performance anti-patterns before merge
    • Designing new queries that will run against large tables (100K+ rows)
    • Planning index strategy after analyzing actual query patterns
    • Migrating queries between database engines where dialect-specific behavior differs

    Known Limitations

    Optimization recommendations depend on accurate statistics — stale table statistics can make EXPLAIN plans misleading (run ANALYZE first). Index recommendations assume sufficient disk space and acceptable write overhead; every index slows INSERT/UPDATE/DELETE. The skill analyzes individual queries, not workload-wide query interaction effects. Always validate with EXPLAIN ANALYZE on production-representative data before deploying changes.

    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.

    Optimization recommendations depend on accurate statistics — stale table statistics can make EXPLAIN plans misleading (run ANALYZE first). Index recommendations assume sufficient disk space and acceptable write overhead; every index slows INSERT/UPDATE/DELETE. The skill analyzes individual queries, not workload-wide query interaction effects. Always validate with EXPLAIN ANALYZE on production-repr

    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

    6 uses

    Times used to date

    Free to use

    No account required to browse

    Trust & safety

    Security scan

    Security scan passed 5 months ago

    • Free with an Agensi account

    Permissions

    Terminal / Shell
    Listed5 months ago
    Updated1 month ago

    What's inside

    Frequently Asked Questions

    The skill is designed to work with all popular AI models (like GPT-4, Claude, or Llama) that support custom instructions or skill integration through your preferred agent platform.

    This skill is specialized for PostgreSQL, MySQL, SQLite, and SQL Server, providing dialect-specific optimizations like CTE materialization rules or specialized indexing strategies for each.

    It focuses on deep query-level tuning, meaning it analyzes execution plans and refactors code rather than suggesting server-level hardware upgrades or configuration file changes.

    To get the most accurate results, you should provide the query itself and its execution plan (EXPLAIN output), as this allows the skill to move beyond generic advice to data-driven optimizations.

    Upon purchase, you receive the full skill configuration file and a guide on how to integrate the specialized logic into your existing AI agent workflow.

    Yes, your purchase includes lifetime access to any logic refinements or dialect updates we release as database engines evolve and new optimization techniques emerge.

    New in Data & Databases

    Free