
Sql Query Optimization
This handles the mechanical work of SQL optimization: analyzing EXPLAIN plans, spotting missing indexes, and rewriting queries that perform poorly. You'd reach for it when a query is taking too long and you need to understand why, or when you're trying to figure out if an index is actually being used. It covers both PostgreSQL and MySQL, focuses on practical patterns like join optimization and subquery flattening, and includes the buffer analysis you need for real diagnostics. The approach is systematic rather than clever, which is exactly right for performance work. If you're comfortable reading query plans yourself, you might not need it, but it's solid for catching the common mistakes that slow down most applications.
- skills.sh installs
- 527
- GitHub stars
- 379
- last updated
- Aug 21, 2026
Install
$ npx -y skills add aj-geddes/useful-ai-prompts --skill sql-query-optimization --agent claude-codeInstalls into .claude/skills of the current project.
Files
SQL Query Optimization
Table of Contents
Overview
Analyze SQL queries to identify performance bottlenecks and implement optimization techniques. Includes query analysis, indexing strategies, and rewriting patterns for improved performance.
When to Use
- Slow query analysis and tuning
- Query rewriting and refactoring
- Index utilization verification
- Join optimization
- Subquery optimization
- Query plan analysis (EXPLAIN)
- Performance baseline establishment
Quick Start
PostgreSQL:
-- Analyze query plan with execution time
EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON)
SELECT u.id, u.email, COUNT(o.id) as order_count
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
WHERE u.created_at > NOW() - INTERVAL '1 year'
GROUP BY u.id, u.email;
-- Check table statistics
SELECT * FROM pg_stats
WHERE tablename = 'users' AND attname = 'created_at';
Reference Guides
Detailed implementations in the references/ directory:
Sponsors
Details
- Repository
- github.com/aj-geddes/useful-ai-prompts
- Categories
- Backend & APIs, AI & Agent Building, Debugging, Databases
- First seen
- Jun 3, 2026
More from aj-geddes/useful-ai-prompts
All 258- Security Headers Configuration519
- Prometheus Monitoring516
- Frontend Testing514
- Api Error Handling513
- Interaction Design510
- Technical Debt Assessment509
- Webhook Development509
- Api Gateway Configuration508
- React Native App508
- Rate Limiting Implementation507
- Ssl Certificate Management505
- Stakeholder Communication505
- Database Migration Management504
- Test Automation Framework504
- Cicd Pipeline Setup503
- Form Validation503
- Stress Testing503
- Test Data Generation502
- Application Logging501
- Grafana Dashboard501
- Changelog Maintenance500
- Code Documentation500
- Api Reference Documentation499
- Database Performance Debugging499