- Schema:
For guidance on query performance when using organization-wide usage views, see Performance (Organization Usage).
QUERY_ METERING_ HISTORY view¶
Important
This view is only available in the organization account. For more information, see Premium views in the organization account.
Organization Usage performance
When you query a specific view in the SNOWFLAKE.ORGANIZATION_USAGE schema, follow the organization-wide guidance in
Performance (Organization Usage): bound every scan on history views, list
columns explicitly, and use the time filter column table plus worked SQL and anti-patterns there.
Note
Coming soon: The QUERY_METERING_HISTORY view is not yet available in the ORGANIZATION_USAGE
schema. Use QUERY_METERING_HISTORY view in ACCOUNT_USAGE for
per-query credit usage on adaptive warehouses.
When available, the query metering history view (QUERY_METERING_HISTORY) will return per-query
credit usage for queries run on adaptive warehouses across
accounts in your organization.
Columns¶
Several columns can be NULL until the query completes. For details, see usage notes.
Organization-level columns
| Column Name | Data Type | Description |
|---|---|---|
| ORGANIZATION_NAME | VARCHAR | Name of the organization. |
| ACCOUNT_LOCATOR | VARCHAR | System-generated identifier for the account. |
| ACCOUNT_NAME | VARCHAR | User-defined identifier for the account. |
Additional columns
| 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¶
- When this view is available in ORGANIZATION_USAGE, latency for the view may be up to 24 hours. Charges accrued by a job may take up to 24 hours 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.
-
The usage notes below describe row refresh, in-progress NULL columns, and data freshness for query metering. They apply to this organization view when it is available.
-
When this view is available, the QUERY_METERING_HISTORY view in the ACCOUNT_USAGE schema will contain the same columns as the QUERY_METERING_HISTORY view in the ORGANIZATION_USAGE schema, except for the organization-level columns. For sample queries, see Examples. Replace
SNOWFLAKE.ACCOUNT_USAGEwithSNOWFLAKE.ORGANIZATION_USAGEin the queries to return organization-level results.