Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+21 more

    SQL Query Performance Optimizer

    1

    Audit SQL queries, detect N+1 ORM patterns, and optimize database performance based on evidence, not assumptions.

    $6.99

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    SQL Query Performance Optimizer

    SQL Query Performance Optimizer

    Example session with this skill installed

    **Audit this query for a PostgreSQL DB:** SELECT * FROM orders JOIN users ON orders.user_id = users.id WHERE users.email LIKE '%@gmail.com' ORDER BY orders.created_at DESC LIMIT 50 OFFSET 10000;

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

    The audit identified two high-priority issues: a non-selective leading wildcard filter and expensive offset pagination on a large dataset. ## Query Performance Audit | Risk | Issue | Impact | Recommendation | | :--- | :--- | :--- | :--- | | **Critical** | Leading Wildcard (`%@gmail.com`) | Forces a Full Table Scan on `users`. Btree indexes cannot be used for suffix matching. | Use a Reverse String Index or `pg_trgm` GIN index if partial matching is required. | | **High** | Large OFFSET (10,000) | DB must scan and discard 10,000 rows before returning 50. Latency increases linearly with offset. | Implement keyset pagination (e.g., `WHERE created_at < ?`) instead of OFFSET. | | **Medium** | Over-fetching (`SELECT *`) | Retrieves all columns from both tables, increasing IO and memory usage. | Explicitly select only the columns required by the application. | ### Optimized Query Suggestion ```sql -- Keyset pagination approach with specific column selection SELECT o.id, o.amount, o.created_at, u.email FROM orders o INNER JOIN users u ON o.user_id = u.id WHERE u.email LIKE '%@gmail.com' AND o.created_at < '2023-10-01 12:00:00' -- Value from last record of previous page ORDER BY o.created_at DESC LIMIT 50; ``` **Next steps** 1. Run `EXPLAIN ANALYZE` on the original query to confirm the Full Table Scan on the `users` table. 2. Evaluate if the business logic can support an exact match (`=`) or prefix match (`'gmail.com%'`) to enable standard Btree index usage. 3. Replace the OFFSET-based pagination in the application code with a cursor-based approach.

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

    About this skill

    The problem

    Slow database queries and hidden N+1 patterns often go unnoticed until production traffic causes a bottleneck. Manual SQL reviews are time-consuming and prone to missing subtle issues like row multiplication or ineffective composite indexes.

    What it does

    • Identifies N+1 query patterns in ORM and application code with concrete fix recommendations.
    • Analyzes EXPLAIN and EXPLAIN ANALYZE output to detect sequential scans, row explosions, and estimate mismatches.
    • Provides structured index recommendations including column ordering, write trade-offs, and verification steps.
    • Rewrites inefficient SQL to fix correlated subqueries, unnecessary joins, and poor pagination logic.
    • Generates prioritized performance reports that rank risks by severity and frequency.

    Why this beats prompting it yourself

    General-purpose LLMs often hallucinate performance metrics or suggest indexes without considering write overhead. This skill enforces strict evidence-based auditing, ensuring every optimization preserves query semantics and includes a verification plan rather than fabricated benchmarks.

    Use cases

    • Auditing legacy SQL queries for bottlenecks before a database migration.
    • Detecting lazy-loading issues in Django, Hibernate, or Eloquent ORM code.
    • Reviewing execution plans for high-latency production queries to find missing indexes.
    • Refactoring offset-based pagination to keyset/cursor pagination for large datasets.

    Known limitations

    Does not provide actual execution times or performance metrics unless you supply the EXPLAIN output or runtime logs. Does not suggest caching as a primary fix for poor query structure.

    Requires EXPLAIN output for runtime facts. Does not invent performance metrics. Optimization recommendations depend on the accuracy of the provided schema and query context.

    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

    This skill supports all major SQL dialects including PostgreSQL, MySQL, and SQL Server. It is also highly effective at analyzing ORM patterns for popular frameworks like Django, Hibernate, and Eloquent.

    The optimizer focuses on query structure and execution plans; it does not require direct access to your live database. You simply provide the query text or EXPLAIN output for analysis.

    While general models might suggest generic indexes, this skill performs deep-dive analysis of execution plans to identify specific bottlenecks like row multiplication and sequential scans while accounting for write-heavy trade-offs.

    You will receive the optimized SQL code, structured index recommendations, a detailed breakdown of detected N+1 patterns, and a verification plan to test the improvements.

    This skill is designed to work seamlessly with leading AI agents and IDE extensions that support custom skill integration, allowing you to trigger optimizations directly from your coding environment.

    This skill is updated regularly to reflect the latest optimization techniques for modern database engines and to address new patterns found in updated ORM versions.

    New in Data & Databases