How would you optimize database queries using indices or denormalization?
Write a PostgreSQL query using the supplied customers and orders tables, then explain which indexes or denormalized structures could improve it.
customer_id, customer_name, completed_order_count, and total_completed_amount.| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Unique customer identifier |
| customer_name | VARCHAR(100) | Customer display name |
| Column | Type | Description |
|---|---|---|
| order_idPK | INT | Unique order identifier |
| customer_id | INT | Customer associated with the order |
| order_date | DATE | Date the order was placed |
| status | VARCHAR(20) | Order lifecycle status |
| total_amount | NUMERIC(12,2) | Total monetary value of the order |