More screenshots

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 more

    N+1 Query Detector: Find Slow ORM Queries in Logs

    1

    Turn a SQL log into a ranked list of N+1 and duplicate queries with the ORM fix (select_related, includes, JOIN FETCH, selectinload).

    $12

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    About this skill

    The page is slow, the agent guesses, and an index gets added at random. The real cause is usually 200 near-identical queries hiding in the SQL log, and nobody counts them by eye.

    Measured on a real Django page: 203 queries found, one line of fix printed, 203 -> 2 queries and 30.0 ms -> 1.0 ms SQL time after it.

    Query Log Lens ships a deterministic tool (qlens.py, standard-library Python) that your agent runs on the log your app already writes:

    • Reads 8 log formats: Django django.db.backends, Rails development.log, Hibernate show_sql / org.hibernate.SQL (with bind parameters), SQLAlchemy echo, PostgreSQL log_statement / log_min_duration_statement / auto_explain, MySQL general and slow logs, JSON lines. Auto-detected; .gz and .bz2 work.
    • Fingerprints every statement (literals become ?) and groups by request, connection and transaction.
    • Finds N+1 SELECTs, per-row INSERT/UPDATE loops, exact duplicates in one request, scans that examined 100x more rows than they returned, unbounded SELECTs, and requests over a query budget.
    • Prints the fix for your ORM: select_related / prefetch_related, includes, JOIN FETCH / @EntityGraph / @BatchSize, joinedload / selectinload, bulk APIs, and a candidate index only when the log shows a scan.
    • Proves the fix: --compare before.log after.log prints queries, SQL time and findings before and after, and exits 1 on a regression.

    Benchmark (exact commands and commit in the skill):

    LogQueriesResult
    Seeded Django app (real Django 6.1 output)203 -> 2N+1 200x found, fix select_related("author")
    Seeded SQLAlchemy app (real 2.1 output)207 -> 4N+1 200x + duplicate found, fix selectinload(Author.posts)
    pgbadger public PostgreSQL logs (pgbench, 3 files)124,9120 false positives after the transaction-boundary rule; 42,764 queries in 6.7 s

    Honest: the first version flagged the pgbench loops as N+1; repeats split by COMMIT are now ignored. 27 automated tests.

    What it does not do: it does not connect to your database, run EXPLAIN for you, or edit code. Without parameters in the log, N+1 confidence drops to medium. Fix lines guess relation names from table and column names: check custom related_name or join columns. PostgreSQL csvlog and cloud JSON log exports are not supported yet.

    Works in Claude Code, Cursor, Codex CLI, Copilot and any SKILL.md agent.

    Private by design: runs locally on the file you give it, no network, no telemetry, nothing written. Output shows fingerprints, not the literal values from your data.

    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.

    Requires SQL logs with parameters for accuracy. No support for SQL Server, Oracle, or cloud-native JSON logs. Fix suggestions for relation names may need manual verification.

    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

    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 22 days ago

    Software
    Git

    Permissions

    Terminal / Shell
    Read Files
    Network Access
    Listed27 days ago
    Updated21 days ago

    What's inside

    Frequently Asked Questions

    This skill analyzes your SQL logs to identify performance bottlenecks like N+1 queries, duplicate lookups, and row-by-row writes, providing specific ORM code snippets (e.g., for Django or SQLAlchemy) to fix them.

    The skill is a standalone Python 3.9+ script compatible with any AI agent that can execute Python code or handle CLI tools, supporting logs from Django, Rails, Hibernate, SQLAlchemy, Postgres, and MySQL.

    You will receive the core Python analysis engine, documentation for log formatting, and a set of ORM-specific fix templates for popular frameworks like Django and Hibernate.

    Unlike generic LLM prompts, this skill uses deterministic fingerprinting to process thousands of log lines that would exceed a standard context window, ensuring every query is accounted for without hallucinated results.

    Yes, the script includes a '--compare' flag that generates a side-by-side 'receipt' of query counts and execution times to quantitatively prove your code changes improved performance.

    For the most accurate N+1 detection, your logs should include query parameters; however, the tool still identifies structural issues like full-table scans and redundant logic even in simplified logs.

    New in Data & Databases