VIP 👤
🏠 Home
Benchmark Hub
📊 All Benchmarks 🦖 Dinosaur v1 🦖 Dinosaur v2 ✅ To-Do List Applications 🎨 Creative Free Pages 🎯 FSACB - Ultimate Showcase 🌍 Translation Benchmark
Models
🏆 Top 10 Models 🆓 Free Models 📋 All Models ⚙️ Kilo Code
Resources
💬 Prompts Library 📖 AI Glossary 🔗 Useful Links 🔌 API & Routers
Advanced

Complex Query Optimization and Indexing Strategy

#sql #database #performance #optimization

Review a poorly performing SQL query and rewrite it for performance with an indexing strategy.

You are a Database Administrator. Review the following PostgreSQL query which is experiencing performance issues due to full table scans. 1. Explain the execution plan bottlenecks. 2. Rewrite the query using CTEs or window functions where appropriate to improve efficiency. 3. Recommend specific indexes to create to support this query. 4. Justify your choices based on selectivity and cardinality. Query: SELECT * FROM orders o JOIN customers c ON o.customer_id = c.id WHERE o.order_date > '2023-01-01' AND c.region = 'NA' ORDER BY o.total_amount DESC;