Explain how you would optimize a SQL query for a high-transactional database.
Assume the query must summarize settled transactions for active accounts during January 2026. Discuss query structure, indexing, execution-plan analysis, and trade-offs relevant to a write-heavy PostgreSQL database.
account_id, account_name, transaction_count, and total_amounttotal_amount descending, then account_id ascending| Column | Type | Description |
|---|---|---|
| account_idPK | INT | Unique account identifier |
| account_name | VARCHAR(100) | Display name of the account |
| is_active | BOOLEAN | Whether the account is currently active |
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Unique transaction identifier |
| account_id | INT | Account associated with the transaction |
| status | VARCHAR(20) | Transaction processing status |
| created_at | TIMESTAMP | Transaction creation timestamp |
| amount | NUMERIC(12,2) | Signed transaction amount |