Coding
TEXT
SQL Query Optimizer & Performance Tuner
January 6, 2025
Optimized for:
gpt-4o
Database performance tuning, slow query optimization, scaling data-heavy applications
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
This comprehensive SQL optimization prompt analyzes queries from multiple angles: execution plan, indexing strategy, and database-specific optimizations. It provides not just a faster query, but understanding of why it's faster and how to maintain performance over time. Essential for database-heavy applications where query performance directly impacts user experience.
Submit your own AI prompts to the community. The best ones get featured on TokenCalculator - and credited to you.