VIP 👤
🏠 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 🔌 API i routery AI
advanced

Optimize Complex Nested SQL Query

#sql #optimization #database #performance

Improve performance of a slow-running SQL query with multiple joins and subqueries.

Given a PostgreSQL database schema with tables `orders`, `customers`, `products`, and `order_items` containing millions of rows, optimize the following provided SQL query. The query currently takes 45 seconds to execute. Analyze the execution plan, identify bottlenecks such as Cartesian products or inefficient filtering, and rewrite the query using CTEs (Common Table Expressions) and appropriate window functions to reduce runtime to under 2 seconds. Explain your indexing strategy.