Skip to content

SQL Optimization Patterns

Speed up slow SQL queries with indexing advice and EXPLAIN plan analysis

Repository
wshobson/agents
Stars
42,095
Licence
MIT
Files
2 files

What it does

When installed, the agent gets a guide to making database queries faster. It explains how to read PostgreSQL EXPLAIN query plans, which index types to create (B-Tree, GIN, partial, covering and others), and common query rewrites such as avoiding SELECT * and filtering before joining. It also lists routine maintenance commands and queries that find slow statements, unused indexes and tables with missing indexes. The skill is written as reference knowledge; it tells the agent what to look for and suggest, not to run anything by itself.

Great for

  • Backend developers debugging a slow query or endpoint on PostgreSQL
  • Engineers designing a new schema who want indexing guidance
  • Anyone reviewing an ORM or application query that causes N+1 or full table scans

Skip it if

  • Non-PostgreSQL databases such as MySQL or SQL Server, where the EXPLAIN syntax, index types and monitoring views differ and some examples will not apply
  • Running optimization changes directly on a production database without review, since commands like VACUUM FULL lock tables and index changes can affect write performance

Try asking

  • “Why is this query taking 8 seconds? SELECT * FROM orders JOIN users ON ... WHERE created_at > ...”
  • “Review my schema and suggest indexes for a users and orders table on PostgreSQL”
  • “Explain this EXPLAIN ANALYZE output and tell me which step is the bottleneck”
  • “Find unused indexes in my PostgreSQL database and tell me which are safe to drop”
Step-by-step guide: how to use SQL Optimization PatternsInstall, first run, examples, tips and FAQs

Install in 3 steps

  1. 1

    Download the skill

    The ZIP contains the 2 original files, the MIT licence and an attribution note.

    sql-optimization-patterns.zip
  2. 2

    Add it to your agent

    Claude Code (all projects)

    mkdir -p ~/.claude/skills && unzip sql-optimization-patterns.zip -d ~/.claude/skills/

    Claude Code / Agent SDK (this project only)

    mkdir -p .claude/skills && unzip sql-optimization-patterns.zip -d .claude/skills/

    Claude apps (web/desktop): Settings → Capabilities → Skills → Upload skill, and choose the ZIP.

  3. 3

    Ask for the task

    No special command needed — the agent reads the skill's description and loads it when your request matches. Try one of the prompts above.

Get better results

  • Paste the full EXPLAIN (ANALYZE, BUFFERS) output rather than a summary so the agent can identify the real bottleneck
  • Test suggested indexes on a copy of the database first and measure before and after
  • Ask the agent to check the PostgreSQL version and extensions before applying the monitoring queries

What's inside

  • references/details.md
  • SKILL.md

Redistributed unmodified from wshobson/agents under the MIT licence. The assessment was drafted with AI from the skill's files on 2026-10-29. Skills can instruct your agent to run code — read SKILL.md and any scripts before installing.