How do you optimize query performance for massive datasets in a cloud-based warehouse?
Using the provided execution, warehouse, and scan tables, write one PostgreSQL query that efficiently summarizes successful executions during Q1 2025. Include only query fingerprints ranked in the top two by total bytes scanned within each warehouse and month.
warehouse_name, region, month_start, query_fingerprint, execution_count, total_elapsed_ms, total_bytes_scanned, total_rows_scanned, and performance_rank.| Column | Type | Description |
|---|---|---|
| execution_idPK | INT | Unique query execution identifier |
| warehouse_id | INT | Warehouse that executed the query |
| query_fingerprint | VARCHAR(64) | Normalized query identifier |
| started_at | TIMESTAMP | Query start timestamp |
| status | VARCHAR(16) | Execution status |
| elapsed_ms | BIGINT | Elapsed execution time in milliseconds |
| bytes_scanned | BIGINT | Bytes scanned by the execution |
| Column | Type | Description |
|---|---|---|
| warehouse_idPK | INT | Unique warehouse identifier |
| warehouse_name | VARCHAR(80) | Warehouse display name |
| region | VARCHAR(40) | Cloud region |
| cluster_size | VARCHAR(20) | Configured cluster size |
| Column | Type | Description |
|---|---|---|
| scan_idPK | INT | Unique table scan record |
| execution_id | INT | Related query execution |
| table_name | VARCHAR(120) | Table accessed by the execution |
| rows_scanned | BIGINT | Rows scanned from the table |