Request a demo

BigQuery · DDL statement

BigQuery CREATE MATERIALIZED VIEW

CREATE MATERIALIZED VIEW stores the result of an aggregation over a BigQuery table and keeps it current automatically. Queries read the small precomputed result plus recent changes instead of rescanning the base table, cutting cost for dashboards that repeat the same GROUP BY.

GoogleSQL for BigQuery · Checked against the official reference in November 2026

A materialized view is a query whose result BigQuery stores and maintains for you. By default it is incremental: each refresh processes only the changes to the base table since the last refresh. When you query the view, BigQuery combines the stored result with any changes since that refresh, so results are always current. With smart tuning, BigQuery also rewrites queries against the base table to read the view instead, as long as the view contains every column and row the query needs. Querying the view directly always uses it.

Refresh is automatic unless you set enable_refresh = FALSE. BigQuery tries to start a refresh within 5 minutes of a base table change, but no more often than refresh_interval_minutes (default 30, allowed from 1 minute to 7 days), and only on a best-effort basis: refreshes run like batch queries and wait when the project has no capacity. You can refresh at any time with CALL BQ.REFRESH_MATERIALIZED_VIEW('project.dataset.view'). Appends to the base table refresh incrementally. UPDATE, DELETE, MERGE, truncation and partition expiration on the base table invalidate the stored data, and until the next refresh queries fall back to reading the base table. In a partitioned view only the affected partitions are invalidated, which is a good reason to partition the view the same way as the base table.

Incremental views accept a restricted query: SELECT, FROM, WHERE, GROUP BY and inner joins, with aggregates such as COUNT, COUNTIF, SUM, AVG, MIN, MAX, APPROX_COUNT_DISTINCT, ANY_VALUE, ARRAY_AGG, LOGICAL_AND/LOGICAL_OR and MAX_BY/MIN_BY. Aggregates must be outputs, so COUNT(*) / 10 or a filter on an aggregate is rejected. Window functions, RIGHT and FULL outer joins, self-joins, UDFs, TABLESAMPLE, FOR SYSTEM_TIME AS OF and non-deterministic functions such as CURRENT_DATE() are not allowed; LEFT JOIN and UNION ALL are in Preview. For anything else, set allow_non_incremental_definition = TRUE together with max_staleness: the view then accepts most SQL, but every refresh recomputes it in full and smart tuning no longer applies. You cannot change a view's query after creation (use CREATE OR REPLACE), write to it with DML, or build a materialized view on top of another one.

You pay for three things: refreshes (bytes processed on demand, or slots), storage of the view, and queries, which read the view plus whatever part of the base table has changed since the last refresh. Automatic refreshes are billed to the view's project and run as the bigquery-adminbot@system.gserviceaccount.com service account, so they show up in that project's job history. max_staleness (30 minutes to 3 days) lets queries on the view skip the base table entirely while the last refresh is recent enough. On reservations, Standard edition can only query existing materialized views; creating them, automatic refresh and smart tuning need Enterprise, Enterprise Plus or on-demand pricing.

Syntax

CREATE [OR REPLACE] MATERIALIZED VIEW [IF NOT EXISTS] view_name
[PARTITION BY partition_expression]
[CLUSTER BY column[, ...]]
[OPTIONS (
  enable_refresh = { TRUE | FALSE },
  refresh_interval_minutes = n,
  max_staleness = INTERVAL ...,
  allow_non_incremental_definition = { TRUE | FALSE }, ...)]
AS query_expression

ALTER MATERIALIZED VIEW view_name SET OPTIONS (option = value[, ...])

CALL BQ.REFRESH_MATERIALIZED_VIEW('project.dataset.view_name')

Arguments and return value

ArgumentDescription
PARTITION BYAllowed only when the base table is partitioned, on the same partitioning column with the same granularity. The column can be a finer truncation of the base column, such as TIMESTAMP_TRUNC(ts, HOUR) over a table partitioned by DATE(ts). The view inherits the base table's partition expiration.
CLUSTER BYUp to four output columns of the view. Aggregate outputs cannot be clustering columns.
enable_refreshBOOL, default TRUE. FALSE stops automatic refresh; you can still refresh manually.
refresh_interval_minutesFLOAT64, default 30. The minimum time between automatic refreshes, from 1 minute to 7 days.
max_stalenessINTERVAL between 30 minutes and 3 days, disabled by default. Queries on the view return stored data without reading the base table while the last refresh is within this interval.
allow_non_incremental_definitionBOOL, default FALSE, settable only at creation. TRUE accepts most SQL (outer joins, HAVING, window functions) but requires max_staleness, recomputes the whole view on each refresh and disables smart tuning.

Returns: A materialized view: stored, automatically maintained query results that can be queried like a table and used to answer matching queries on the base table.

Examples

Hourly revenue per store, partitioned like the base table

orders is partitioned by DATE(order_ts). The view truncates the timestamp to the hour and partitions by its date, so a DELETE in one day of orders invalidates only that day of the view.

CREATE MATERIALIZED VIEW `project.dataset.hourly_revenue_mv`
PARTITION BY DATE(order_hour)
CLUSTER BY store_id
OPTIONS (enable_refresh = TRUE, refresh_interval_minutes = 60)
AS
SELECT
  TIMESTAMP_TRUNC(order_ts, HOUR) AS order_hour,
  store_id,
  COUNT(*) AS orders,
  SUM(amount) AS revenue
FROM `project.dataset.orders`
GROUP BY order_hour, store_id;

Read the view from a dashboard query

Re-aggregating the hourly rows is cheap: the scan covers the view's November partitions, not the raw orders. The same question asked of orders is rewritten to use the view only if every column and filter is an output of the view, for example a filter on TIMESTAMP_TRUNC(order_ts, HOUR) rather than on order_ts.

SELECT
  store_id,
  SUM(orders) AS orders,
  SUM(revenue) AS revenue
FROM `project.dataset.hourly_revenue_mv`
WHERE order_hour >= '2026-11-01'
GROUP BY store_id
ORDER BY revenue DESC;

Slow down refreshes and refresh by hand

For a report read twice a day, a 4-hour refresh cap and an 8-hour staleness window keep refresh cost down and let queries skip the base table. The CALL refreshes immediately and is billed to the project that runs it.

ALTER MATERIALIZED VIEW `project.dataset.hourly_revenue_mv`
SET OPTIONS (
  refresh_interval_minutes = 240,
  max_staleness = INTERVAL "8:0:0" HOUR TO SECOND
);

CALL BQ.REFRESH_MATERIALIZED_VIEW('project.dataset.hourly_revenue_mv');

A non-incremental view for a query incremental views reject

HAVING is not allowed in an incremental view. With allow_non_incremental_definition it works, but every refresh reruns the whole query over orders, so the refresh interval directly sets the cost.

CREATE MATERIALIZED VIEW `project.dataset.high_value_customers_mv`
OPTIONS (
  enable_refresh = TRUE,
  refresh_interval_minutes = 720,
  max_staleness = INTERVAL "24:0:0" HOUR TO SECOND,
  allow_non_incremental_definition = TRUE
)
AS
SELECT customer_id, SUM(amount) AS lifetime_value
FROM `project.dataset.orders`
GROUP BY customer_id
HAVING SUM(amount) > 10000;

Common mistakes

  • Computing on an aggregate inside an incremental view. SUM(amount) / COUNT(*) AS avg_order or COUNT(*) / 10 is rejected; store SUM(amount) and COUNT(*) and divide when you query the view.
  • Using CURRENT_DATE() to keep the view to a rolling window. Non-deterministic functions are not allowed. Store all dates in the view, or let partition expiration on the base table trim it, and filter by date when you query.
  • Running frequent UPDATE, DELETE or MERGE on the base table of an unpartitioned view. Each change invalidates the whole view, so queries read the base table until the next full refresh and you pay for both. Partition the view like the base table so only touched partitions are invalidated.
  • Expecting a filter on the raw column to be rewritten to the view. Smart tuning needs every column and filter to be an output of the view: a view that outputs DATE(order_ts) is not used by a query filtering on order_ts.
  • Forgetting that require_partition_filter on the base table also applies to queries on the view: they fail with Cannot query over table without a filter that can be used for partition elimination unless they filter on the partitioning column.

Cost and performance

  • Refresh cost is the hidden line item. An incremental refresh processes only rows appended since the last one, but a non-incremental view reruns its whole query on every refresh, and UPDATE, DELETE or MERGE on the base table forces the affected data to be recomputed (all of it if the view is unpartitioned). Refresh jobs run as bigquery-adminbot@system.gserviceaccount.com in the view's project, so you can find them in INFORMATION_SCHEMA.JOBS.
  • Between refreshes, queries read the view plus the base table changes since the last refresh. With a long refresh_interval_minutes on a busy table, that delta grows and so does query cost; max_staleness caps it by serving stored results while they are fresh enough.
  • For AVG, ARRAY_AGG and APPROX_COUNT_DISTINCT, the view stores an intermediate sketch rather than the final value, and storage is calculated on that sketch as BYTES, not on the NUMERIC or FLOAT64 the column shows.

FAQ

How often does a BigQuery materialized view refresh?

By default BigQuery starts a refresh within 5 minutes of a base table change, but no more than once every 30 minutes (refresh_interval_minutes). It is best effort. Run CALL BQ.REFRESH_MATERIALIZED_VIEW(...) to refresh immediately.

What is the difference between a view and a materialized view in BigQuery?

A view stores only SQL and reruns it, with full cost, on every query. A materialized view stores the result, keeps it current incrementally and can answer queries on the base table, at the price of refresh and storage costs and a restricted query syntax.

Can a BigQuery materialized view use a LEFT JOIN or a window function?

Incremental views allow inner joins; LEFT JOIN and UNION ALL are in Preview. Window functions, outer joins and HAVING need allow_non_incremental_definition = TRUE with max_staleness, which turns every refresh into a full recompute.

Who pays for materialized view refreshes?

Automatic refreshes are billed to the project that contains the view; a manual BQ.REFRESH_MATERIALIZED_VIEW call is billed to the project that runs it.

Errors you may hit

More DDL statements

All BigQuery DDL statements · All statements and clauses · BigQuery error messages

Observability for every BigQuery table, in about 15 minutes

Masthead detects freshness, volume and schema anomalies, monitors pipeline errors and maps column-level lineage across all your projects, from logs and metadata only.