🏠 Startseite
Vergleiche
📊 Alle Benchmarks 🦖 Dinosaurier v1 🦖 Dinosaurier v2 ✅ To-Do-Listen-Apps 🎨 Kreative freie Seiten 🎯 FSACB - Ultimatives Showcase 🌍 Übersetzungs-Benchmark
Modelle
🏆 Top 10 Modelle 🆓 Kostenlose Modelle 📋 Alle Modelle ⚙️ Kilo Code
Ressourcen
💬 Prompt-Bibliothek 📖 KI-Glossar 🔗 Nützliche Links
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.