🏠 Home
Benchmark Hub
📊 All Benchmarks 🦖 Dinosaur v1 🦖 Dinosaur v2 ✅ To-Do List Applications 🎨 Creative Free Pages 🎯 FSACB - Ultimate Showcase 🌍 Translation Benchmark
Models
🏆 Top 10 Models 🆓 Free Models 📋 All Models ⚙️ Kilo Code
Resources
💬 Prompts Library 📖 AI Glossary 🔗 Useful Links
advanced

SQL Query Refactoring

#sql #database #optimization

Optimize a poorly written SQL query and explain the execution plan changes.

You are a Database Performance Expert. I have a slow-running PostgreSQL query that performs a nested loop join on two large tables (Users and Orders) and filters by a non-indexed column on the Users table. Rewrite this query to maximize performance. Provide the rewritten SQL, and explain the specific changes in the execution plan (e.g., switching from a Nested Loop to a Hash Join or Merge Join). Suggest the specific indexes that should be created to support this query and explain the trade-offs of maintaining those indexes during write-heavy operations.