Use BigQuery’s INFORMATION_SCHEMA views to detect, inspect, and optimize long-running SQL jobs.
BigQuery flags a query as slow when slot time, execution duration, or bytes processed exceed expected thresholds. Long runtimes usually stem from scanning un-filtered columns, shuffling large joins, or missing partition pruning.
Query INFORMATION_SCHEMA.JOBS or JOB_QUERY_STATS in your project’s region.Filter on job_type = 'QUERY', state = 'DONE', and execution_time > desired threshold.
SELECT job_id, user_email, total_slot_ms/1000 AS slot_s, total_bytes_processed/1e9 AS gb, query FROM `region-us`.INFORMATION_SCHEMA.JOBS_BY_PROJECT WHERE creation_time > TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 24 HOUR) AND job_type='QUERY' AND state='DONE' ORDER BY total_slot_ms DESC LIMIT 10;
Use region-us`.INFORMATION_SCHEMA.JOBS_BY_PROJECT
combined with INFORMATION_SCHEMA.JOBS_TIMELINE
to see per-stage bytes read.Cross-reference referenced_tables
to detect hot tables such as Orders
or OrderItems
.
Full table scans without partitions, cross joins, SELECT * on wide tables, and un-bounded ORDER BYs force BigQuery to scan or shuffle TBs, slowing results and costing more.
Partition Orders
by order_date
, cluster by customer_id
. Add WHERE clauses on created_at
for Customers
. Replace SELECT * with explicit columns.Use approximate aggregation functions like APPROX_COUNT_DISTINCT
when accuracy tolerance exists.
If a report repeatedly aggregates historical sales, build a materialized view on Orders
totals per day. BigQuery auto-refreshes the delta, letting dashboards read in milliseconds.
• Always filter on partition column
• Cluster large, frequently-filtered columns
• Limit SELECT columns
• Use WITH clauses to break complex logic
• Monitor BYTES_INPUT_SCANNED
in Cloud Monitoring
.
BigQuery’s optimizer rewrites SQL internally, yet it cannot add partitions or rewrite SELECT *. Schema-level tuning remains your task.
No. LIMIT impacts returned rows, not scanned bytes. Add WHERE filters to reduce cost.
Set up a scheduled query or Looker Studio dashboard to review weekly. Early detection prevents runaway costs.