Request a demo

BigQuery cost query · Waste

Failed BigQuery jobs and the slots they waste

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.

Runs on INFORMATION_SCHEMA metadata only · Columns checked against the Google Cloud docs in November 2026

The query

SELECT
  error_result.reason                         AS reason,
  COUNT(*)                                    AS failed_jobs,
  COUNT(DISTINCT user_email)                  AS principals,
  ROUND(SUM(total_slot_ms) / 3600000, 1)      AS slot_hours_used,
  ANY_VALUE(error_result.message)             AS example_message
FROM `region-us`.INFORMATION_SCHEMA.JOBS
WHERE creation_time >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY)
  AND error_result IS NOT NULL
  AND (statement_type != 'SCRIPT' OR statement_type IS NULL)
GROUP BY reason
ORDER BY slot_hours_used DESC;

How it works

error_result is set on every job that failed, with a machine-readable reason (for example resourcesExceeded, quotaExceeded, invalidQuery, accessDenied) and the human-readable message. Grouping by reason shows whether the failures are many cheap syntax errors or a few expensive jobs that ran out of memory after an hour of work.

With on-demand pricing, BigQuery doesn't bill queries that return an error. Under editions, the slots a job used before failing were still part of the reservation's usage, and an orchestrator that retries three times spends them three times.

Output columns

ColumnMeaning
reasonError reason, the same values as in the API.
slot_hours_usedSlot time the failed jobs consumed before failing.
example_messageOne error message for the reason; look up the full message in BigQuery error messages.

Permissions and notes

Needs: bigquery.jobs.listAll on the project, for example through the BigQuery Resource Viewer role (roles/bigquery.resourceViewer).

  • (statement_type != 'SCRIPT' OR statement_type IS NULL) drops parent rows of multi-statement queries, which repeat their children's slot time and errors, while keeping load and copy jobs, whose statement type is NULL.
  • Replace region-us with your location. Each region has its own INFORMATION_SCHEMA views.

Variations

Queries that keep failing

Groups failures by the normalized query hash, so the same scheduled query failing every day shows up as one row.

SELECT
  query_info.query_hashes.normalized_literals AS query_hash,
  ANY_VALUE(error_result.reason)              AS reason,
  COUNT(*)                                    AS failures,
  ANY_VALUE(user_email)                       AS principal,
  ANY_VALUE(LEFT(query, 200))                 AS example_query
FROM `region-us`.INFORMATION_SCHEMA.JOBS
WHERE creation_time >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY)
  AND job_type = 'QUERY'
  AND error_result IS NOT NULL
GROUP BY query_hash
HAVING failures >= 3
ORDER BY failures DESC;

FAQ

Are failed BigQuery queries free?

On-demand, yes: queries that return an error aren't charged. Under capacity (editions) pricing, the slot time they used counts as usage of your reservation.

Which failures should I fix first?

Recurring failures of scheduled jobs: each one is wasted compute and usually a stale or missing table downstream. Sort the second variation by failures.

All BigQuery cost queries · Data FinOps playbook · Pricing calculator

Cut BigQuery spend without guessing

Masthead attributes compute and storage cost to every project, user, pipeline and table, finds unused and dead-end tables, and shows where editions or on-demand pricing is cheaper. Mnemonic cut its BigQuery compute cost by 20% within 24 hours of onboarding.