Describe your process for optimizing a slow-running SQL query that processes billions of rows at AWS.
Using the provided PostgreSQL tables, produce the optimized query and explain the validation process, including execution plans, filtering, joins, aggregation, and indexing considerations.
account_name, service_name, request_date, successful_requests, p95_latency_ms, successful_bytes, and daily_change.account_name, service_name, and request_date ascending.| Column | Type | Description |
|---|---|---|
| account_idPK | BIGINT | AWS account identifier |
| account_name | VARCHAR(100) | Display name for the account |
| owner_team | VARCHAR(100) | Team responsible for the account |
| active | BOOLEAN | Whether the account is active |
| Column | Type | Description |
|---|---|---|
| service_idPK | BIGINT | AWS service identifier |
| service_name | VARCHAR(100) | AWS service name |
| Column | Type | Description |
|---|---|---|
| request_idPK | BIGINT | Unique API request identifier |
| account_id | BIGINT | Requesting AWS account |
| service_id | BIGINT | AWS service handling the request |
| request_ts | TIMESTAMPTZ | Request timestamp |
| status_code | INT | HTTP-style response status code |
| bytes_sent | BIGINT | Response bytes sent |
| region | VARCHAR(50) | AWS Region for the request |
| latency_ms | NUMERIC(12,3) | Request latency in milliseconds |