Glossary · BigQuery
What is materialized view?
A BigQuery materialized view stores the precomputed result of a query, usually an aggregation, and keeps it up to date with incremental refreshes. Queries read the small stored result plus recent changes instead of the base table, which cuts bytes and slots for repeated dashboard queries.
How materialized views work
A materialized view is defined by a query over one or more base tables. BigQuery stores the result and, after changes to the base tables, refreshes it incrementally in the background. When you query it, BigQuery reads the stored result and only the base-table changes since the last refresh, so results are fresh even between refreshes.
CREATE MATERIALIZED VIEW analytics.daily_revenue_mv
OPTIONS (enable_refresh = TRUE, refresh_interval_minutes = 60)
AS
SELECT
DATE(created_at) AS order_date,
country,
COUNT(*) AS orders,
SUM(amount) AS revenue
FROM analytics.orders
GROUP BY order_date, country;
Incremental materialized views support a limited set of SQL: aggregates such as COUNT, SUM, AVG, MIN, MAX, COUNTIF and APPROX_COUNT_DISTINCT, but no window functions, self-joins, UDFs or non-deterministic functions such as CURRENT_DATE(), and you cannot change the query after creation. Non-incremental views (allow_non_incremental_definition = true) accept more SQL but rerun the whole query on every refresh. With smart tuning, BigQuery can rewrite queries against the base table to read an incremental materialized view instead, without changing the query. Syntax is on CREATE MATERIALIZED VIEW.
What it does to the bill
A materialized view moves cost from every query to the refresh:
- Queries bill the bytes (on demand) or slots (editions) of the view plus the base-table changes they read.
- Refreshes bill bytes or slots too. Automatic refreshes are charged to the project that holds the view.
- Storage is billed like any table.
The saving is largest for small aggregates over large tables that many queries repeat. If a dashboard fires 2,000 queries a day that each scan 5 GiB of an orders table, that is about 9.8 TiB, or $61 a day on demand. Served from a 1 GiB aggregate, the same queries scan a fraction of that, plus the refreshes. A view that is refreshed often but rarely queried does the opposite and only adds cost.
See refresh cost in INFORMATION_SCHEMA
Automatic refreshes run as bigquery-adminbot@system.gserviceaccount.com and appear in the view's project job history, so INFORMATION_SCHEMA.JOBS shows what they cost:
SELECT
DATE(creation_time) AS day,
COUNT(*) AS refresh_jobs,
ROUND(SUM(total_bytes_billed) / POW(1024, 3), 1) AS gib_billed,
ROUND(SUM(total_slot_ms) / 3600000, 2) AS slot_hours
FROM `region-us`.INFORMATION_SCHEMA.JOBS
WHERE creation_time >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 14 DAY)
AND user_email = 'bigquery-adminbot@system.gserviceaccount.com'
GROUP BY day
ORDER BY day DESC;
INFORMATION_SCHEMA.MATERIALIZED_VIEWS adds last_refresh_time and last_refresh_status, which is set when the last automatic refresh failed. Compare refresh cost with how often each view is actually queried before keeping it.
Pitfalls
- Deleting and recreating a base table breaks the view: queries and refreshes fail until you recreate the view too.
- Materialized views cannot be nested and cannot read external tables (except BigLake), wildcard tables or snapshots.
- A low
refresh_interval_minuteson a busy base table means many refresh jobs; raise it when the view does not need minute-level freshness. - BI Engine only accelerates a materialized view when both the view and its base tables are preferred tables.
FAQ
What is the difference between a view and a materialized view in BigQuery?
A logical view stores only SQL and runs it against the base tables every time it is queried. A materialized view stores the result and refreshes it, so queries read far less data, but it supports a narrower set of SQL and adds storage and refresh costs.
How often does a BigQuery materialized view refresh?
With automatic refresh on (the default), BigQuery tries to refresh within 5 minutes of a base table change, but no more often than the frequency cap, 30 minutes by default and configurable from 1 minute to 7 days. Refresh is best effort, and queries still return fresh results by reading recent changes from the base table.
Can I create materialized views on BigQuery Standard edition?
No. Standard edition reservations can only query existing materialized views. Creating them, automatic and manual refresh, and smart tuning need Enterprise or Enterprise Plus.
