Rewrite slow SQL queries for optimal performance
Rewrite this SQL query for better performance: Original Query: ```sql [PASTE YOUR SLOW QUERY] ``` Table Information: [DESCRIBE TABLES, SIZES, EXISTING INDEXES] Current Execution Time: [TIME] Target Execution Time: [GOAL] Database: [PostgreSQL/MySQL/SQL Server] Explain the problem areas and provide: 1. Rewritten query with optimizations 2. Explanation of each optimization applied 3. Alternative query approaches if applicable 4. Index recommendations to support the rewrite 5. Query plan analysis (before/after expectations) 6. Caveats or trade-offs of the optimizations
Or press ⌘C to copy
Replace these placeholders with your own content before using the prompt.
[PASTE YOUR SLOW QUERY][TIME][GOAL]