Your question is Optimizing Slow Queries. Start with the requirements and the three tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Describe how you would approach optimizing a slow-running query in a large relational database.
Use the supplied PostgreSQL schema and data to demonstrate an optimized version of the query. Your answer should address diagnosis, execution plans, filtering, joins, aggregation, indexes, statistics, and verification.
customer_id, customer_name, and total_valuetotal_value descending, then customer_id ascending| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Customer identifier |
| customer_name | VARCHAR(100) | Customer display name |
| region | VARCHAR(50) | Customer region |
| is_active | BOOLEAN | Whether the customer is active |
| Column | Type | Description |
|---|---|---|
| order_idPK | INT | Order identifier |
| customer_id | INT | Customer who placed the order |
| order_date | DATE | Order creation date |
| status | VARCHAR(20) | Order processing status |
| Column | Type | Description |
|---|---|---|
| order_item_idPK | INT | Order-item identifier |
| order_id | INT | Related order identifier |
| quantity | INT | Number of units |
| unit_price | DECIMAL(10,2) | Price per unit |