- A BigQuery dataset (this example uses
kodekloud-gcp-training.demo_dataset). - A base
employeestable already present in the dataset (used for the materialized view source).
departments table:
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.
employees table, including department_id so you can join to departments in queries. The materialized view is configured to auto-refresh every 30 minutes.

departments table at query time:
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.
- Check current values for an employee (example:
employee_id = 1):
- Update the base
employeestable (for example, change salary):
- If you query the materialized view immediately, it may still show the previous salary until the next automatic refresh. Force an immediate refresh:
- Re-run the SELECT to validate the refresh:
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.- BigQuery documentation: https://cloud.google.com/bigquery/docs
- BigQuery materialized views: https://cloud.google.com/bigquery/docs/materialized-views
- Apache Airflow: https://airflow.apache.org/