Overview
CREATE MATERIALIZED VIEW defines a view that persists results in durable storage and incrementally updates them as new data arrives. Materialized views are the primary mechanism for transforming and maintaining derived data in Materialize.Syntax
Key Features
Incremental Maintenance
Materialized views are automatically and incrementally updated as source data changes:order_totals updates incrementally without recomputing from scratch.
Cross-Cluster Access
Materialized views can be queried from any cluster:- Separate maintenance compute from query compute
- Share results across multiple query clusters
- Optimize resource allocation
Durable Storage
Results are persisted in durable storage:- Survives cluster restarts
- No memory limitations
- Can handle arbitrarily large result sets
Parameters
Name of the materialized view to create
Cluster where the view will be maintained. Defaults to the active cluster.
The query defining the view’s contents
Refresh Strategies
By default, materialized views use REFRESH ON COMMIT (incremental maintenance). For specific use cases, you can configure alternative refresh strategies.Refresh On Commit (Default)
Views update continuously as data arrives:Refresh At Specific Times
Schedule refreshes at specific timestamps:Refresh Every Interval
Schedule periodic refreshes:Scheduled refresh strategies should only be used for specific reporting use cases over slow-changing data. For most workloads, use the default incremental maintenance.
Non-Null Assertions
Force columns to be non-nullable when Materialize can’t infer it:Indexing Materialized Views
For faster queries, create indexes on materialized views:Indexes are cluster-local. Create indexes in each cluster where you query the view.
Examples
Basic Aggregation
Join Multiple Sources
Window Functions
Time-Based Aggregation
Temporal Filter
Materialized Views vs Views vs Indexes
| Feature | Materialized View | View + Index | View (no index) |
|---|---|---|---|
| Storage | Durable storage | Memory (cluster-local) | None |
| Cross-cluster | Yes | No | No |
| Updates | Incremental | Incremental | None (computed on read) |
| Best for | Shared results, sinks | Fast queries in one cluster | Query aliases |
Best Practices
-
Use Materialized Views For:
- Results shared across clusters
- Data exported to sinks
- Results larger than memory
- Expensive transformations used by multiple queries
-
Avoid Materialized Views When:
- Results only queried in one cluster (use indexed view instead)
- Results are small and latency is critical (use indexed view)
- Query is only run occasionally (use ad hoc query)
-
Optimize Performance:
- Create indexes on frequently filtered columns
- Use appropriate cluster sizes for maintenance
- Monitor memory and disk usage
-
Consider Refresh Strategies:
- Use default incremental maintenance for most cases
- Use scheduled refreshes only for reporting on archival data
- Configure hydration time estimates for scheduled clusters