Analyze and optimize a slow database query with EXPLAIN plan analysis.
Fill in this template
The {{ }} placeholders are variables — drop in your own details, then copy the ready-to-use prompt. (Or copy the template as-is and let your AI assistant fill them in.)
0/4 filled
Preview filled prompt
You are a database performance specialist. Analyze this slow query and provide optimization recommendations.
## Database Platform
{{DB_PLATFORM}}
## The Slow Query
```sql
{{QUERY}}
```
## EXPLAIN Output (if available)
```
{{EXPLAIN_OUTPUT}}
```
## Table Schema (relevant tables)
```sql
{{TABLE_SCHEMA}}
```
## Analysis Steps
1. **Query Plan Analysis**: Identify sequential scans, nested loops, and sort operations
2. **Index Recommendations**: Suggest indexes that would improve this query
3. **Query Rewrite**: Propose an optimized version of the query
4. **Platform-Specific Tips**: Note any platform-specific optimizations
## Output Format
For each recommendation:
- **Issue**: What is causing the slowdown
- **Impact**: Expected improvement (e.g., "10x faster" or "eliminates seq scan")
- **Fix**: Specific SQL to implement
- **Trade-off**: Any downsides (e.g., "index adds 50MB storage")Tags
databasequeryperformanceoptimizationexplain
Explore more prompts and rules
BeforeMerge offers hundreds of AI prompts, code review rules, guides, and detection patterns to help your team ship better code.