Finding Expensive Queries With INFORMATION_SCHEMA Jobs
A three-step BigQuery audit that ranks queries by the right cost signal.

Finding expensive queries in BigQuery starts with INFORMATION_SCHEMA.JOBS, but how to rank them depends on how the project pays. Bytes billed guide on-demand optimization, while slot milliseconds guide capacity optimization. A three-step audit turns that distinction into a prioritized fix list by ranking repeated queries, isolating scheduled work, and tracing slot use over time.
Why the same query produces two different cost signals in BigQuery
BigQuery records every query job in INFORMATION_SCHEMA.JOBS, making it the authoritative cost ledger across several months of project history. In each row, total_bytes_billed measures the bytes charged under on-demand pricing, while total_slot_ms measures how much compute the job uses and is the cost proxy for Editions reservations. These fields answer different questions about the same execution. Neither can substitute for the other.
Consider a query that scans little data but spends a long time on complex aggregations. It can look cheap by bytes and expensive by slot milliseconds. For a team using Editions, sorting by bytes billed can therefore elevate queries that contribute little to its capacity needs. The audit may lead to fixes that work well but leave the bill unchanged. Before investigating any query, the first question is which signal matches the pricing model.

What INFORMATION_SCHEMA.JOBS and JOBS_TIMELINE each expose
INFORMATION_SCHEMA.JOBS provides one row per job, whether its state is PENDING, RUNNING, or DONE. Its summary fields include total_slot_ms, total_bytes_billed, total_bytes_processed, and cache_hit, which describe resource use and cached results. Fields including reservation_id, job_id, user_email, and creation and end timestamps place that work in context. This is the view for per-job ranking. It connects consumption to the query, its origin, and its timing without reconstructing each second of execution.
INFORMATION_SCHEMA.JOBS_TIMELINE supplies that finer view, with one row per job per second of execution. Its period_slot_ms field exposes slot consumption during each period, while period_estimated_runnable_units helps reveal work waiting for slots. Both views use the region-LOCATION prefix for their region, such as region-us-central1. Job prefixes also help distinguish origins. The scheduled_query_ prefix identifies scheduled queries, materialized_view_refresh_ identifies materialized view refresh jobs, and bquxjob_ identifies BigQuery UI queries.
Step 1: Surface the top offenders by the right cost signal
Sorting individual jobs finds the worst single execution, but that is not necessarily the most expensive query pattern. A modest query repeated throughout the month can cost more in aggregate. Repetition changes what belongs at the top. To capture it, query JOBS_BY_PROJECT over a 30-day window and group executions by SUBSTR(query, 1, 200). That substring acts as a signature for clustering repeated runs.
For on-demand projects, rank those groups by SUM(total_bytes_billed). For Editions, use SUM(total_slot_ms) to rank by how much compute the jobs use. Include execution_count, avg_gib_per_execution, and user_email to show how often each pattern runs, its average billed scan size, and who submits it. Frequency gives the total a useful explanation. It distinguishes a large one-off execution from a smaller query whose cumulative demand deserves attention.
A second pass should normalize whitespace with REGEXP_REPLACE before taking the substring, so formatting differences do not split the same query into separate buckets. The query preview remains necessary for interpretation. Keep the list of patterns to check short, typically the top 20 patterns. That gives the next steps a defined scope rather than turning the audit into an examination of every job.
Step 2: Isolate scheduled queries from the ranked list
Scheduled queries are especially fixable because their repetition is explicit, yet that same repetition can conceal growing costs. A query written for a smaller table may keep running even after the table has outgrown what it was built for. Fintel Analytics describes teams that found a single scheduled query running hundreds of times a month against an unpartitioned multi-TB table. Its expense had been attributed to “general growth.” The job history exposed a specific recurring cause instead.
To isolate this category, apply STARTS_WITH(job_id, 'scheduled_query_') to INFORMATION_SCHEMA.JOBS. The predicate separates scheduled jobs from ad-hoc, dbt-driven, and UI queries without a join. Fintel Analytics recommends first sorting the past month’s scheduled executions by total_bytes_billed DESC, then grouping by SUBSTR(query, 1, 200) and summing their cost. That sequence reveals both the largest execution and cumulative 30-day demand. For Editions, the ranking still needs to use slot milliseconds.
The output now supports more pointed questions. When an execution is above a small estimated_cost_usd threshold, is a partition predicate missing from its preview? Is a “daily” report refreshing every hour? Is the same table being scanned repeatedly when a materialized view or incremental dbt model could replace that work?
Step 3: Map slot consumption over time to find contention and over-provisioning
The ranked list cannot show whether expensive jobs need the same slots at the same time. Nor does it reveal whether a reservation sits mostly idle between runs. Timing changes the diagnosis of resource use. A nightly pipeline can consume substantial compute without disrupting other work, or it can overlap with interactive queries and leave them waiting. That distinction requires JOBS_TIMELINE.
Aggregate period_slot_ms by hour to derive average concurrent slot usage, then compare that usage with the reservation baseline. When a reservation keeps using far fewer slots than were purchased, money is going toward idle capacity. Contention needs a separate measure of waiting. When period_estimated_runnable_units > 0 during a large share of a job’s execution seconds, work was queued for slots. The percentage of affected seconds helps distinguish sustained contention from a brief overlap.
Grouping the timeline by reservation_id also shows whether capacity is balanced across workload assignments. Together, these views give a profile of peak slots, average slots, and the times when jobs compete for slots. A steady pipeline and a short burst need not justify the same capacity arrangement. This profile supplies the time dimension needed to decide whether on-demand or Editions is cheaper.
How the audit's output determines which pricing model wins
The pricing decision depends on the relationship between bytes and compute, which the audit expresses as a slot-hours-per-TiB ratio for assessment against the relevant pricing terms. That comparison can show very different costs for the same workload. A nightly pipeline that scans heavily and runs predictably strongly favors capacity pricing.
On-demand is a better fit for use that comes in bursts, including weeks with near-zero queries or a few high-value queries within the free tier. The danger is retaining that model after the workload has grown beyond those conditions. Yet predictability alone does not excuse idle reservations. The timeline shows whether purchased capacity actually matches the work, so the decision must account for both consumption and utilization.
The choice need not apply uniformly across every workload. Mixed-model operation can keep ad-hoc exploration on-demand while placing heavy scheduled pipelines on Editions. The audit helps draw that boundary at the project level. It also explains why optimizing a query and reducing a bill are not always the same task. Sometimes changing how a recurring workload is priced can save more.
The fixes that follow from the ranked list: partition filters, caching, and materialized views
Once the pricing model and ranking agree, the first remediation target is missing partition filters. For a partitioned table, total_bytes_processed represents the post-pruning scan and should be closer to the relevant partition size than the full table size. Large scans deserve a closer look first. Start with jobs that have more than 10 GiB billed when checking for missing date predicates, and check separately for the expensive query pattern SELECT *.
Grouping by cache_hit shows how much query volume returns cached results at zero cost, while non-deterministic functions, changes to the underlying table, and explicitly disabled result caching explain missed reuse. Repeated scans may also call for replacement. Scheduled queries reading the same table on a fixed cadence with no row-level changes are strong materialized view candidates, since BigQuery refreshes those views incrementally. Incremental dbt models are another way to replace repeated work found by the audit.
What the audit cannot do: its limits as a lagging instrument
The ledger records expensive queries after they have run and billed. It cannot intercept a new pattern introduced by an analyst, a pipeline, or AI-generated SQL before the expense arrives. Historical evidence can guide corrections, but it cannot make every future query safe or cheap.
Some findings also fall outside what query tuning can resolve. BigQuery imposes quota limits on concurrent queries and jobs, while slot contention exposes another source of waiting. The audit diagnoses pressure without removing those constraints. Latency variance under high concurrency may persist despite optimization, and a correctly written query can still be inherently expensive for its workload type. At that point, deciding where the query should run becomes more useful than rewriting it.
When the audit reveals that the problem is the architecture, not the query
Real-time product features and application APIs can impose high concurrency and latency demands that do not fit a batch analytical warehouse. Their cost comes from the serving pattern. Dashboard queries that refresh on every user load create a similar multiplier on repeated work. Append-only observability and event-stream queries with sub-second requirements present another mismatch. In these cases, a top-offender entry may identify an architectural boundary.
Latency-sensitive, high-concurrency serving can move to a system designed for it, while BigQuery remains responsible for batch analytics. The audit identifies which query pattern needs that separation. For sensitive data, deployment also enters the decision because moving to a third-party managed service can require a governance review. BYOC deployment keeps data inside the team’s own AWS or Google Cloud account.
AI agent workloads deserve particular attention when they emerge as major slot consumers. Agents that query a database again and again can be a poor fit for per-query metering even when each request seems reasonable. Frequency is the structural issue in that case. Those workloads need isolated, read-only compute, full audit logs, and no per-query metering. The assessment should therefore consider the execution model as well as the SQL that appears in the ranked list.
Turning the audit into a repeatable process rather than a one-time fix
A one-time audit gives a snapshot, but query patterns and table sizes can change after the initial repairs. To make the workflow repeatable, save its three analyses as scheduled queries and write their outputs to a monitoring table. Keep them restricted to metadata for negligible compute use. Each set of outputs should keep the ranking by signature, the scheduled queries on their own, and the slot timeline. That preserves both cumulative cost and the timing needed to interpret it.
Alerts can then focus on changes that warrant investigation. A new signature in the top-20 list shows a pattern that was absent in the prior period, while a scheduled query whose per-execution cost rises week over week may have outgrown what it was built for. Sustained low utilization signals a different intervention. When slot use stays well below the reservation baseline for more than a defined number of consecutive hours, it points toward downsizing the reservation.
For teams whose recurring audit identifies a serving workload that belongs elsewhere, the next step can remain narrow. A free workload assessment or trial can focus on the specific pattern the ledger exposed. There is no need to begin with a full migration. The practical test is whether a different execution layer better fits that workload’s concurrency, latency, governance, and charging needs.


