
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-skillsAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| repo stars | ★ 196 |
|---|---|
| Last updated | July 25, 2026 |
| Repository | secondsky/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
- Sequential scans on large tables
- Missing indexes on foreign keys
- N+1 query problems from ORMs
- Leading wildcard LIKE queries (
%search) - SELECT * in production code
- Missing LIMIT on large result sets
- Inefficient subqueries vs JOINs
- Stale statistics after bulk loads
- Missing composite indexes
- Wrong index column order
- SQL injection from non-parameterized queries
- 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