
Sql Query Optimizer
Analyze and rewrite SQL queries for peak database performance
What You Can Do
You can submit any SQL query and receive a thoroughly optimized version with specific performance improvements. The skill analyzes query structure, recommends missing indexes with creation syntax for your database dialect, rewrites inefficient patterns, and provides estimated performance gains. It maintains semantic equivalence while transforming your queries into production-ready code.
Features
transforms slow patterns into optimized equivalents while preserving logic
identifies missing indexes with dialect-specific creation syntax
converts dependent subqueries into efficient JOINs or window functions
restructures multi-table operations for minimal data scanning
improves readability and performance using Common Table Expressions
optimizes for PostgreSQL, MySQL, and SQLite with dialect-specific syntax
provides estimated improvement percentages and explains each optimization
analyzes execution plans to identify bottlenecks and sequential scans
Example Output
Input Query:
SELECT u.id, u.name, (SELECT COUNT(*) FROM orders WHERE orders.user_id = u.id) as order_count
FROM users u
WHERE u.created_at > '2024-01-01';
Optimized Output:
WITH user_orders AS (
SELECT user_id, COUNT(*) as order_count
FROM orders
GROUP BY user_id
)
SELECT u.id, u.name, COALESCE(uo.order_count, 0) as order_count
FROM users u
LEFT JOIN user_orders uo ON u.id = uo.user_id
WHERE u.created_at > '2024-01-01';
Index Recommendation:
CREATE INDEX idx_users_created_at ON users(created_at);
CREATE INDEX idx_orders_user_id ON orders(user_id);
Performance Impact: ~65% faster execution time by eliminating correlated subquery (N+1 problem).
What's Included
- SKILL.md: Complete optimization framework with dialect-specific syntax rules
- Query optimization checklist: 15-point performance review template
- Index recommendation template: Structured format for proposing database indexes
- EXPLAIN plan decoder: Guide to interpreting execution plans across PostgreSQL, MySQL, and SQLite
- Common anti-patterns guide: Quick reference for slow query patterns and their optimized alternatives
Who It's For
- Database Administrators — optimizing production queries and capacity planning
- Backend Engineers — improving application performance and reducing database load
- Data Engineers — tuning ETL and data pipeline queries for efficiency
- DevOps Engineers — troubleshooting slow database performance in CI/CD pipelines
- Performance Specialists — analyzing and benchmarking query optimization efforts
Best For
- Slow query analysis and rewriting for production systems
- Index design and recommendation for large datasets
- Converting legacy SQL patterns to modern, efficient syntax
- Troubleshooting N+1 query problems and correlated subqueries
- Preparing queries for high-traffic environments with strict latency requirements







