code
Apr 02, 2026CODE-013This SQL query takes 45 seconds on a table with 10M rows. Rewrite it to run in under 1 second. Explain your optimization strategy. ```sql SELECT u.name, u.email, (SELECT COUNT(*) FROM orders o WHERE o.user_id = u.id) as order_count, (SELECT SUM(amount) FROM orders o WHERE o.user_id = u.id) as total_spent, (SELECT MAX(created_at) FROM orders o WHERE o.user_id = u.id) as last_order FROM users u WHERE u.created_at > '2024-01-01' AND (SELECT COUNT(*) FROM orders o WHERE o.user_id = u.id) > 5 ORDER BY total_spent DESC LIMIT 100; ``` Assume standard B-tree indexes on primary keys only. What indexes would you add?
Winner
Claude Opus 4.6
openrouter
9.29
WINNER SCORE
matrix avg: 7.68
10×10 Judgment Matrix · 54 judgments
OPEN DATA
| Judge ↓ / Respondent → | GPT-5.4 | Gemini 3 | Claude Opus 4.6 | Gemini 3.1 Pro | Claude Sonnet 4.6 | MiniMax M2.5 | Grok 4.20 | GPT-OSS-120B | MiMo-V2-Flash | DeepSeek V4 |
|---|---|---|---|---|---|---|---|---|---|---|
| GPT-5.4 | — | 7.8 | 8.6 | 0.5 | 8.4 | · | · | 7.8 | 7.4 | 4.7 |
| Gemini 3 | 9.8 | — | 10.0 | 1.4 | 10.0 | · | · | 9.8 | 9.6 | 8.0 |
| Claude Opus 4.6 | 9.6 | 8.6 | — | 1.0 | 9.2 | · | · | 9.2 | 8.9 | 6.5 |
| Gemini 3.1 Pro | 7.2 | 8.0 | 9.6 | — | 9.6 | · | · | 7.8 | 6.3 | 7.7 |
| Claude Sonnet 4.6 | 9.3 | 8.8 | 9.6 | 1.0 | — | · | · | 9.6 | 9.2 | 7.2 |
| MiniMax M2.5 | 9.2 | 8.6 | 9.0 | 1.0 | 9.0 | — | · | 8.8 | 9.2 | 7.8 |
| Grok 4.20 | 9.0 | · | 9.0 | 0.2 | 8.8 | · | — | · | · | · |
| GPT-OSS-120B | · | 8.6 | · | · | · | · | · | — | 8.6 | · |
| MiMo-V2-Flash | 9.3 | 9.3 | 9.3 | 2.5 | · | · | · | · | — | 7.8 |
| DeepSeek V4 | · | · | · | · | · | · | · | · | · | — |