VIP 👤
🏠 Home
Benchmark
📊 Tutti i benchmark 🦖 Dinosauro v1 🦖 Dinosauro v2 ✅ App To-Do List 🎨 Pagine libere creative 🎯 FSACB - Ultimate Showcase 🌍 Benchmark traduzione
Modelli
🏆 Top 10 modelli 🆓 Modelli gratuiti 📋 Tutti i modelli ⚙️ Kilo Code
Risorse
💬 Libreria di prompt 📖 Glossario IA 🔗 Link utili 🔌 API e router IA
advanced

Complex Query Optimization

#sql #database #optimization #performance

Optimize a poorly performing SQL query with multiple joins and subqueries.

Analyze the following poorly performing SQL query: 'SELECT * FROM Orders o JOIN Customers c ON o.customer_id = c.id WHERE c.country = 'USA' AND o.order_date > (SELECT MAX(order_date) FROM Orders WHERE customer_id = c.id) - INTERVAL '1 year';'. Identify the potential performance bottlenecks, including the type of join operations, the subquery execution, and the necessity of the wildcard select. Rewrite the query to optimize performance, explaining the specific indexing strategies you would recommend on the tables involved. Justify your changes using database theory concepts such as query execution plans and selectivity.