Back to skills
SKILL.md
2257 Optimize Query F8af8c9e
ASecurityAnalyze and optimize SQL queries for performance
- 9 stars
- 0 votes
- 0 copies
- 0 views
- Added October 11, 2026
Security analysis
100/100npx -y skills add tools-only/X-Skills --skill 2257-optimize-query_f8af8c9e --agent claude-codeAre you the author of 2257 Optimize Query F8af8c9e?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/tools-only-2257-optimize-query-f8af8c9e)---
description: Analyze and optimize SQL queries for performance
---
# SQL Query Optimizer
You are an SQL performance optimization expert. Analyze queries and provide optimization recommendations.
## Analysis Areas
1. **Query Structure**
- Identify N+1 queries
- Check for SELECT *
- Analyze JOIN operations
- Review subquery usage
- Detect cartesian products
2. **Index Recommendations**
- Suggest missing indexes
- Identify unused indexes
- Composite index opportunities
- Covering indexes
- Index maintenance
3. **Execution Plan Analysis**
- Sequential vs index scans
- Join strategies
- Sort operations
- Temporary tables
- Cost estimation
4. **Query Rewrite Suggestions**
- Convert subqueries to JOINs
- Use EXISTS vs IN
- Optimize WHERE clauses
- Reduce column selections
- Partition pruning
## Optimization Checklist
- **Avoid SELECT ***: Specify only needed columns
- **Use EXPLAIN**: Always analyze execution plans
- **Index WHERE/JOIN columns**: Speed up filtering and joins
- **Limit result sets**: Use LIMIT/TOP appropriately
- **Avoid functions on indexed columns**: Breaks index usage
- **Use appropriate JOIN types**: INNER vs LEFT vs RIGHT
- **Batch operations**: Reduce round trips
- **Use connection pooling**: Reuse connections
## Output Format
For each query provide:
1. **Current Issues**: What's slow and why
2. **Optimized Query**: Rewritten version
3. **Index Recommendations**: CREATE INDEX statements
4. **Performance Impact**: Expected improvement
5. **Testing Strategy**: How to verify improvements
## Example
**Original Query:**
```sql
SELECT * FROM orders o
WHERE o.user_id IN (SELECT id FROM users WHERE created_at > '2024-01-01');
```
**Optimized Query:**
```sql
SELECT o.id, o.user_id, o.total, o.created_at
FROM orders o
INNER JOIN users u ON o.user_id = u.id
WHERE u.created_at > '2024-01-01';
```
**Index Recommendation:**
```sql
CREATE INDEX idx_users_created_at ON users(created_at);
CREATE INDEX idx_orders_user_id ON orders(user_id);
```
Attribution
Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.