Google Cloud Tutorial · Storage, Databases and Analytics · Lesson 21 of 27
BigQuery
BigQuery for analytics: datasets and tables, how queries are billed, partitioning and clustering, and controlling cost.
Serverless analytics
BigQuery stores data in columnar tables inside datasets and runs SQL over terabytes in seconds without servers to manage. Storage and compute are separate: you pay for data stored and for the compute your queries use.
SELECT DATE(ordered_at) AS day, SUM(total) AS revenue
FROM `acme-analytics.sales.orders`
WHERE ordered_at >= TIMESTAMP('2026-11-01')
GROUP BY day
ORDER BY day;
How queries are billed
- On-demand: per byte scanned (the first 1 TiB per month is free).
- Capacity (editions): you buy slots (compute capacity) and queries use them.
Because columns are stored separately, SELECT * reads every column, and LIMIT doesn't reduce what's scanned.
Partitioning and clustering
Partitioning splits a table by date (or integer range) so queries filtering on that column only scan matching partitions. Clustering sorts data within partitions by chosen columns, so filters on them read less.
table_gb_per_day = 40
days = 730 # two years of data
columns, used_columns = 30, 4
price_per_tib = 6.25 # on-demand list price in many regions
def cost(scanned_gb):
return scanned_gb / 1024 * price_per_tib
full = table_gb_per_day * days
print(f"SELECT * over everything: {full:8,.0f} GB ${cost(full):6.2f}")
cols = full * used_columns / columns
print(f"Only the 4 needed columns: {cols:8,.0f} GB ${cost(cols):6.2f}")
pruned = table_gb_per_day * 30 * used_columns / columns
print(f"...on a date-partitioned table, 30 d: {pruned:8,.0f} GB ${cost(pruned):6.2f}")
Output
SELECT * over everything: 29,200 GB $178.22 Only the 4 needed columns: 3,893 GB $ 23.76 ...on a date-partitioned table, 30 d: 160 GB $ 0.98
Also: preview the bytes a query will scan (a dry run), set maximum bytes billed, and use materialised views for dashboards that repeat the same query.
Test yourself
A query on an unpartitioned table uses LIMIT 10. How much data does on-demand billing charge for?
Only the 10 rows returnedEvery byte in the columns the query reads, regardless of LIMITNothing; small queries are freeOnly the first partition
Show answer
Answer: Every byte in the columns the query reads, regardless of LIMIT
LIMIT is applied after scanning; select fewer columns and partition to scan less.