What a query costs
You want to know what a query will cost before you run it. BigQuery gives you that number up front, and it is easy to read once you know what it counts.
How it works
BigQuery stores each column of a table separately. A query reads the columns its result depends on, from the partitions its date filter allows, and the on-demand price follows the bytes it processes. The editor shows an estimate of that number before you run anything.
- A column counts when the result depends on it: it is used in
SELECT,WHERE,JOINorORDER BY. fact_mot_testhas one partition for each month ofcompleted_date, andcompleted_datecounts as a column when a filter names it.- A
learn.mottable drawn from the real MOT data is scaled, so a query on it shows the bytes it would read on the full data rather than on the sample in your browser. The one exception israw_mot_intake. It holds eight hand-written rows that stand for no larger table, so a query on it reads a few hundred bytes. - The estimate comes before the run. The bytes you are billed for are reported with the job after it. A real run bills each table it reads at least 10 MiB, and a run answered from the cache bills nothing.
- Other BigQuery habits are taught in other tracks: backticked table paths in Basics,
QUALIFYin Window functions, andSAFE_functions andCASTin Dates and strings.
Common mistake
A fast query can still read a lot of data, and a slow one can read very little. The clock says little about the bill, so compare byte estimates before you run.
Worked example
SELECT COUNT(DISTINCT vehicle_id) AS vehicles
FROM `learn.mot.fact_mot_test`
WHERE completed_date BETWEEN '2024-03-01' AND '2024-03-31'The query names two columns, vehicle_id and completed_date.
The filter selects the March 2024 partition, so those two columns of that one month are what the estimate counts.