Schemas:

ACCOUNT_USAGE

QUERY_METERING_HISTORY view

The query metering history view (QUERY_METERING_HISTORY) returns per-query credit usage for queries run on adaptive warehouses within the last 365 days (1 year). This view is available in the ACCOUNT_USAGE schema. Coming soon: a corresponding ORGANIZATION_USAGE view for organization-wide reporting (latency may be up to 24 hours).

Use this view to monitor price and performance at the query level. For aggregated warehouse credit usage, see WAREHOUSE_METERING_HISTORY view.

Columns

Several columns can be NULL until the query completes. For details, see usage notes.

Column nameData typeDescription
QUERY_IDVARCHARInternal/system-generated identifier for the SQL statement.
WAREHOUSE_IDNUMBERInternal/system-generated identifier for the warehouse that the query was executed on.
WAREHOUSE_NAMEVARCHARName of the warehouse that the query executed on.
QUERY_METERING_HOURTIMESTAMP_LTZStart of the metering hour window this row represents.
QUERY_START_TIMETIMESTAMP_LTZTime when query execution started (in the local time zone).
QUERY_END_TIMETIMESTAMP_LTZTime when query execution ended (in the local time zone). NULL until the query completes; see usage notes.
PARENT_QUERY_IDVARCHARQuery ID of the parent query. NULL until the query completes, or NULL if the query does not have a parent.
ROOT_QUERY_IDVARCHARQuery ID of the topmost query in the chain. NULL until the query completes, or NULL if the query is a standalone query (not part of a chain).
USER_IDNUMBERInternal/system-generated identifier for the user who issued the query.
USER_NAMEVARCHARUser who issued the query.
ROLE_NAMEVARCHARRole that issued the query.
QUERY_HASHVARCHARThe hash value computed based on the canonicalized SQL text.
QUERY_PARAMETERIZED_HASHVARCHARThe hash value computed based on the parameterized query.
QUERY_TAGVARCHARQuery tag set for this statement through the QUERY_TAG session parameter.
CREDITS_USED_COMPUTENUMBERNumber of credits used for compute for this query in this metering hour.
CREDITS_USED_CLOUD_SERVICESNUMBERNumber of credits used for cloud services for this query in this metering hour.
CREDITS_USEDNUMBERTotal number of credits used for this query in this metering hour.

Usage notes

  • This view displays results for any role granted the USAGE_VIEWER or GOVERNANCE_VIEWER database role.
  • Latency for the view may be up to 1 hour. Charges accrued by a job may take up to 1 hour to appear in the view.
  • This view includes per-query credit usage for queries run on adaptive warehouses.

  • Each query can have multiple rows in this view: one row per metering hour while the query runs. Use QUERY_METERING_HOUR to identify the metering window for each row.

  • While a query is running, each metering-hour row is refreshed in-place with updated credit usage. When the query finishes, the final row for that metering hour is written and no longer changes.

  • Until a query completes, the following columns can be NULL on in-progress rows: WAREHOUSE_NAME, QUERY_START_TIME, QUERY_END_TIME, PARENT_QUERY_ID, ROOT_QUERY_ID, USER_NAME, ROLE_NAME, QUERY_HASH, QUERY_PARAMETERIZED_HASH, and QUERY_TAG. After the query completes, PARENT_QUERY_ID and ROOT_QUERY_ID remain NULL when the query has no parent or is not part of a chain.

  • For aggregated warehouse credit usage (all warehouse types), use WAREHOUSE_METERING_HISTORY view.

  • For per-query compute cost attribution on standard warehouses, use QUERY_ATTRIBUTION_HISTORY view.

Data freshness examples

Query runs for one hour

A query runs for an entire hour. The view contains one row for that metering hour. While the query is running, that row is updated in-place with current credit usage. When the query finishes at the end of the hour, that row is final.

Query runs for multiple hours

A query runs across multiple hours. The view contains one row per metering hour (QUERY_METERING_HOUR). Each row follows the same in-place refresh behavior while the query is still running.

Examples

The following example filters on warehouse_name and query_start_time, which excludes in-progress rows where those columns are still NULL.

Return total credits used per query for an adaptive warehouse over the past 7 days:

SELECT
  query_id,
  SUM(credits_used) AS total_credits_used,
  SUM(credits_used_compute) AS total_credits_used_compute,
  SUM(credits_used_cloud_services) AS total_credits_used_cloud_services
FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_METERING_HISTORY
WHERE warehouse_name = 'my_adaptive_wh'
  AND query_start_time >= DATEADD(day, -7, CURRENT_DATE())
GROUP BY query_id
ORDER BY total_credits_used DESC;