What cuts a BigQuery bill on a dbt model of web analytics events
On three dated held-out queries, the one-line date filter cut scanned data by a median 80%, against 87% before.
What was tested
The first six queries picked the winner. A fair test needs queries that played no part in that. Four more were written and frozen in the design, before any query ran. They were run once the first results were in, three times each with the cache off, on the same layouts.
The test applied the two best changes where they fit without a new model: the one-line date filter and the table copy. The rule, set in advance: the filter's gain holds if its median saving on these queries is at least half its median on the first six.
The result
It held. The filter saved a median 80%, against 87% before, a ratio of 0.92. The bar was 0.5. Slot time fell 48% to 80%.
Share of bytes billed saved by the filter, median of 3 runs
The table copy held too: a median 86% against 87% before.
- New against returning users by week, all 92 days: the filter does not apply, the table copy 92%.
- Revenue per session by landing page, last 30 days: the filter saved 74%, the table copy 68%.
- Add-to-cart rate by item category, last 21 days: the filter saved 80%, the table copy does not apply.
- Daily engaged sessions by country, last 7 days: the filter saved 94%, the table copy 86%.
The weekly new-against-returning query reads every day, so the filter has nothing to skip. The add-to-cart query reads the items view, which has no table copy.
Every held-out query gave the same answer on every layout.
Every held-out run
Bytes billed, slot time and elapsed time, median of three runs per layout.
| Query | Layout | MiB billed | Slot seconds | Elapsed seconds |
|---|---|---|---|---|
| New against returning users by week, all 92 days | Staging view, as built | 1,472 | 68.02 | 3.52 |
| Copied into a table | 118 | 6.38 | 0.80 | |
| Table partitioned by date | 118 | 2.23 | 0.59 | |
| Partitioned and clustered by event name | 118 | 1.96 | 0.47 | |
| Revenue per session by landing page, last 30 days | Staging view, as built | 1,558 | 32.91 | 3.28 |
| Same view, one-line date filter | 410 | 17.18 | 1.51 | |
| Copied into a table | 498 | 8.79 | 0.88 | |
| Table partitioned by date | 136 | 2.77 | 0.39 | |
| Partitioned and clustered by event name | 136 | 3.08 | 0.36 | |
| Add-to-cart rate by item category, last 21 days | Staging view, as built | 171 | 3.18 | 2.06 |
| Same view, one-line date filter | 34 | 0.93 | 0.89 | |
| Daily engaged sessions by country, last 7 days | Staging view, as built | 1,520 | 21.04 | 2.60 |
| Same view, one-line date filter | 92 | 4.27 | 1.06 | |
| Copied into a table | 210 | 1.66 | 0.25 | |
| Table partitioned by date | 14 | 0.26 | 0.16 | |
| Partitioned and clustered by event name | 14 | 0.23 | 0.14 |
Limits
Four queries is a small test. They come from the same model and the same 92 days, so they test whether the gain carries to new questions, not to new data. The marts did not carry: each was built for its own tile.
The held-out queries were written with the first six, and their date ranges, 7 to 30 days, are like theirs. The filter's cut is roughly the share of days a query skips, so a query reading more of the history would gain less. So the filter's result here confirms that arithmetic on new questions. It is not independent evidence: a test on a longer history would be. The table copy's gain does not depend on the range.