Back to Chapters
Chapter Progress: 0 %0 / 5 Lessons Read
‹›

2. Fast and cheap tables: partitions, clusters and nested data

2.1 Partitioning: one drawer for each day

Highlights & notes

Select lesson text to highlight it, or tap Add note.

    Bookmarks

    Bookmark a lesson to see it here.

      A school office keeps attendance in one drawer per month. To check March, the clerk opens only the March drawer. A partitioned table works the same way. BigQuery splits the table into parts using a date column.

      When your query filters on that column, BigQuery opens only the matching parts and skips the rest. This skipping is called pruning. Less data read means a faster and cheaper query.

      You can partition by:

      • a DATE, TIMESTAMP or DATETIME column. One part per day is the usual choice.
      • the time the row was loaded, called ingestion time
      • a range of whole numbers

      A table can have up to 10,000 partitions. With one partition per day, that covers about 27 years.

      Without and with partitions

      • No partitions: a query for one day reads all days
      • Partitioned by order_date: a query for one day reads one day
      • The filter must be on the partition column itself: WHERE order_date = '2026-01-06'
      Must Know:

      On big tables add OPTIONS (require_partition_filter = TRUE). BigQuery then refuses any query that forgets the date filter, so nobody scans three years of data by mistake.

      How it fits together

      1. Table: orders
      2. Split by order_date
      3. Query opens 1 day only

      Watch pruning happen

      The first statement makes a partitioned copy. The second one reads it.

      SQL

      CREATE TABLE sales.orders_pPARTITION BY order_date ASSELECT * FROM sales.orders;SELECT order_id, amountFROM sales.orders_pWHERE order_date = '2026-01-06';

      Rows at this step

      order_id | amount
      ---------+-------
      102      | 700

      Try it yourself

      1. Run the first statement of the walkthrough to create sales.orders_p.
      2. Type SELECT * FROM sales.orders_p and note the bytes in the dry run.
      3. Add WHERE order_date = '2026-01-06'. The bytes drop, because only one partition is read.

      Question 1 · Easy

      What does a partitioned table do?

      Question 2 · Medium

      orders is partitioned by order_date. Which filter lets BigQuery skip partitions?

      Question 3 · Hard

      What does require_partition_filter = TRUE do?

      Key takeaways

      A partitioned table is split by a date (or number) column. A filter on that column reads only the matching partitions. Add require_partition_filter on big tables.

      Lesson 6 of 90

      Save your progress

      Start free and your progress, code and notes stay saved. Free for 1 month, no card needed.

      Start free Log in
      PreviousPartitioning: one drawer for each day
      Save your progress free for 1 month. Start free · Log in