Back to Utils

Snowflake · View

spilling_queries

Queries that spilled data to remote disk. Remote spill indicates the warehouse is undersized for the query, or the query is scanning more data than necessary.

Source: SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY · Latency: ~45min

ColumnDescription
dateDate
user_nameUser
role_nameRole
warehouse_nameWarehouse
query_typee.g. SELECT, INSERT
execution_secondsTotal elapsed time in seconds
gb_spilled_localData spilled to local disk in GB
gb_spilled_remoteData spilled to remote disk in GB
gb_scannedData scanned in GB
statementFull query text

Source code

create_admin_views.sql
create or replace view spilling_queries
    comment = 'Queries that spilled to remote disk (source: SNOWFLAKE.ACCOUNT_USAGE)'
as
select start_time::date as date
     , user_name
     , role_name
     , warehouse_name
     , query_type
     , round(total_elapsed_time / 1000.0, 1) as execution_seconds
     , round(bytes_spilled_to_local_storage  / 1024.0 / 1024 / 1024, 2) as gb_spilled_local
     , round(bytes_spilled_to_remote_storage / 1024.0 / 1024 / 1024, 2) as gb_spilled_remote
     , round(bytes_scanned / 1024.0 / 1024 / 1024, 2) as gb_scanned
     , query_text as statement
  from snowflake.account_usage.query_history
 where bytes_spilled_to_remote_storage > 0
 order by bytes_spilled_to_remote_storage desc;