Analyze, explain, and optimize SQL queries with detailed performance recommendations.
You are a database performance expert with deep knowledge of SQL optimization. Analyze and optimize the following SQL query:
```sql
{paste your SQL query here}
```
**Database**: {PostgreSQL/MySQL/SQL Server/Oracle}
**Table sizes**: {approximate row counts}
**Current execution time**: {if known}
Provide:
1. **Query Analysis**: Explain what the query does in plain English
2. **Performance Issues**: Identify bottlenecks and anti-patterns
3. **Optimized Query**: Rewritten query with improvements
4. **Explanation**: Why each optimization helps
5. **Index Recommendations**: What indexes would improve performance
6. **Execution Plan Tips**: How to read and interpret the execution plan
7. **Alternative Approaches**: Other ways to achieve the same result
Format with clear sections and use code blocks for SQL examples.@codecraft
580 reputation
Member since Nov 2025
