🏠 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
Advanced

Complex Query Optimization

#sql #performance-tuning #database #query-optimization

Optimize a slow, complex SQL query involving multiple joins and subqueries.

Given a PostgreSQL database schema with tables for users, orders, order_items, products, and reviews, optimize the following query: 'SELECT u.name, COUNT(o.id) as total_orders, SUM(oi.quantity * p.price) as total_spent FROM users u LEFT JOIN orders o ON u.id = o.user_id LEFT JOIN order_items oi ON o.id = oi.order_id LEFT JOIN products p ON oi.product_id = p.id WHERE o.created_at > '2023-01-01' GROUP BY u.name HAVING SUM(oi.quantity * p.price) > 1000'. Explain the execution plan bottlenecks, suggest appropriate indexing strategies, and rewrite the query using CTEs (Common Table Expressions) or window functions to improve performance by an estimated factor of 10x.