Analyze and optimize slow database queries with explanations.
Act as a database performance engineer. Optimize this slow query: ```sql [PASTE YOUR SLOW QUERY] ``` Context: - Database: [PostgreSQL / MySQL / SQLite / MongoDB] - Table sizes: [APPROXIMATE ROW COUNTS] - Current execution time: [HOW LONG IT TAKES] - Existing indexes: [LIST OR "UNKNOWN"] - How often this query runs: [FREQUENCY] Provide: 1. **Analysis** — Why is this query slow? (explain the execution plan) 2. **Optimized Query** — Rewritten for performance 3. **Indexes** — Exactly which indexes to create (with CREATE INDEX statements) 4. **Explanation** — Why each change improves performance 5. **Expected improvement** — Rough estimate of speed gain 6. **Trade-offs** — Any downsides to the optimization (write speed, storage) If the query structure itself is the problem, suggest an alternative approach (materialized view, caching, denormalization).
Turn slow queries into fast ones with expert optimization advice.
Diagnose error messages and get step-by-step fix instructions.
Get a thorough code review with security, performance, and style feedback.
Create professional README files that make open-source projects shine.