Skip to main content
Welcome back. This guide expands on BigQuery fundamentals — creating datasets, tables, and views — and walks through materialized views in BigQuery: what they are, when to use them, and how to manage refresh behavior. Materialized views store precomputed query results to speed up repeated queries. They can refresh automatically on a schedule or be refreshed manually when you need immediate, up-to-date results. Prerequisites
  • A BigQuery dataset (this example uses kodekloud-gcp-training.demo_dataset).
  • A base employees table already present in the dataset (used for the materialized view source).
Quick check — view current summary
Create a departments table To demonstrate joining a materialized view with another table, create a simple departments table:
Insert sample department records:
Verify the inserted data:
Relational context Now you have two related tables: employees and departments. This is a classic relational setup where department_id in employees references department_id in departments, enabling joins at query time. Important: materialized view limitations BigQuery materialized views are optimized for performance but have SQL restrictions. They do not support arbitrary joins across multiple base tables or every SQL construct. If you require a precomputed result combining many tables or unsupported SQL, use:
  • a regular view (virtual, computed at query time), or
  • a scheduled query that writes a denormalized table for fast access.
Warning: use materialized views when queries match the supported patterns and when caching precomputed results is beneficial. Create a materialized view (precomputed employees) This example creates a materialized view that precomputes selected columns from the employees table, including department_id so you can join to departments in queries. The materialized view is configured to auto-refresh every 30 minutes.
The materialized view is created. In the BigQuery UI it has a distinct icon that differentiates materialized views from regular views and tables:
A screenshot of the Google Cloud BigQuery console showing a dataset tree (demo_dataset) with tables like departments, employee_department_view (highlighted), employee_summary, and employees. The employee_department_view row is selected and outlined in red.
Query the materialized view Run a simple query against the materialized view to read the precomputed results:
Join the materialized view with departments If you need department metadata (name, budget), join the materialized view with the departments table at query time:
Materialized view metadata & benefits BigQuery displays metadata for materialized views (for example, row counts and logical bytes stored). Materialized views store logical results and can reduce both query cost and latency for repeated queries that match the materialized query pattern. Table — Materialized view vs Regular view (summary) Refresh behavior — demo and manual refresh
  • Automatic refresh: materialized view results refresh automatically on the configured interval (30 minutes in this example).
  • Manual refresh: you can force an immediate refresh to ensure the materialized view reflects the latest base-table changes.
  1. Check current values for an employee (example: employee_id = 1):
  1. Update the base employees table (for example, change salary):
  1. If you query the materialized view immediately, it may still show the previous salary until the next automatic refresh. Force an immediate refresh:
  1. Re-run the SELECT to validate the refresh:
After the forced refresh, the materialized view should show the updated salary (85,000).
Materialized views are useful for precomputing and accelerating common queries. They have limitations (for example, not all SQL constructs or non-deterministic functions are supported). You can rely on scheduled refresh intervals or trigger refreshes (for example, from Airflow or other orchestration tools) when you need up-to-date results.
References and further reading That concludes this demo on BigQuery materialized views. See you in the next lesson.

Watch Video