AI Prompts Library

Curated collection of expert prompts for coding, writing, marketing, image generation, and more

Have a great prompt? Submit it to the library →

Coding

SQL Query Optimizer & Performance Tuner

Optimized for: gpt-4o • TEXT
Analyze and optimize the following SQL query for maximum performance.

**Current Query:**
```sql
[PASTE YOUR SQL QUERY HERE]
```

**Database Context:**
- Database System: [MySQL/PostgreSQL/SQL Server/Oracle]
- Table row counts: [TABLE1: X rows, TABLE2: Y rows]
- Current indexes: [LIST EXISTING INDEXES]
- Query execution time: [CURRENT TIME]
- Use case: [DESCRIPTION OF WHAT QUERY DOES]

**Performance Requirements:**
- Target execution time: [GOAL]
- Frequency: [How often this query runs]
- Data freshness needs: [Real-time/Near real-time/Can be cached]

**Please provide:**

1. **Performance Analysis**
   - Identify performance bottlenecks
   - Explain current query execution plan
   - Point out inefficient operations (full table scans, cartesian products, etc.)

2. **Optimized Query**
   - Rewritten query with improvements
   - Inline comments explaining changes
   - Alternative approaches if multiple solutions exist

3. **Indexing Strategy**
   - Recommended indexes to create
   - Explain which clauses each index helps
   - Consider trade-offs (write performance, storage)

4. **Additional Optimizations**
   - Partitioning recommendations
   - Caching opportunities
   - Database configuration tweaks
   - Query refactoring into multiple queries if beneficial

5. **Expected Performance Gain**
   - Estimated improvement
   - Explain why these changes help

6. **Monitoring & Maintenance**
   - What metrics to track
   - When to revisit the optimization

Database performance tuning, slow query optimization, scaling data-heavy applications

Want Custom Prompts?

Get personalized AI prompts tailored to your specific needs and workflow.

Contact Us