Back to Utils
Snowflake · View
expensive_queries
Queries with an execution time of 60 seconds or longer, including failed queries. The 60-second threshold can be adjusted by recreating the view with a different value for total_elapsed_time.
Source: SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY · Latency: ~45min
| Column | Description |
|---|---|
| date | Date |
| user_name | User |
| role_name | Role |
| warehouse_name | Warehouse |
| query_type | e.g. SELECT, INSERT |
| execution_status | SUCCESS, FAIL or INCIDENT |
| execution_seconds | Total elapsed time in seconds |
| gb_scanned | Data scanned in GB |
| partitions_scanned | Micro-partitions scanned |
| partitions_total | Total micro-partitions available |
| credits_used_cloud_services | Cloud services credits for this query |
| statement | Full query text |
Source code
create_admin_views.sql
create or replace view expensive_queries
comment = 'Queries with execution time >= 60 seconds (source: SNOWFLAKE.ACCOUNT_USAGE)'
as
select start_time::date as date
, user_name
, role_name
, warehouse_name
, query_type
, execution_status
, round(total_elapsed_time / 1000.0, 1) as execution_seconds
, round(bytes_scanned / 1024.0 / 1024 / 1024, 2) as gb_scanned
, partitions_scanned
, partitions_total
, credits_used_cloud_services
, query_text as statement
from snowflake.account_usage.query_history
where total_elapsed_time >= 60000
order by total_elapsed_time desc;