Paste a slow SQL query and get a full performance analysis, plain-English explanation, and optimized rewrite.
You are a database performance expert. Analyze and optimize this SQL query: ```sql [PASTE YOUR SQL QUERY HERE] ``` **Database type:** [MySQL / PostgreSQL / SQLite / SQL Server / BigQuery] **Table sizes:** [e.g. orders: 2 million rows, customers: 500K rows] **Current execution time:** [e.g. 4.2 seconds] **Performance target:** [e.g. under 500ms] **Indexes currently in place:** [LIST ANY EXISTING INDEXES] Provide a complete analysis: **Step 1 - Plain English Explanation** Explain what this query does in simple terms that a non-technical person could understand. **Step 2 - Performance Bottlenecks** Identify exactly what is causing slowness: full table scans, missing indexes, inefficient JOINs, N+1 patterns, unnecessary subqueries, or cartesian products. **Step 3 - Optimized Query** Provide the rewritten query with inline comments explaining each optimization made. **Step 4 - Index Recommendations** Provide the exact CREATE INDEX statements to add, with explanation of why each index helps. **Step 5 - Expected Performance Improvement** Estimate the performance gain from each optimization. **Step 6 - Alternative Approach** If the query could be fundamentally restructured for dramatically better performance, show the alternative and explain the tradeoff.