D8LooPFocus modeCODE WORKSPACE
Return query_id, query_label, gb_scanned, and cost_rank for the three queries that scanned the most data.
Rank the runs by gb_scanned descending, then keep the top three.
Sample input
| query_id | query_label | gb_scanned |
|---|---|---|
| 1 | daily_active_users | 12 |
| 2 | orders_export | 240 |
| 3 | revenue_by_country | 3 |
| 4 | event_funnel | 85 |
| 5 | late_event_audit | 6 |
| 6 | adhoc_select_star | 180 |
Expected output
| query_id | query_label | gb_scanned | cost_rank |
|---|---|---|---|
| 2 | orders_export | 240 | 1 |
| 6 | adhoc_select_star | 180 | 2 |
| 4 | event_funnel | 85 | 3 |
Constraints
Use RANK() OVER (ORDER BY gb_scanned DESC) as cost_rank. Order by gb_scanned DESC, query_id ASC, and keep the top 3.
Expected skills
Ranking query history by cost and selecting optimization targets.
Run the SQL query to inspect preview rows.