PlugWiki

SQL Optimization Patterns Skill (wshobson) for Claude Code

sql-optimization-patterns (from the wshobson/agents collection) helps Claude speed up slow SQL by reading EXPLAIN plans, choosing indexes and rewriting queries.

Installs
20.1K
on skills.sh
Stars
42.1K
on GitHub
Files
1
besides SKILL.md
Updated
Oct 2026
last repo commit

The skill loads when you debug slow queries, design schemas, analyze EXPLAIN plans or add indexes. SKILL.md explains what to look for in EXPLAIN output (Seq Scan, Index Scan, join types, cost, actual time), lists five index types and shows index patterns such as composite, partial, expression, covering and JSONB indexes.

It also lists query rewrites, 8 best practices and 7 pitfalls, such as over-indexing and a function in a WHERE clause. Its monitoring queries are PostgreSQL-specific: slow queries from pg_stat_statements, tables read by sequential scans, and unused indexes.

references/details.md adds five patterns (N+1, pagination, aggregation, subqueries, batch operations) and three advanced techniques (materialized views, partitioning, query hints).

Good for

  • Developers debugging slow queries
  • Engineers designing schemas and indexes
  • Teams fixing N+1 queries and slow pagination

Install sql-optimization-patterns

Claude Code

  1. 1

    Copy this prompt.

    Install the sql-optimization-patterns skill in Claude Code. Run this command:
    
    npx skills add https://github.com/wshobson/agents --skill sql-optimization-patterns
    
    Then check that it loaded and tell me how to use it.
  2. 2

    Paste it into Claude Code. It shows the change and asks before running it.

Requires Node.js.

From its listing on skills.sh. Source.

What's in the skill

When it loads

Master SQL query optimization, indexing strategies, and EXPLAIN analysis to dramatically improve database performance and eliminate slow queries. Use when debugging slow queries, designing database schemas, or optimizing application performance.

Sections in SKILL.md

  1. When to Use This Skill
  2. Core Concepts
  3. 1. Query Execution Plans (EXPLAIN)
  4. 2. Index Strategies
  5. 3. Query Optimization Patterns
  6. Detailed patterns and worked examples
  7. Best Practices
  8. Common Pitfalls
  9. Monitoring Queries

Key facts

Installs on skills.sh
20,117 as of 2026-11-02
GitHub stars (whole repo)
42,081 as of 2026-11-02
License
MIT
Last repo commit
2026-10-30
Files in the skill folder
2 files including SKILL.md

What it includes

  • Read plans: scans, joins, cost and actual time

    PostgreSQL EXPLAIN, EXPLAIN ANALYZE and the BUFFERS, VERBOSE options.

    Runs code · EXPLAIN analysis

  • B-Tree, Hash, GIN, GiST, BRIN and index patterns

    Composite, partial, expression, covering, full-text and JSONB indexes. Warns that column order matters.

    Write · Index strategies

  • Avoid SELECT *, function-free WHERE, better joins

    Bad and good versions of common patterns.

    Query rewrites

  • ANALYZE, VACUUM, VACUUM FULL, REINDEX

    Examples in SKILL.md. It notes VACUUM FULL locks the table.

    Runs code · Maintenance commands

  • Slow queries, missing indexes, unused indexes

    Three PostgreSQL queries over pg_stat_statements and the pg_stat_user views.

    Runs code · Monitoring queries

  • N+1, pagination, aggregates, subqueries, batching

    Five patterns in references/details.md.

    Optimization patterns

  • Materialized views, partitioning, hints

    In references/details.md, including REFRESH MATERIALIZED VIEW and range partitioning.

    Runs code · Advanced techniques

From the official docs

Permissions

Low risk

The skill is guidance only, but its examples include index changes, VACUUM FULL, REINDEX and materialized view refreshes that can lock tables on a live database. Test on a copy before you run anything it suggests.

What it can do

  • Read your data
  • Create and change things
  • Delete things
  • Read-only mode

Watch out for

  • Examples can lock tables on a live database

    SKILL.md shows VACUUM FULL (it notes it locks the table), REINDEX and CREATE INDEX statements, and details.md shows REFRESH MATERIALIZED VIEW and partitioning DDL. Run them on a copy or in a quiet window. github.com

  • Monitoring queries read database statistics

    SKILL.md has queries over pg_stat_statements, pg_stat_user_tables and pg_stat_user_indexes. They need those PostgreSQL views to be available. github.com

Technical details
Scopes
  • database you point Claude at

Questions

What does the sql-optimization-patterns skill do?

It guides Claude through speeding up slow queries: reading EXPLAIN output, choosing indexes, rewriting queries and fixing N+1 problems, mostly with PostgreSQL examples.

How do I install it in Claude Code or Codex?

Use the install box above. The skills CLI command installs only this skill. The wshobson/agents README also documents gh skill install wshobson/agents sql-optimization-patterns, which needs GitHub CLI 2.90 or later, and plugin installs for Claude Code and Codex.

Does it connect to my database?

Nothing in SKILL.md or details.md sets up a database connection, and the skill bundles no scripts. It gives Claude SQL and EXPLAIN patterns to apply.

Is it safe to install?

It bundles no scripts: SKILL.md plus one reference file. The SQL it shows can change a live database. SKILL.md notes that VACUUM FULL locks the table, and it also shows index creation, REINDEX and REFRESH MATERIALIZED VIEW. Our advice: run them on a copy first.

Does it work with MySQL and other databases?

Mostly PostgreSQL. SKILL.md has PostgreSQL EXPLAIN and monitoring queries, and one MySQL index-hint example in details.md. Check syntax against your own database.

Does it need an API key?

No. SKILL.md and details.md name no key or service.

Information

updated Nov 2, 2026

Repository
wshobson/agents
Folder
plugins/developer-essentials/skills/sql-optimization-patterns

wshobson/agentsskills.sh

Sources

Docs, issue trackers and discussions this page is built from.

Show all 3
  1. sql-optimization-patterns SKILL.md · github.com
  2. sql-optimization-patterns details.md · github.com
  3. wshobson/agents README · github.com

Updated Nov 2, 2026.