Advanced
Complex SQL Optimization Challenge
Analyze a provided slow SQL query scenario and rewrite it for optimal performance on a large dataset.
📝 Prompt-Inhalt
You are a Senior Database Engineer. You are given a schema with tables: Orders (order_id, user_id, order_date, status), Users (user_id, region, signup_date), and Order_Items (item_id, order_id, product_id, quantity, price). The current query attempts to find the top 3 regions by total revenue for orders placed in the last 30 days, but it times out due to the volume of data (100M+ rows). 1. Analyze the potential bottlenecks in a standard JOIN/GROUP BY approach for this specific question. 2. Write an optimized SQL query (standard ANSI SQL) to solve this problem. 3. Explain your indexing strategy to support this query. 4. Discuss how partitioning could further improve performance.