# Find the most expensive queries in BigQuery (SQL) | Masthead

This query lists the BigQuery jobs that billed the most bytes in the last 30 days, with an on-demand cost estimate, slot-hours and the start of the SQL. It is the first query to run when the bill jumps: a handful of jobs usually explains most of the spend.

> For the index of this section of the site, see [llms.txt](https://mastheadata.com/llms.txt)

BigQuery cost query · Where the money goes

# Find the most expensive queries in BigQuery

This query lists the BigQuery jobs that billed the most bytes in the last 30 days, with an on-demand cost estimate, slot-hours and the start of the SQL. It is the first query to run when the bill jumps: a handful of jobs usually explains most of the spend.

Runs on INFORMATION\_SCHEMA metadata only · Columns checked against the Google Cloud docs in November 2026

## The query

```
SELECT
  job_id,
  user_email,
  creation_time,
  ROUND(total_bytes_billed / POW(1024, 4), 3)        AS tib_billed,
  ROUND(total_bytes_billed / POW(1024, 4) * 6.25, 2) AS est_on_demand_usd,
  ROUND(total_slot_ms / 3600000, 2)                  AS slot_hours,
  LEFT(query, 200)                                   AS query_start
FROM `region-us`.INFORMATION_SCHEMA.JOBS
WHERE creation_time >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY)
  AND job_type = 'QUERY'
  AND statement_type != 'SCRIPT'
ORDER BY total_bytes_billed DESC
LIMIT 50;
```

## How it works

Every query job leaves a row in `INFORMATION_SCHEMA.JOBS` with the bytes it billed (`total_bytes_billed`) and the slot time it used (`total_slot_ms`). On-demand pricing charges per TiB billed, so sorting by `total_bytes_billed` puts the most expensive jobs first. Slot-hours are what the same job would cost under editions.

One expensive job is a cleanup task. The same query run 2,000 times a month is a design problem: group by the normalized query hash (second variation) to find those, because a scheduled dashboard refresh rarely shows up in a top-50 list of single jobs.

## Output columns

| Column | Meaning |
| --- | --- |
| `tib_billed` | TiB billed by the job, after the 10 MB minimum per table and per query. |
| `est_on_demand_usd` | On-demand list price for those bytes. Not your bill if you use editions or have discounts. |
| `slot_hours` | Slot time the job used. Under editions, cost is slot-hours times the price per slot-hour. |
| `query_start` | First 200 characters of the SQL, enough to recognise the job. |

## Permissions and notes

**Needs:** `bigquery.jobs.listAll` on the project, for example through the BigQuery Resource Viewer role (`roles/bigquery.resourceViewer`). To see only your own jobs, query `JOBS_BY_USER` instead.

*   The `6.25` is the on-demand list price per TiB in the US and EU multi-regions. If your projects run on editions, cost follows slot-hours instead: multiply `slot_hours` by your edition's price per slot-hour (see [BigQuery pricing](https://mastheadata.com/bigquery/pricing.md)).
*   `statement_type != 'SCRIPT'` drops the parent row of multi-statement queries. The parent repeats the bytes and slots of its child statements, so keeping it would count them twice.
*   Replace `region-us` with the location your jobs run in (`region-eu`, `region-europe-west2`, ...). Each region has its own INFORMATION\_SCHEMA views, so a multi-region estate needs one query per region.
*   INFORMATION\_SCHEMA.JOBS keeps 180 days of history. The view is partitioned by `creation_time`, so the time filter also keeps this query cheap.

## Variations

### Across every project in the organization

```
SELECT
  project_id,
  job_id,
  user_email,
  ROUND(total_bytes_billed / POW(1024, 4) * 6.25, 2) AS est_on_demand_usd,
  LEFT(query, 200) AS query_start
FROM `region-us`.INFORMATION_SCHEMA.JOBS_BY_ORGANIZATION
WHERE creation_time >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY)
  AND job_type = 'QUERY'
  AND statement_type != 'SCRIPT'
ORDER BY total_bytes_billed DESC
LIMIT 50;
```

### Group repeated runs of the same query

`query_info.query_hashes.normalized_literals` is the same for queries that differ only in literals, comments or parameter values, so a scheduled query and its daily runs collapse into one row.

```
SELECT
  query_info.query_hashes.normalized_literals         AS query_hash,
  COUNT(*)                                            AS runs,
  ANY_VALUE(user_email)                               AS example_user,
  ANY_VALUE(LEFT(query, 200))                         AS example_query,
  ROUND(SUM(total_bytes_billed) / POW(1024, 4) * 6.25, 2) AS est_on_demand_usd
FROM `region-us`.INFORMATION_SCHEMA.JOBS
WHERE creation_time >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY)
  AND job_type = 'QUERY'
  AND statement_type != 'SCRIPT'
GROUP BY query_hash
ORDER BY est_on_demand_usd DESC
LIMIT 50;
```

## FAQ

Why is the estimate different from my invoice?

It applies the on-demand list price to bytes billed. Your invoice also reflects the 1 TiB monthly free tier, discounts, editions or reservations, storage and other services. Use it to rank queries, and Cloud Billing to reconcile totals.

Does INFORMATION\_SCHEMA.JOBS cost money to query?

Yes, it is billed like any query, with a 10 MB minimum. Filtering on `creation_time`, the partitioning column, keeps the scan small.

How do I see queries from other projects?

Use `JOBS_BY_ORGANIZATION`, which needs `bigquery.jobs.listAll` at the organization level, or run the query in each project.

## Related

[BigQuery cost by user and service account](https://mastheadata.com/bigquery/cost-queries/cost-by-user.md)[Find repeated BigQuery queries and cache misses](https://mastheadata.com/bigquery/cost-queries/repeated-queries.md)[Daily BigQuery cost trend and spike detection](https://mastheadata.com/bigquery/cost-queries/daily-cost-trend.md)[Which BigQuery tables drive query cost](https://mastheadata.com/bigquery/cost-queries/cost-by-table.md)[Find SELECT \ queries that scan whole tables](https://mastheadata.com/bigquery/cost-queries/select-star-queries.md)

*   [INFORMATION\SCHEMA.JOBS reference](https://mastheadata.com/bigquery/sql/information-schema-jobs.md)
*   [BigQuery pricing explained](https://mastheadata.com/bigquery/pricing.md)

[All BigQuery cost queries](https://mastheadata.com/bigquery/cost-queries.md) · [Data FinOps playbook](https://mastheadata.com/data-finops.md) · [Pricing calculator](https://mastheadata.com/bigquery/pricing-calculator.md)
---

## Other pages in cost-queries

> For the full index of this section, see [BigQuery Reference](https://mastheadata.com/llms/llms-bigquery-reference.txt).

- [BigQuery cost per Airflow DAG and task (SQL) | Masthead](https://mastheadata.com/bigquery/cost-queries/airflow-dag-cost.md): This query uses the airflow-dag and airflow-task labels that Airflow's Google provider adds to BigQuery jobs to rank DAGs and tasks by on-demand cost and slot-hours over the last 30 days, on Cloud Composer or any other Airflow.
- [BigQuery cost by label: team, product or pipeline (SQL) | Masthead](https://mastheadata.com/bigquery/cost-queries/cost-by-label.md): This query splits BigQuery compute by the value of a job label, such as team or cost center, and shows how much spend has no label at all. Labels are how BigQuery cost gets an owner, so the unlabeled share is the first number to drive down.
- [BigQuery cost by project across the organization (SQL) | Masthead](https://mastheadata.com/bigquery/cost-queries/cost-by-project.md): This query ranks every project in the organization by bytes billed, on-demand cost estimate and slot-hours over the last 30 days, from one INFORMATION_SCHEMA view. It is the starting point for showback: which teams and products spend what.
- [Which BigQuery tables drive query cost (SQL) | Masthead](https://mastheadata.com/bigquery/cost-queries/cost-by-table.md): This query ranks tables by the bytes billed of the queries that read them over the last 30 days, with an even split for queries that read several tables. It points to the tables where partitioning, clustering or a summary table would save the most.
- [BigQuery cost by user and service account (SQL) | Masthead](https://mastheadata.com/bigquery/cost-queries/cost-by-user.md): This query adds up bytes billed, an on-demand cost estimate and slot-hours per user and service account over the last 30 days. It shows whether the bill comes from people running ad hoc queries or from pipelines running under service accounts.
- [Daily BigQuery cost trend and spike detection (SQL) | Masthead](https://mastheadata.com/bigquery/cost-queries/daily-cost-trend.md): This query returns BigQuery compute per day for the last 90 days (bytes billed, on-demand cost estimate, slot-hours) and a variation flags days that cost more than twice the previous week's average. Run it to see when a cost jump started before you go looking for the job that caused it.
- [BigQuery cost per dbt model (SQL) | Masthead](https://mastheadata.com/bigquery/cost-queries/dbt-model-cost.md): This query attributes BigQuery compute to dbt models by reading the JSON comment dbt prepends to every query, then ranks models by on-demand cost, slot-hours and run time over the last 30 days. It finds the handful of models worth making incremental or rescheduling.
- [Find dead-end tables: written but never read (SQL) | Masthead](https://mastheadata.com/bigquery/cost-queries/dead-end-tables.md): This query finds tables that jobs wrote to in the last 30 days but no query read, and what building them cost. Dead-end tables waste both the compute that refreshes them and the storage they occupy, so they are often worth more than unused tables.
- [Failed BigQuery jobs and the slots they waste (SQL) | Masthead](https://mastheadata.com/bigquery/cost-queries/failed-jobs-cost.md): This query groups the last 30 days of failed BigQuery jobs by error reason, with how many failed, who ran them and the slot-hours they used before failing. On-demand failures aren't billed, but under editions the slot time is spent, and retries multiply it.
- [Logical vs physical storage billing: which datasets to switch (SQL) | Masthead](https://mastheadata.com/bigquery/cost-queries/logical-vs-physical-storage.md): This query computes each dataset's monthly storage cost under logical and physical billing with Google's own forecast formula, and the saving from switching. Physical billing usually wins for well-compressed data that doesn't churn.
- [BigQuery cost of Looker Studio dashboards (SQL) | Masthead](https://mastheadata.com/bigquery/cost-queries/looker-studio-cost.md): This query finds the BigQuery jobs Looker Studio runs, groups them by data source and shows their on-demand cost and cache hit rate over the last 30 days. Dashboards that refresh often on large tables are one of the most common hidden BigQuery costs.
- [On-demand vs editions: which is cheaper per project (SQL) | Masthead](https://mastheadata.com/bigquery/cost-queries/on-demand-vs-editions.md): This query compares what each project's queries cost on-demand with what the same slot-hours would cost on Standard and Enterprise editions, using 30 days of INFORMATION_SCHEMA data, and adds the GiB scanned per slot-hour that decides the answer.
- [Peak and p95 BigQuery slot usage (SQL) | Masthead](https://mastheadata.com/bigquery/cost-queries/peak-slot-usage.md): This query computes slots in use for every second of the last week from JOBS_TIMELINE, then reports the average, 95th percentile and peak per hour. Size autoscaling for the p95, not the peak, and baseline for what runs all the time.
- [Find repeated BigQuery queries and cache misses (SQL) | Masthead](https://mastheadata.com/bigquery/cost-queries/repeated-queries.md): This query finds queries that run over and over with the same shape, with how often they ran, how often the result cache answered them and what they cost. Repeated queries are the best candidates for materialized views, summary tables, BI Engine or simply a slower refresh.
- [Find SELECT * queries that scan whole tables (SQL) | Masthead](https://mastheadata.com/bigquery/cost-queries/select-star-queries.md): This query finds the most expensive queries that start with SELECT  FROM in the last 30 days, grouped by principal. BigQuery bills every column a query touches, so SELECT  on a wide table is often the single most expensive habit, and LIMIT doesn't help.
- [BigQuery slot usage by hour (SQL) | Masthead](https://mastheadata.com/bigquery/cost-queries/slot-usage-by-hour.md): This query turns INFORMATION_SCHEMA.JOBS_TIMELINE into the average number of slots your jobs used in each hour of the last week. It is the curve you size a reservation against, and it shows when your heavy pipelines actually run.
- [BigQuery storage cost per table (SQL) | Masthead](https://mastheadata.com/bigquery/cost-queries/storage-cost-by-table.md): This query lists the tables that cost the most to store, with logical and physical size and the monthly cost under each billing model, from INFORMATION_SCHEMA.TABLE_STORAGE. It finds the few tables that make up most of the storage bill.
- [Find tables paying for time travel and fail-safe storage (SQL) | Masthead](https://mastheadata.com/bigquery/cost-queries/time-travel-storage-cost.md): This query finds the tables with the most time-travel and fail-safe bytes, which physical storage billing charges at the active rate. Tables rebuilt every day are the usual culprits; shortening the time travel window or loading incrementally fixes them.
- [Find unused BigQuery tables (SQL) | Masthead](https://mastheadata.com/bigquery/cost-queries/unused-tables.md): This query finds tables older than 90 days that no query job has read in the last 90 days, with their size and monthly storage cost. They are the safest storage savings: archive, expire or delete them after checking with their owners.
- [BigQuery Cost Queries: SQL to Find and Cut BigQuery Spend | Masthead](https://mastheadata.com/bigquery/cost-queries.md): 20 ready-to-run SQL queries for BigQuery cost: the most expensive queries, cost by user, project, label, dbt model and dashboard, slot usage, storage cost, unused and dead-end tables.
