Attributed cost system table reference
This feature is in Beta.
This page provides an overview of the attributed cost system table, including the schema, how attributed cost is estimated, and example queries.
The attributed cost table breaks shared compute bills down to the workloads that ran on them. A SQL warehouse is billed as a single resource in system.billing.usage, so you cannot tell from the billable usage table which queries, users, or teams drove a warehouse's cost. The attributed cost table estimates each query's share of the warehouse's usage so you can identify cost drivers and charge back or show back shared costs.
Table path: This system table is located at system.billing.attributed_cost.
During Beta, the table contains records for queries run on SQL warehouses only. Each row is one query. For records from system.billing.usage that do not have attributed cost records, such as jobs or serverless notebooks, use the billable usage table directly.
Record availability
Records are typically available within 24 hours. Data delivery for new workspaces can take longer than this.
Using the attributed cost table
The attributed cost table includes a record for each query that ran on a SQL warehouse and consumed warehouse compute. The table includes records from all workspaces in your account that are in the same region as the workspace you use to access the table.
Each record reports active usage, which is the estimated share of the warehouse's billed usage that the query consumed while it was running. Active usage does not include unattributed time, which is the time when the warehouse was ready but had no queries running on it. Because of this, the sum of active usage for a warehouse is less than or equal to the warehouse's total billed usage in system.billing.usage. To charge back the full warehouse cost, including unattributed time, see Charge back the full warehouse cost.
By default, only admins have access to the system table. To share the table's data with a user or group, Databricks recommends creating a dynamic view for each user or group. See Create a dynamic view.
Attributed cost table schema
The attributed cost system table uses the following schema:
Column name | Data type | Description | Example |
|---|---|---|---|
| string | Unique ID for this attributed cost record. For queries, the value is |
|
| struct | System-provided metadata about the workload the cost is attributed to, grouped by product. Only the struct for the product that originated the usage is populated. See Usage metadata. | See Usage metadata |
| struct | System-provided metadata about the identities involved in the attributed usage. See Identity metadata. |
|
| timestamp | The start time of the workload. For queries, the time when Databricks received the request. Timezone information is recorded at the end of the value with |
|
| timestamp | The end time of the workload. For queries, the time the statement execution ended. Timezone information is recorded at the end of the value with |
|
| date | Date of the attributed cost record, derived from |
|
| string | Unit the attributed usage is measured in. |
|
| decimal | Estimated number of units the workload consumed while it was running. For queries, this is the query's share of the warehouse's billed usage. Usage from unattributed time is not included. See How attributed cost is estimated. |
|
| decimal | Estimated list-price cost of |
|
| struct | Tags applied to the workload rather than to the compute resource. For queries, |
|
|
| The |
|
| string | ID of the account this report was generated for. |
|
| string | ID of the workspace this usage was associated with. |
|
| string | Name of the SKU, from the associated billable usage record. If the query's usage spans more than one SKU, this is the SKU with the highest list price. See How attributed cost is estimated. |
|
| string | Cloud associated with this usage. Possible values are |
|
| string | The product that originated the usage. During Beta, the value is always |
|
|
| Custom tags from the associated billable usage record, such as the tags applied to the SQL warehouse. |
|
Usage metadata reference
The usage_metadata column is a struct with one nested struct per product. Only the struct for the product that originated the usage is populated. The other structs are null.
The usage_metadata column in this table is separate from the usage_metadata column on the associated records in system.billing.usage. To read the billable usage record's metadata, join on usage_record_ids. See Join with the billable usage table.
sql
The usage_metadata.sql struct is populated for queries run on SQL warehouses. Its values match the corresponding columns in system.query.history for the same statement.
Value | Description | Example |
|---|---|---|
| The ID that uniquely identifies the execution of the statement. Join this value to |
|
| ID of the SQL warehouse that ran the statement. |
|
| Client application that ran the statement, such as |
|
| A struct that identifies the Databricks entities involved in running the statement, such as a job or dashboard. The struct has the same shape as the |
|
Identity metadata reference
The identity_metadata column records the identities involved in the attributed usage. The executed_by field is the email address or username of the user or Databricks service principal that ran the workload. For queries, this matches executed_by in system.query.history.
The identity_metadata column in this table is separate from the identity_metadata column in system.billing.usage. For SQL warehouse usage, system.billing.usage records the warehouse owner in identity_metadata.owned_by, whereas this table records the user who ran each query.
How attributed cost is estimated
Attributed cost is an estimate. Databricks does not meter individual queries. Instead, the attributed cost table splits each warehouse's billed usage across the queries that ran on it:
- For each billing period of a warehouse in
system.billing.usage, Databricks identifies the queries that ran on that warehouse during the period. - The billed usage of the period is split across those queries in proportion to the compute each query consumed, based on the query's task execution time. Queries that span more than one billing period receive a share of each period they ran in.
- A query's share is capped at the usage of a single cluster for the duration of the query. A query runs on one cluster of a warehouse, so its attributed usage doesn't exceed what that cluster consumed while the query ran, even on multi-cluster warehouses.
- Usage from unattributed time is not assigned to any query. It remains part of the warehouse's billed usage in
system.billing.usagebut does not appear in this table.
If a warehouse is billed under more than one SKU in the same billing period, the query receives a share of each SKU's usage. active_usage_quantity is the total across those SKUs, and active_usage_list_cost prices each SKU's share at that SKU's list price, so the cost is a blend of the SKUs' rates. Because a record has a single sku_name, it reports the SKU with the highest list price.
As a result:
active_usage_quantitysummed across all queries on a warehouse is less than or equal to the warehouse'susage_quantityinsystem.billing.usagefor the same period. The difference is the usage from unattributed time.- The same query can have a different attributed cost on a different day, because its cost depends on what else ran on the warehouse at the same time.
- Queries that do not consume warehouse compute, such as queries served from the query result cache, do not have records in this table.
Join with the billable usage table
Each attributed cost record is associated with one or more records in system.billing.usage through usage_record_ids. A query that runs within a single billing period has one associated usage record. A query that spans a billing period boundary has one usage record per period.
To join the two tables, explode the array:
SELECT
a.record_id,
a.statement_id,
a.active_usage_quantity,
u.record_id AS usage_record_id,
u.usage_start_time,
u.usage_end_time,
u.usage_quantity AS warehouse_usage_quantity
FROM (
SELECT
record_id,
usage_metadata.sql.statement_id,
active_usage_quantity,
explode(usage_record_ids) AS usage_record_id
FROM system.billing.attributed_cost
WHERE usage_date = current_date() - 1
) a
JOIN system.billing.usage u ON u.record_id = a.usage_record_id
Sample queries
The following queries show common ways to use the attributed cost table. For sample queries against the billable usage table, see Monitor costs using system tables.
Which queries were the most expensive this month, and who ran them?
SELECT
a.usage_metadata.sql.statement_id,
a.identity_metadata.executed_by,
a.usage_metadata.sql.warehouse_id,
a.active_usage_quantity,
a.active_usage_list_cost,
q.statement_text
FROM system.billing.attributed_cost a
LEFT JOIN system.query.history q
ON q.statement_id = a.usage_metadata.sql.statement_id
AND q.workspace_id = a.workspace_id
WHERE a.usage_date >= date_trunc('MONTH', current_date())
ORDER BY a.active_usage_quantity DESC
LIMIT 10
How much did each user spend on SQL warehouses this month?
SELECT
identity_metadata.executed_by,
SUM(active_usage_quantity) AS active_dbus,
SUM(active_usage_list_cost) AS active_list_cost
FROM system.billing.attributed_cost
WHERE usage_date >= date_trunc('MONTH', current_date())
GROUP BY 1
ORDER BY active_dbus DESC
How much did a team spend, based on query tags?
This query uses the team query tag. Replace the tag key and value with your own.
SELECT
SUM(active_usage_quantity) AS active_dbus,
SUM(active_usage_list_cost) AS active_list_cost
FROM system.billing.attributed_cost
WHERE usage_date >= date_trunc('MONTH', current_date())
AND granular_tags.query_tags['team'] = 'marketing'
Which dashboards, jobs, or Genie Agents drove the most cost?
The usage_metadata.sql.query_source struct identifies the entity that triggered each query. This query groups cost by dashboard.
SELECT
usage_metadata.sql.query_source.dashboard_id,
COUNT(*) AS queries,
SUM(active_usage_quantity) AS active_dbus,
SUM(active_usage_list_cost) AS active_list_cost
FROM system.billing.attributed_cost
WHERE usage_date >= date_trunc('MONTH', current_date())
AND usage_metadata.sql.query_source.dashboard_id IS NOT NULL
GROUP BY 1
ORDER BY active_dbus DESC
LIMIT 10
To group by a different source, replace dashboard_id with job_info.job_id, notebook_id, alert_id, sql_query_id, or genie_space_id.
How do I charge back the full warehouse cost?
Active usage excludes unattributed time, so summing active_usage_quantity understates what the warehouse cost in total. To charge back the full bill, distribute each warehouse's total billed usage from system.billing.usage across teams in proportion to their active usage. This example attributes by the team query tag.
WITH warehouse_bill AS (
SELECT
workspace_id,
usage_metadata.warehouse_id AS warehouse_id,
SUM(usage_quantity) AS total_usage
FROM system.billing.usage
WHERE usage_date >= date_trunc('MONTH', current_date())
AND billing_origin_product = 'SQL'
AND usage_metadata.warehouse_id IS NOT NULL
GROUP BY 1, 2
),
team_active_usage AS (
SELECT
workspace_id,
usage_metadata.sql.warehouse_id AS warehouse_id,
granular_tags.query_tags['team'] AS team,
SUM(active_usage_quantity) AS active_usage
FROM system.billing.attributed_cost
WHERE usage_date >= date_trunc('MONTH', current_date())
GROUP BY 1, 2, 3
),
warehouse_active_usage AS (
SELECT workspace_id, warehouse_id, SUM(active_usage) AS total_active_usage
FROM team_active_usage
GROUP BY 1, 2
)
SELECT
t.team,
SUM(t.active_usage) AS active_usage,
SUM(t.active_usage * b.total_usage / NULLIF(w.total_active_usage, 0)) AS total_usage
FROM team_active_usage t
JOIN warehouse_active_usage w ON t.workspace_id = w.workspace_id AND t.warehouse_id = w.warehouse_id
JOIN warehouse_bill b ON t.workspace_id = b.workspace_id AND t.warehouse_id = b.warehouse_id
GROUP BY 1
ORDER BY total_usage DESC
Rows with a null team represent queries without the tag. Usage from unattributed time is split in proportion to each team's active usage on the same warehouse. For a more accurate split, group by day or by hour instead of by month.
How much of a warehouse's usage was not attributed to any query?
WITH billed AS (
SELECT usage_metadata.warehouse_id AS warehouse_id, SUM(usage_quantity) AS billed_dbus
FROM system.billing.usage
WHERE usage_date = current_date() - 1
AND billing_origin_product = 'SQL'
AND usage_metadata.warehouse_id IS NOT NULL
GROUP BY 1
),
attributed AS (
SELECT usage_metadata.sql.warehouse_id AS warehouse_id, SUM(active_usage_quantity) AS active_dbus
FROM system.billing.attributed_cost
WHERE usage_date = current_date() - 1
GROUP BY 1
)
SELECT
b.warehouse_id,
b.billed_dbus,
COALESCE(a.active_dbus, 0) AS active_dbus,
b.billed_dbus - COALESCE(a.active_dbus, 0) AS unattributed_dbus,
ROUND(COALESCE(a.active_dbus, 0) / b.billed_dbus, 2) AS active_share
FROM billed b
LEFT JOIN attributed a ON a.warehouse_id = b.warehouse_id
ORDER BY unattributed_dbus DESC
A low active_share means that most of the warehouse's billed time was unattributed time. Consider lowering the warehouse's auto-stop setting or consolidating workloads onto fewer warehouses.