How would you approach debugging a slow-performing SQL query for Zomato analytics?
Focus on how you would identify the bottleneck, validate the query plan, and decide what to change first. Keep the answer practical and specific to PostgreSQL behavior.
| Column | Type | Description |
|---|---|---|
| order_idPK | BIGINT | Unique order identifier |
| restaurant_id | BIGINT | Restaurant that received the order |
| customer_id | BIGINT | Customer who placed the order |
| order_status | VARCHAR(20) | Order state such as delivered, cancelled, or pending |
| order_created_at | TIMESTAMP | Order creation timestamp |
| order_value | NUMERIC(10,2) | Order amount |
| Column | Type | Description |
|---|---|---|
| restaurant_idPK | BIGINT | Unique restaurant identifier |
| city_name | VARCHAR(50) | City where the restaurant operates |
| is_active | BOOLEAN | Whether the restaurant is currently active |
| Column | Type | Description |
|---|---|---|
| event_idPK | BIGINT | Unique delivery event identifier |
| order_id | BIGINT | Order associated with the event |
| event_type | VARCHAR(30) | Event type such as picked_up or delivered |
| event_time | TIMESTAMP | Timestamp of the delivery event |