🏠 Strona Główna
Benchmarki
📊 Wszystkie benchmarki 🦖 Dinozaur v1 🦖 Dinozaur v2 ✅ Aplikacje To-Do List 🎨 Kreatywne wolne strony 🎯 FSACB - Ostateczny pokaz 🌍 Benchmark tłumaczeń
Modele
🏆 Top 10 modeli 🆓 Darmowe modele 📋 Wszystkie modele ⚙️ Kilo Code
Zasoby
💬 Biblioteka promptów 📖 Słownik AI 🔗 Przydatne linki
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.