SQL Optimization Patterns
Diagnose slow SQL queries and fix them with the right indexes and rewrites.
Installation
- Make sure Claude is on your device and in your terminal.
Skills load from
~/.claude/skills/when Claude Code starts up — so you need it on your machine first. If you don't have it yet, install it once with the command below, then runclaudein any terminal to verify.One-time setupnpm i -g @anthropic-ai/claude-codeAlready have it? Skip ahead.
- Paste into Claude Code or into your terminal.
This copies the whole skill folder into
~/.claude/skills/sql-optimization-patterns-wshobson/— the SKILL.md plus any scripts, reference docs, or templates the skill ships with. Safe default: works for every skill.Faster alternative (instruction-only skills)
Skips the clone and grabs only the SKILL.md file. Don't use this if the skill ships Python scripts, reference markdowns, or asset templates — they won't be downloaded and the skill will fail when it tries to load them.
Quick install (SKILL.md only)Sign up to copy - Restart Claude Code.
Quit and reopen Claude Code (or any other agent that loads from
~/.claude/skills/). New skills are picked up on startup. - Just ask Claude.
Skills auto-activate when your request matches the skill's description — no slash command needed. Trigger phrases live in the skill's own frontmatter; you can read them in the “What this skill does” section above.
Prefer to read the source first? Open on GitHub.
When Claude uses it
Teaches Claude to read PostgreSQL EXPLAIN/ANALYZE output, choose the right index type (B-Tree, GIN, GiST, BRIN, partial, covering, expression), and rewrite queries that defeat the planner. Reach for it when debugging a slow query, designing a schema for performance, resolving N+1 problems, or deciding which indexes a table actually needs. Includes pg_stat_statements and pg_stat_user_tables queries for finding slow paths, missing indexes, and unused indexes.
What this skill does
What it does: Gives Claude a working playbook for turning slow SQL into fast SQL, grounded in query-plan analysis and indexing strategy rather than guesswork.
- Reads EXPLAIN and EXPLAIN (ANALYZE, BUFFERS, VERBOSE) output, explaining what Seq Scan, Index Only Scan, and the three join types (Nested Loop, Hash, Merge) mean for performance.
- Picks the right index for the job — B-Tree, Hash, GIN, GiST, BRIN — plus composite (column order matters), partial, expression, covering (INCLUDE), and full-text/JSONB indexes, with CREATE INDEX templates.
- Rewrites query anti-patterns: dropping SELECT *, replacing functions in WHERE with functional indexes, and converting implicit cross-joins into filtered explicit JOINs.
- Surfaces problems with ready-to-run monitoring SQL against pg_stat_statements, pg_stat_user_tables, and pg_stat_user_indexes to find slow, missing, and unused indexes.
- Lists maintenance and pitfall checklists — ANALYZE/VACUUM/REINDEX cadence, over-indexing write costs, leading-wildcard LIKE, and OR conditions that block index use.
Related skills
Multi-Agent Communication Protocol
alirezarezvani
Enable C-suite agents to query each other, coordinate analysis, and prevent communication loops.
Resume Interrupted Claude Work
daymade
Recover context from interrupted Claude sessions and continue work without replaying full history.
Solana Blockchain Query
raphaelmansuy
Query wallet balances, token portfolios, transactions, and NFTs on Solana with USD pricing.
ClickHouse Analytics
arabicapp
Optimize ClickHouse queries and design high-performance analytical databases.