Your question is Debug and Optimize Slow SQL. Start with the requirements and the two 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.
How would you debug and improve the efficiency of a slow SQL query?
Keep your answer focused on the steps you would take to identify the bottleneck and the changes you would make to improve runtime. Assume the query is used in PostgreSQL.
| Column | Type | Description |
|---|---|---|
| customer_idPK | BIGINT | Unique customer identifier |
| customer_name | VARCHAR(255) | Customer display name |
| is_active | BOOLEAN | Whether the customer is currently active |
| signup_date | DATE | Date the customer account was created |
| Column | Type | Description |
|---|---|---|
| order_idPK | BIGINT | Unique order identifier |
| customer_id | BIGINT | Customer who placed the order |
| order_date | DATE | Date the order was placed |
| total_amount | NUMERIC(12,2) | Order total amount |