Skip to content
Software capabilities
BigQuery

Estimate query bytes before running

BigQuery can validate a query and estimate its processed bytes with a dry run. Use the REST query job for automation or the bq command when you are working in a terminal.

Documentation reviewed · 2 methods with sources

Ways to do it

  1. API: POST /bigquery/v2/projects/{projectId}/queries
  2. CLI: bq query --dry_run
API

POST /bigquery/v2/projects/{projectId}/queries

Submit a jobs.query request with dryRun enabled. The response validates the SQL and reports estimated bytes processed without running the query.

Read source: BigQuery jobs.query API
Requirements
A Google Cloud project, Application Default Credentials or an OAuth access token, BigQuery Job User permission on the project, and access to the referenced datasets and tables.
Limitations
Dry runs of federated queries can report a lower bound of zero bytes, and tables protected by row-level security return zero bytes, so those estimates are not a reliable cost ceiling.

Example json

{
  "query": "SELECT COUNT(*) FROM `PROJECT.DATASET.TABLE`",
  "dryRun": true,
  "useLegacySql": false,
  "useQueryCache": false
}
CLI

bq query --dry_run

Validate a GoogleSQL statement and print the estimated bytes from the bq command-line tool.

Read source: BigQuery cost controls and bq dry run
Requirements
The Google Cloud CLI with bq installed, an authenticated account, a default project or --project_id, and permission to create query jobs and read referenced tables.
Limitations
The command only validates and estimates the statement. It does not return query rows or account for bytes from an external source that BigQuery cannot determine until execution.

Example shell

bq query --use_legacy_sql=false --dry_run 'SELECT COUNT(*) FROM `PROJECT.DATASET.TABLE`'