Query Optimization

EXPLAIN PLAN analysis, index selection, join strategies, and slow query debugging.

48 stars 10 forksSoftware Development Plugin marketplace

Install

Claude Code plugin
/plugin marketplace add sethdford/claude-skills

The repo is a Claude Code plugin marketplace. Run /plugin afterwards to pick the plugin that includes this skill.

skills CLI (Claude Code, Cursor, Codex and more)
npx skills add sethdford/claude-skills --skill query-optimization
Manual install
git clone --depth 1 https://github.com/sethdford/claude-skills.git /tmp/claude-skills
mkdir -p ~/.claude/skills
cp -r /tmp/claude-skills/engineer/database-engineering/skills/query-optimization ~/.claude/skills/query-optimization

Personal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.

From the SKILL.md

# Query Optimization

Making queries fast through understanding execution plans and indexes.

## Context

You are optimizing slow queries. Use EXPLAIN PLAN to understand execution.

## Domain Context

- **Execution Plan**: How database executes query; cost is estimate
- **Sequential Scan**: Reads all rows; slow on large tables
- **Index Scan**: Uses index; much faster if selective
- **Join Strategy**: Nested loop, hash, sort-merge; tradeoffs
- **Cardinality**: Rows filtered at each step

## Instructions

1. **Identify Slow Queries**: Slow logs, application monitoring
2. **Get EXPLAIN PLAN**: Understand how database executes query
3. **Look for Scans**: Sequential scan on large table = problem
4. **Add Indexes**: On columns in WHERE, JOIN, ORDER BY
5. **Verify Join Order**: Database should join most selective first
6. **Rewrite if Needed**: Sometimes different query is faster
7. **Monitor**: Re-check plan after schema changes

## Anti-Patterns

- Optimizing without EXPLAIN PLAN; guessing is unreliable
- Adding indexes for every column; slows writes, wastes storage
- Not updating stats; optimizer makes bad decisions
- Complex queries database can't optimize; rewrite
- Indexes on queries that return too much (unconstrained)

## Further Reading

- PostgreSQL EXPLAIN documentation
- MySQL EXPLAIN documentation
- SQL Antipatterns (Joe Celko), Chapter on queries
Read the full skill on GitHub

Details

Skill name
query-optimization
Path
engineer/database-engineering/skills/query-optimization/SKILL.md
License
MIT
Repo updated
11 March 2026

FAQ

What does the Query Optimization skill do?

EXPLAIN PLAN analysis, index selection, join strategies, and slow query debugging.

How do I install the Query Optimization skill?

Claude Code plugin: /plugin marketplace add sethdford/claude-skills. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.

Is Query Optimization popular?

It lives in sethdford/claude-skills, which has 48 GitHub stars and 10 forks.

Related skills

Browse the most popular Claude skills, all software development skills, or write your own with the skills generator.