What problem does it solve?
This skill addresses slow or resource-heavy SQL queries by providing a structured, repeatable process to diagnose performance bottlenecks, propose safer rewrites, and verify both correctness and measurable performance improvements.
Core Features & Use Cases
- Query plan analysis: Guidance on using EXPLAIN, EXPLAIN ANALYZE, and platform-specific plan inspection to identify full table scans, materialization, and costly join patterns.
- Optimization techniques: Practical approaches including CTEs, join restructuring, window functions, predicate pushdown, and index recommendations with database-specific cautions for SQLite, PostgreSQL, and MySQL.
- Verification & benchmarking: Procedures for full-result correctness checks, multi-run timing (cold vs warm cache), and incremental profiling of subqueries or CTEs to validate real gains.
- Use case: Improve a slow report query that times out during peak hours by reworking correlated subqueries into joins or CTEs, adding covering indexes, and selecting the best-performing rewrite via measured benchmarks.
Quick Start
Analyze the slow query with EXPLAIN/EXPLAIN ANALYZE, identify the primary bottleneck, propose two alternative rewrites with index suggestions, and benchmark each version across multiple runs to confirm correctness and performance.