Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
Claude Skills Maintainers avatar

Sql Query Optimization

  • 196 repo stars
  • Updated July 25, 2026
  • secondsky/claude-skills

Diagnose and fix slow SQL with EXPLAIN analysis, indexing, and N+1 elimination on PostgreSQL or MySQL.

About

An SQL performance skill for PostgreSQL and MySQL that uses EXPLAIN analysis, indexing, and JOIN tuning to fix slow queries. A developer reaches for it when hitting sequential scans, N+1 problems, OFFSET pagination, temp-table spills, or missing indexes that drag down a running database.

  • EXPLAIN analysis
  • Indexing strategy
  • Fixes N+1 problems
  • PostgreSQL and MySQL

Sql Query Optimization by the numbers

  • Data as of Jul 28, 2026 (Skillselion catalog sync)
/plugin marketplace add secondsky/claude-skills
/plugin install sql-query-optimization@claude-skills

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
repo stars196
Last updatedJuly 25, 2026
Repositorysecondsky/claude-skills

What it does

Diagnose and fix slow SQL with EXPLAIN analysis, indexing, and N+1 elimination on PostgreSQL or MySQL.

README.md

SQL Query Optimization Skill

Comprehensive SQL query performance optimization for PostgreSQL and MySQL.

What This Skill Does

Provides systematic optimization patterns for:

  • Debugging slow queries using EXPLAIN ANALYZE
  • Creating optimal indexes (B-Tree, composite, covering, partial)
  • Rewriting inefficient queries (N+1, subqueries, pagination)
  • Monitoring database performance with pg_stat_statements

Auto-Trigger Keywords

This skill activates when Claude detects:

  • slow query, slow queries, query performance
  • sequential scan, seq scan, missing index
  • N+1 problem, N+1 queries
  • EXPLAIN ANALYZE, query plan
  • database optimization, sql optimization
  • index strategy, composite index, covering index
  • connection pooling, prepared statements
  • LIKE performance, full-text search
  • pagination, OFFSET LIMIT
  • cache hit ratio, buffer cache

Prevents 12 Common Errors

  1. Sequential scans on large tables
  2. Missing indexes on foreign keys
  3. N+1 query problems from ORMs
  4. Leading wildcard LIKE queries (%search)
  5. SELECT * in production code
  6. Missing LIMIT on large result sets
  7. Inefficient subqueries vs JOINs
  8. Stale statistics after bulk loads
  9. Missing composite indexes
  10. Wrong index column order
  11. SQL injection from non-parameterized queries
  12. Missing connection pooling

Quick Start

-- 1. Find slow queries
SELECT query, mean_exec_time FROM pg_stat_statements
ORDER BY mean_exec_time DESC LIMIT 10;

-- 2. Analyze query plan
EXPLAIN (ANALYZE, BUFFERS) <your query>;

-- 3. Add missing index
CREATE INDEX CONCURRENTLY idx_table_column ON table_name(column);

Resources

  • 6 Reference Files: Error catalog, EXPLAIN analysis, index strategies, query rewrites, monitoring, workflow
  • 4 SQL Templates: EXPLAIN queries, index examples, query rewrites, monitoring queries
  • Production Tested: PostgreSQL 14-17, MySQL 8.0+

License

MIT

Related skills

Databasesdatabasesanalytics

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.