Last active
June 30, 2025 13:20
-
-
Save Kevinlearynet/aa438cf96edd965b9153022d5a0eef2e to your computer and use it in GitHub Desktop.
Query to find the most expensive and slow queries in a BigQuery data warehouse over the last 7 days
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
job_id, | |
user_email, | |
TIMESTAMP_DIFF(end_time, start_time, MILLISECOND) as job_time_ms, | |
query, | |
ROUND(total_bytes_processed / 1024 / 1024 / 1024, 3) as total_gb_processed, | |
ROUND(total_bytes_billed / 1024 / 1024 / 1024, 3) as total_gb_billed, | |
FORMAT("$%.2f", (total_bytes_billed / 1024 / 1024 / 1024 / 1024) * 6.25) as estimated_cost_usd, | |
total_slot_ms, | |
creation_time | |
FROM `region-us`.INFORMATION_SCHEMA.JOBS_BY_PROJECT | |
WHERE job_type = "QUERY" | |
AND state = "DONE" | |
AND creation_time >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 7 DAY) | |
ORDER BY total_bytes_processed DESC | |
LIMIT 50; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment