Skip to content
BigQueryGCPData Engineering

BigQuery Partitioning vs Clustering: A Practical Guide to Cutting Query Costs

Learn how BigQuery partitioning and clustering cut query costs, when to use each, and the DDL, guardrails and anti-patterns that keep bytes scanned low.

By 7 min read

BigQuery makes it easy to query terabytes in seconds, which also makes it easy to spend more than you planned. Partitioning and clustering are the two main tools for controlling how much data each query reads. This guide explains how each one works, when to combine them, and the habits that keep your bill predictable.

How BigQuery bills your queries

BigQuery stores tables in a columnar format, which means each column is stored separately. A query reads only the columns it references, and it reads them for every row the engine cannot rule out in advance. Storage is billed separately and is usually the smaller part of the bill.

There are two compute pricing models:

  • On-demand: you pay per TiB of data scanned. Reducing bytes scanned directly reduces cost.
  • Capacity (BigQuery editions): you pay for slots, BigQuery's units of compute, over time, with optional autoscaling. Bytes scanned do not appear on the invoice, but scanning less uses fewer slot-seconds, so queries finish faster and leave capacity for everyone else.

Either way, the goal is the same: make each query read as little data as possible. Partitioning and clustering do this by letting BigQuery skip data before reading it.

Partitioning: splitting a table into segments

A partitioned table is divided into segments, called partitions, based on the value of one column. When a query filters on that column, BigQuery reads only the matching partitions. This is called partition pruning, and the savings show up in the dry-run estimate before the query even runs.

BigQuery supports three kinds of partitioning.

Time-unit column partitioning

You partition on a DATE, TIMESTAMP or DATETIME column with hourly, daily, monthly or yearly granularity. This is the most common choice for events, logs and transactions, because most analytical queries filter by a date range.

Ingestion-time partitioning

BigQuery assigns rows to partitions based on when they were loaded, exposed through the _PARTITIONTIME and _PARTITIONDATE pseudo-columns. It suits raw landing tables where the source has no reliable timestamp, but late-arriving data ends up in the partition for its load date, not its event date.

Integer-range partitioning

You partition on an INT64 column using a start, end and interval, for example customer IDs in buckets of 10,000. It helps when queries consistently filter on a numeric key, though it is far less common than date partitioning.

Partitions also age independently. A partition that is not modified for 90 consecutive days moves to cheaper long-term storage pricing automatically, which is a quiet saving for append-mostly tables.

Clustering: sorting data inside storage blocks

Clustering sorts the data in a table, or within each partition, by up to four columns. BigQuery stores the sorted data in blocks and keeps metadata about the range of values in each block. When a query filters on the clustering columns, BigQuery skips blocks that cannot contain matching rows. This is called block pruning.

Two details matter in practice:

  • Column order matters. Filters are most effective on the first clustering column, then the second, and so on. Put the column you filter on most often first.
  • Estimates are upper bounds. A dry run cannot know how many blocks will be pruned, so it reports the worst case. The bytes actually billed are often lower.

Clustering works well on high-cardinality columns such as customer_id or sku, where partitioning would create far too many tiny partitions. BigQuery also re-clusters new data automatically in the background at no extra charge.

When to use partitioning, clustering or both

Situation Best fit
Queries almost always filter by a date range Partition by date
Filters on high-cardinality columns such as IDs or SKUs Cluster
You need reliable cost estimates before a query runs Partition
You want to drop or expire old data cheaply Partition
Each daily partition would be very small Cluster, or partition monthly
Queries filter by date and by one or two other columns Partition and cluster

For most large fact tables the answer is both: partition by event date and cluster by the columns that appear most often in WHERE and JOIN clauses. A good rule of thumb is that if daily partitions would each hold only a few hundred megabytes, switch to monthly partitions or rely on clustering alone.

Here is a typical DDL (data definition language) statement for an events table:

CREATE TABLE analytics.events
(
  event_id    STRING NOT NULL,
  event_ts    TIMESTAMP NOT NULL,
  customer_id INT64,
  event_type  STRING,
  country     STRING,
  payload     JSON
)
PARTITION BY DATE(event_ts)
CLUSTER BY customer_id, event_type
OPTIONS (
  require_partition_filter = TRUE,
  partition_expiration_days = 400,
  description = "Product events, partitioned by day, clustered by customer"
);

A query that filters on both the partition column and the first clustering column benefits from both kinds of pruning:

SELECT event_type, COUNT(*) AS events
FROM analytics.events
WHERE event_ts >= TIMESTAMP('2026-01-01')
  AND event_ts <  TIMESTAMP('2026-02-01')
  AND customer_id = 42
GROUP BY event_type;

Guardrails: partition filters, expiration and materialized views

Good table design only helps if queries take advantage of it. BigQuery offers a few settings that enforce good behavior:

  • require_partition_filter: queries that do not filter on the partition column fail instead of scanning the whole table. This one option prevents most accidental full scans.
  • Partition expiration: partition_expiration_days deletes partitions automatically once they pass a given age, keeping storage flat and supporting retention policies.
  • Materialized views: these precompute and store query results, such as daily aggregates, and BigQuery refreshes them incrementally as the base table changes. Eligible queries against the base table can even be rewritten automatically to use the view, which makes them a strong fit for dashboards.
  • Maximum bytes billed: set this on a query or in your client library so that any query exceeding the limit fails before it costs anything.

Common anti-patterns and a quick checklist

Most surprise bills come from a handful of habits:

  • SELECT *: reads every column, including large JSON or STRING fields you may not need. Adding LIMIT generally does not reduce the bytes scanned.
  • Transforming the partition column: a filter that formats or casts the column, like the one below, prevents pruning. With require_partition_filter enabled, BigQuery rejects the query outright.
  • Dynamic filters: a filter such as WHERE event_ts > (SELECT MAX(...) ...) is not a constant, so it can scan every partition. Compute the value first and pass it in as a query parameter.
  • Over-partitioning: hourly partitions on a modest table add metadata overhead and can hit the per-table partition limit.
-- Anti-pattern: the partition column is transformed, so nothing is pruned
SELECT *
FROM analytics.events
WHERE FORMAT_TIMESTAMP('%Y-%m', event_ts) = '2026-01';

Before shipping a new table or scheduled query, run through this checklist:

  • Partition large tables by the date column most queries filter on.
  • Cluster by up to four frequently filtered columns, most used first.
  • Enable require_partition_filter on any table larger than a few gigabytes.
  • Set partition expiration to match your retention policy.
  • Select only the columns you need.
  • Check the bytes estimate with a dry run before scheduling a query.
  • Use materialized views for aggregations that run many times a day.

A dry run from the command line reports the bytes a query would process without running it:

bq query --dry_run --use_legacy_sql=false \
  'SELECT event_type FROM analytics.events
   WHERE event_ts >= TIMESTAMP("2026-01-15") AND event_ts < TIMESTAMP("2026-01-16")'

Key takeaways

  • On-demand BigQuery bills by bytes scanned, so every byte you skip saves money; on editions it saves slot time.
  • Partition by date for predictable pruning, cheap expiration and accurate cost estimates.
  • Cluster by high-cardinality filter columns, ordered by how often you filter on them.
  • Combine both for large fact tables, and enforce good habits with require_partition_filter and maximum bytes billed.
  • Avoid SELECT *, transformed partition filters and dynamic filters, and dry-run queries before scheduling them.
Portrait of Nandha Kumar

Written by

Nandha Kumar

Data Engineer & Full-Stack Developer in Chennai, building data platforms on AWS and Google Cloud.