Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 more

    SQL Query Review: Anti-Patterns and Fixes

    by Saizul Amin

    1

    This skill gives your agent a proven procedure plus scripts that check the facts, so you get the same correct answer every time, with exact fixes instead of vague advice.

    $5

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    SQL Query Review: Anti-Patterns and Fixes

    SQL Query Review: Anti-Patterns and Fixes

    Example session with this skill installed

    Run the SQL Query Review skill on my project and give me a prioritised list of what to fix, with exact changes.

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

    Here is what the SQL Query Review: Anti-Patterns and Fixes skill produced.

    Demo: real, unedited output of the skill's bundled script on the test fixture that ships with its source repo.

    Output

    sql-lint: 3 high, 8 medium, 7 low, 1 info (19 statements checked)
    HIGH    tests/fixtures/sql-query-review/bad.sql:16  null_comparison  '= NULL' is never true (NULL compares as unknown)
            fix: use IS NULL / IS NOT NULL
    HIGH    tests/fixtures/sql-query-review/bad.sql:18  dml_without_where  UPDATE without WHERE touches every row
            fix: add a WHERE clause; for intentional full-table changes batch it (see safe-migrations) or use TRUNCATE
    HIGH    tests/fixtures/sql-query-review/bad.sql:20  dml_without_where  DELETE without WHERE touches every row
            fix: add a WHERE clause; for intentional full-table changes batch it (see safe-migrations) or use TRUNCATE
    MEDIUM  tests/fixtures/sql-query-review/bad.sql:2  select_star  SELECT * reads every column (no index-only scans, breaks when columns change)
            fix: list the columns the caller uses
    MEDIUM  tests/fixtures/sql-query-review/bad.sql:4  function_on_column  DATE(column) in a predicate prevents a plain index on that column from being used
            fix: rewrite as a range on the bare column (col >= x AND col < y), or add an expression/functional index
    MEDIUM  tests/fixtures/sql-query-review/bad.sql:6  function_on_column  LOWER(column) in a predicate prevents a plain index on that column from being used
            fix: rewrite as a range on the bare column (col >= x AND col < y), or add an expression/functional index
    MEDIUM  tests/fixtures/sql-query-review/bad.sql:8  leading_wildcard  LIKE with a leading % cannot use a B-tree index (full scan)
            fix: PostgreSQL: pg_trgm GIN index; MySQL: FULLTEXT index; or anchor the pattern ('abc%')
    MEDIUM  tests/fixtures/sql-query-review/bad.sql:10  or_different_columns  OR across different columns (customer_id, status) usually forces a scan
            fix: split into UNION ALL of index-friendly queries, or index each column (PostgreSQL BitmapOr / MySQL index_merge)
    MEDIUM  tests/fixtures/sql-query-review/bad.sql:14  not_in_subquery  NOT IN (subquery) returns no rows if the subquery yields a NULL, and plans poorly
            fix: use NOT EXISTS (SELECT 1 FROM ... WHERE ...)
    MEDIUM  tests/fixtures/sql-query-review/bad.sql:22  order_by_random  ORDER BY RAND()/RANDOM() sorts the whole result to pick a few rows
            fix: pick random ids in the application, or TABLESAMPLE (PostgreSQL)
    MEDIUM  tests/fixtures/sql-query-review/bad.sql:34  function_on_column  cast created_at::date in a predicate prevents index use
            fix: cast the parameter instead of the column, or index the expression
    LOW     tests/fixtures/sql-query-review/bad.sql:12  or_same_column  OR chain on status: status = a OR status = b ...
            fix: use status IN (a, b, ...)
    LOW     tests/fixtures/sql-query-review/bad.sql:24  large_offset  OFFSET 50000: the database reads and discards every skipped row
            fix: use keyset pagination: WHERE (created_at, id) < (?, ?) ORDER BY created_at DESC, id DESC
    LOW     tests/fixtures/sql-query-review/bad.sql:26  implicit_cast  phone looks like a string column but is compared to a number (pass --schema to confirm)
            fix: compare against a string literal / bind the parameter as a string
    LOW     tests/fixtures/sql-query-review/bad.sql:28  comma_join  implicit comma join: a forgotten join condition silently becomes a cross join
            fix: use explicit JOIN ... ON
    LOW     tests/fixtures/sql-query-review/bad.sql:30  insert_without_columns  INSERT without a column list breaks when a column is added or reordered
            fix: name the columns: INSERT INTO t (a, b) VALUES (...)
    LOW     tests/fixtures/sql-query-review/bad.sql:36  optional_filter  '(col = ? OR ? IS NULL)' catch-all filter: one cached plan cannot use the index well
            fix: build the WHERE clause dynamically with only the filters that are set
    LOW     tests/fixtures/sql-query-review/bad.sql:38  function_on_column  arithmetic on column total in a predicate prevents index use
            fix: move the arithmetic to the other side: col = ? - 1
    INFO    tests/fixtures/sql-query-review/bad.sql:32  union_distinct  UNION removes duplicates (extra sort/hash)
            fix: use UNION ALL when the branches cannot overlap
    

    What you do next

    1. Fix the highest-severity items first.
    2. Ask your agent to apply the fixes it suggests, then run the skill again to confirm.
    3. Keep the skill installed and re-run it whenever the project changes.

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

    About this skill

    Review SQL queries for PostgreSQL and MySQL/MariaDB performance and correctness anti-patterns - SELECT *, functions or casts on indexed columns, leading-wildcard LIKE, OR chains across columns, NOT IN with NULLs, = NULL, UPDATE/DELETE without WHERE, ORDER BY RAND(), deep OFFSET pagination, implicit type casts, comma joins, N+1 query bursts in logs - with a linter for .sql files, query logs and stdin, then rewrite them.

    Who it's for

    Use when the user asks to review, optimise or lint a SQL query or .sql file, asks why a query is slow or not using an index, pastes ORM-generated SQL, or wants a SQL check in CI.

    What's inside

    • Tested, offline Python script(s): sql_lint.py (deterministic results, standard library only unless noted)
    • Reference guides: rewrites.md, anti-patterns.md
    • Step-by-step agent instructions in SKILL.md covering: When to use; When not to use; Workflow; Decision points

    Why it's worth it

    Generic prompts guess. This skill gives your agent a proven procedure plus scripts that check the facts, so you get the same correct answer every time, with exact fixes instead of vague advice. See the real demo below.

    Works with every major AI agent

    Built on the open SKILL.md standard: Claude Code, Codex CLI, Cursor, VS Code Copilot, Gemini CLI, Windsurf and 20+ other agents.

    Requirements

    • Python 3.8+ for the bundled scripts
    • No API keys, no account, runs locally

    Open source: saizul/sql-database-skills on GitHub (MIT licence, by Saizul Amin).

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse All Claude Skills.

    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.

    Frequently Asked Questions

    Review SQL queries for PostgreSQL and MySQL/MariaDB performance and correctness anti-patterns - SELECT *, functions or casts on indexed columns, leading-wildcard LIKE, OR chains across columns, NOT IN with NULLs, = NULL, UPDATE/DELETE without WHERE, ORDER BY RAND(), deep OFFSET pagination, implic...

    This skill uses the open SKILL.md standard. Use it through an MCP-compatible agent connected to Agensi, and check the compatibility information on this page for confirmed agents and required capabilities.

    Connect your AI agent to Agensi through MCP, then ask it to use SQL Query Review: Anti-Patterns and Fixes on your task. Your agent loads the latest approved version each time. Paid skills require a purchase or active subscription. Skill files are not available for download; your licence does not allow you to save, copy or export any part of a skill.