SQL Optimizer
CautionAnalyzes SQL queries for performance issues, rewrites slow queries, recommends index strategies, and explains execution plans across PostgreSQL, MySQL, and SQLite.
Install
Claude Code
Copy the SKILL.md file to your project's .claude/skills/ directory About This Skill
SQL Optimizer analyzes your queries and database schema to find performance bottlenecks and suggest improvements. It understands execution plans, index selection, join strategies, and query planner behavior across PostgreSQL, MySQL, and SQLite.
How It Works
- Query analysis — Parses SQL to identify anti-patterns like SELECT *, implicit type casts, and missing WHERE clauses
- Execution plan review — Reads EXPLAIN/EXPLAIN ANALYZE output to find sequential scans, hash joins, and sort operations
- Index recommendation — Suggests indexes based on WHERE, JOIN, ORDER BY, and GROUP BY columns
- Query rewrite — Transforms slow patterns: N+1 to JOINs, correlated subqueries to CTEs, DISTINCT to EXISTS
- Benchmark comparison — Provides before/after cost estimates from execution plans
Best For
- Optimizing slow API endpoints caused by inefficient queries
- Database performance audits before scaling infrastructure
- Reviewing ORM-generated queries for hidden performance issues
- Learning SQL optimization patterns through explained rewrites
Database Support
Full support for PostgreSQL (including JSONB, array operations, and partial indexes), MySQL/MariaDB, SQLite, and basic support for SQL Server and Oracle.
Use Cases
- Analyze EXPLAIN output and identify missing indexes
- Rewrite N+1 queries into efficient JOINs or subqueries
- Optimize complex aggregation queries with window functions
- Convert correlated subqueries to lateral joins or CTEs
- Recommend composite index strategies for multi-column filters
Pros & Cons
Pros
- + Explains execution plans in plain language
- + Handles PostgreSQL-specific features like JSONB and partial indexes
- + Provides before/after cost comparison for rewrites
- + Catches ORM-generated query anti-patterns
Cons
- - Execution plan analysis requires actual EXPLAIN output from the database
- - Cannot account for data distribution without table statistics
Related Skills
Schema Designer
VerifiedDesigns relational and NoSQL database schemas with proper normalization, indexing strategies, migration scripts, and entity-relationship diagrams.
Data Pipeline
CautionDesigns and implements ETL/ELT data pipelines using Python, SQL, and orchestration tools like Airflow, dbt, and Prefect for batch and streaming workflows.
Stay Updated on Agent Skills
Get weekly curated skills + safety alerts
每周精选 Skills + 安全预警