- Schemas:
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 name | Data type | Description |
|---|---|---|
| QUERY_ID | VARCHAR | Internal/system-generated identifier for the SQL statement. |
| WAREHOUSE_ID | NUMBER | Internal/system-generated identifier for the warehouse that the query was executed on. |
| WAREHOUSE_NAME | VARCHAR | Name of the warehouse that the query executed on. |
| QUERY_METERING_HOUR | TIMESTAMP_LTZ | Start of the metering hour window this row represents. |
| QUERY_START_TIME | TIMESTAMP_LTZ | Time when query execution started (in the local time zone). |
| QUERY_END_TIME | TIMESTAMP_LTZ | Time when query execution ended (in the local time zone). NULL until the query completes; see usage notes. |
| PARENT_QUERY_ID | VARCHAR | Query ID of the parent query. NULL until the query completes, or NULL if the query does not have a parent. |
| ROOT_QUERY_ID | VARCHAR | Query 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_ID | NUMBER | Internal/system-generated identifier for the user who issued the query. |
| USER_NAME | VARCHAR | User who issued the query. |
| ROLE_NAME | VARCHAR | Role that issued the query. |
| QUERY_HASH | VARCHAR | The hash value computed based on the canonicalized SQL text. |
| QUERY_PARAMETERIZED_HASH | VARCHAR | The hash value computed based on the parameterized query. |
| QUERY_TAG | VARCHAR | Query tag set for this statement through the QUERY_TAG session parameter. |
| CREDITS_USED_COMPUTE | NUMBER | Number of credits used for compute for this query in this metering hour. |
| CREDITS_USED_CLOUD_SERVICES | NUMBER | Number of credits used for cloud services for this query in this metering hour. |
| CREDITS_USED | NUMBER | Total 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_HOURto 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, andQUERY_TAG. After the query completes,PARENT_QUERY_IDandROOT_QUERY_IDremain 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: