All BigQuery cost anti-patterns

Querying a partitioned table without a partition filter

A partitioned table with no filter on its partition column scans every partition — usually the single largest avoidable cost in a BigQuery estate.

What it is

Partitioning splits a table into segments that can be skipped. Skipping only happens when the query filters on the partition column. Without that filter you pay for every partition ever written.

Why it costs money

  • Partitioned tables are usually the big ones — that is why someone partitioned them — so the mistake is expensive precisely where it hurts most.
  • The cost grows silently as the table accumulates history. The query that cost $2 last year costs $30 today with no change to the SQL.
  • It is invisible in testing: on a small dev table with 5 partitions, the missing filter costs nothing.

Worked example

Expensive
SELECT user_id, SUM(revenue)
FROM `analytics.orders`
GROUP BY user_id
Cheaper
SELECT user_id, SUM(revenue)
FROM `analytics.orders`
WHERE order_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY)
GROUP BY user_id
The arithmetic. On a table with 1,095 daily partitions averaging 3 GiB each, the unfiltered query bills ~3.2 TiB ($20). Thirty days bills ~90 GiB ($0.55) — 36× cheaper for the answer people usually wanted anyway.

How to fix it

  1. 1Add a filter on the partition column with a constant, or an expression of constants such as DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY).
  2. 2Set require_partition_filter = true on the table. Then the next person gets an error instead of a bill, which is the only fix that survives staff turnover.
  3. 3Check the pruning worked: a dry run should report far fewer bytes than the table's total logical size.
The analyzer detects this one. Paste your query into the BigQuery Query Cost Analyzer and it will point at the exact line.

Fixing one query is satisfying. Fixing the pattern is the win.

Finitizer finds every instance of this across your BigQuery job history, ranks them by what they actually cost, and keeps checking after you have fixed them.