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

ColumnDescription
dateDate
user_nameUser
role_nameRole
warehouse_nameWarehouse
query_typee.g. SELECT, INSERT
execution_statusSUCCESS, FAIL or INCIDENT
execution_secondsTotal elapsed time in seconds
gb_scannedData scanned in GB
partitions_scannedMicro-partitions scanned
partitions_totalTotal micro-partitions available
credits_used_cloud_servicesCloud services credits for this query
statementFull 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;