The maximum number of partitions per table in BigQuery has increased from 4,000 to 10,000. Partitioned tables in BigQuery are divided into segments called partitions, which improve query performance and reduce costs by scanning only relevant parts of the data. There are three types of partitions:
Types of Partitions
Integer Range Partitioning
- Partitions based on ranges of integer values in a specified column.
Time-Unit Column Partitioning
- Partitions based on
DATE
,TIMESTAMP
, orDATETIME
columns. - Granularity can be
HOUR
,DAY
,MONTH
, orYEAR
.
- Partitions based on
Ingestion Time Partitioning
- Partitions based on the time when data is ingested into BigQuery.
- Granularity can be
HOUR
,DAY
,MONTH
, orYEAR
. - Adds pseudocolumns
_PARTITIONTIME
and_PARTITIONDATE
.
When to Use Partitioning
- Improve query performance by scanning only a portion of a table.
- Exceed standard table quotas by scoping operations to specific partition column values.
- Determine query costs before execution using query cost estimates.
- Utilize partition-level management features like setting expiration times, writing data to specific partitions, or deleting specific partitions.
When to Use Clustering Instead
- Need more granularity than partitioning allows.
- Queries commonly use filters or aggregation against multiple columns.
- High cardinality of values in a column or group of columns.
- No need for strict cost estimates before query execution.
- Small amount of data per partition (less than 10 GB).
- Large number of partitions exceeding limits.
- Frequent DML operations modifying most partitions.
Combining Clustering and Partitioning
Combining table partitioning with clustering achieves finer-grained sorting and query optimization. Data is first segmented into partitions and then clustered within each partition based on user-defined sort properties.
Partition Decorators
Partition decorators allow referencing a specific partition in a table. Formats vary by partitioning type:
- Hourly:
yyyymmddhh
- Daily:
yyyymmdd
- Monthly:
yyyymm
- Yearly:
yyyy
- Integer range:
range_start
Limitations
- Cannot use legacy SQL for partitioned tables.
- Only one column can be used for partitioning.
- Specific limitations for time-unit and integer-range partitioned tables regarding column types and field levels.
Quotas, Limits, and Pricing
Partitioned tables have defined limits and quotas for various operations like loading, exporting, querying, and copying data. Charges are based on data storage and queries run against the data. Many partitioned table operations are free but subject to quotas and limits.
Table Security
Access control for partitioned tables is the same as for standard tables. For more information, see the relevant BigQuery documentation.