Skip to main content

Materialized View Overview

A materialized view stores the results of a query so that later queries can reuse the computation. In VeloDB Cloud, synchronous materialized views are maintained with the base table, while asynchronous materialized views refresh according to a policy. The optimizer can use eligible views to accelerate queries on the base tables. You can also query an asynchronous materialized view directly.

Choose a materialized view​

Before choosing and using a materialized view, consider these questions:

  • What problem do you want to solve? Query acceleration, data modeling, or lakehouse acceleration?
  • How strict are the data freshness requirements? Do you need strong consistency or eventual consistency?
  • Does the defining SQL involve a single table or multiple tables?
  • Do you want the refresh to be full, partition-incremental, or real-time?

Materialized views use additional storage and compute. Synchronous views add work to writes, and asynchronous views consume compute during refresh. Retain views that benefit your workload and drop views you no longer use.

Use cases for materialized views​

Common use cases include query acceleration, data modeling, and accelerating queries on external data.

Query acceleration​

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.

  • Computing joins and aggregations repeatedly consumes compute resources.
  • Materialized views can precompute results used by common queries.
  • The benefit depends on query patterns, view definitions, data volume, and refresh cost.

Lightweight ETL (data modeling)​

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.

Lakehouse​

For various external data sources, you can build materialized views on the tables they use, so that you can:

  • Reuse an asynchronously refreshed result in the warehouse instead of repeatedly reading and computing the same external data.
  • Accelerate queries on external data sources.

Materialized view types​

Materialized views can be classified along three dimensions: data freshness, query structure, and refresh method.

Data freshness: synchronous and asynchronous​

CategoryData consistencyTypical freshnessQuery methodApplicable scenarios
Synchronous materialized viewConsistent with the base tableUpdated with writesQuery the base tableSingle-table queries that require current data
Asynchronous materialized viewReflects the last successful refreshDepends on refresh policy and durationQuery the view directlyQueries that can tolerate refresh latency

Selection guidance:

  • High freshness requirements: choose synchronous materialized views.
  • Freshness requirements are not high and some delay is acceptable: choose asynchronous materialized views.

Query structure: single table and multiple tables​

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:

  • Asynchronous materialized views: support both single-table and multi-table.
  • Synchronous materialized views: support only single-table.

Refresh method: full, partition incremental, and synchronous​

Different categories of materialized views support different refresh methods:

Materialized view typeFull refreshPartition-incremental refreshSynchronous maintenance
Asynchronous materialized viewSupportedSupportedNot supported
Synchronous materialized view--Supported

Meaning of each refresh method:

  • Full refresh (asynchronous): computes all the data of the materialized view's defining SQL.
  • Partition-incremental refresh (asynchronous): for eligible definitions and data sources, identifies affected view partitions when base-table partitions change and recomputes those partitions. This refreshes whole affected partitions, rather than applying only changed rows. See the asynchronous materialized view overview for source and partition requirements.
  • Synchronous maintenance: updates the view together with the base table as data is written. This is different from running a separate refresh job.

See also​