A materialized view is an entity that contains both computation logic and data. Unlike a regular view, which only stores computation logic without data, a materialized view refreshes data periodically or in real time according to a policy. It can be queried directly, and it can also transparently rewrite queries.
Before choosing and using a materialized view, confirm the following questions:
The following sections address these questions one by one.
A materialized view computes and stores data based on its SQL definition, and updates the data periodically or in real time according to a policy. It can be queried directly, and it can also transparently rewrite queries. Common use cases include:
In decision support systems (such as BI reports and ad-hoc queries), analytical queries usually contain aggregation operations and may also involve multi-table joins.
In data layering scenarios, you can use nested materialized views to build the DWD and DWM layers, and use the scheduled refresh capability of materialized views to replace some ETL tasks.
For various external data sources, you can build materialized views on the tables they use, so that you can:
Materialized views can be classified along three dimensions: data freshness, SQL pattern, and refresh method.
| Category | Data Consistency | Typical Freshness | Direct Query Support | Applicable Scenarios |
|---|---|---|---|---|
| Synchronous materialized view | Strongly consistent with base | Real-time | Not supported | Scenarios with high freshness requirements |
| Asynchronous materialized view | Eventually consistent with base | T+1 / hourly | Supported | General analytical scenarios with looser freshness |
Selection guidance:
The defining SQL of a materialized view can be either a single-table query or a multi-table query. Based on the number of tables used, materialized views can be divided into single-table materialized views and multi-table materialized views:
Different categories of materialized views support different refresh methods:
| Materialized View Type | Full Refresh | Partition-Incremental Refresh | Real-Time Refresh |
|---|---|---|---|
| Asynchronous materialized view | Supported | Supported | Not supported |
| Synchronous materialized view | - | - | Supported |
Meaning of each refresh method: