- Add 60 new agents across all 10 categories (75 -> 135) - Add 95 new plugins with command files (25 -> 120) - Update all agents to use model: opus - Update README with complete plugin/agent tables - Update marketplace.json with all 120 plugins
1.5 KiB
1.5 KiB
/optimize-query - Optimize SQL Query
Analyze and optimize a slow SQL query for better performance.
Steps
- Read the SQL query provided by the user or from a slow query log
- Parse the query to understand: tables, joins, conditions, aggregations, sorting
- Run EXPLAIN ANALYZE to get the current execution plan
- Identify performance bottlenecks: full table scans, nested loops, sort operations
- Check if appropriate indexes exist for WHERE, JOIN, and ORDER BY columns
- Suggest index additions that would improve the query execution plan
- Rewrite the query to eliminate N+1 patterns, unnecessary subqueries, or redundant joins
- Replace correlated subqueries with JOINs or CTEs where beneficial
- Add query hints or optimizer directives if needed for the specific database
- Run EXPLAIN ANALYZE on the optimized query and compare execution times
- Present a before/after comparison: execution plan, estimated rows, actual time
- Provide the optimized query with inline comments explaining each change
Rules
- Always show the EXPLAIN output before and after optimization
- Prefer index-based solutions over query rewrites when possible
- Do not add indexes without considering write performance impact
- Consider the data distribution when recommending indexes
- Test optimizations with production-like data volumes
- Preserve the exact result set; optimization must not change query results
- Warn about queries that may perform differently with larger datasets