Skip to content
Back to skills

2257 Optimize Query 80770c2b

ASecurity

Analyze and optimize SQL queries for performance

  • 9 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 11, 2026
testingsqltestingperformance

Security analysis

A100/100

Scanned October 11, 2026

npx -y skills add tools-only/X-Skills --skill 2257-optimize-query_80770c2b --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 2257 Optimize Query 80770c2b?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 2257 Optimize Query 80770c2b
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tools-only-2257-optimize-query-80770c2b/badge)](https://www.skillsdirectory.com/skills/tools-only-2257-optimize-query-80770c2b)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

SKILL.md
---
name: optimize-query
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

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.