Implementation:Risingwavelabs Risingwave Handle Create Mv
| Knowledge Sources | |
|---|---|
| Domains | Streaming, Query_Processing, SQL_DDL |
| Last Updated | 2026-02-09 07:00 GMT |
Overview
Concrete tool for creating incrementally-maintained materialized views in RisingWave provided by the frontend SQL handler.
Description
The handle_create_mv function is the SQL DDL handler for CREATE MATERIALIZED VIEW statements. It binds the SQL query using the streaming binder, resolves dependent relations and UDFs, then delegates to handle_create_mv_bound which optimizes the query into a streaming plan and deploys it as a streaming job on compute nodes.
Usage
This handler is invoked when a user executes a CREATE MATERIALIZED VIEW ... AS SELECT statement. The resulting materialized view is continuously updated as new data arrives at its source relations.
Code Reference
Source Location
- Repository: risingwave
- File: src/frontend/src/handler/create_mv.rs
- Lines: L158-186
Signature
pub async fn handle_create_mv(
handler_args: HandlerArgs,
if_not_exists: bool,
name: ObjectName,
query: Query,
columns: Vec<Ident>,
emit_mode: Option<EmitMode>,
) -> Result<RwPgResponse>
Import
// Internal to the frontend crate
use crate::handler::create_mv::handle_create_mv;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| handler_args | HandlerArgs | Yes | Session context and handler metadata |
| if_not_exists | bool | Yes | Skip creation if MV already exists |
| name | ObjectName | Yes | Name of the materialized view |
| query | Query | Yes | SQL SELECT query defining the view |
| columns | Vec<Ident> | Yes | Optional column aliases (can be empty) |
| emit_mode | Option<EmitMode> | No | EMIT ON WINDOW CLOSE mode for windowed queries |
Outputs
| Name | Type | Description |
|---|---|---|
| Result<RwPgResponse> | RwPgResponse | Success response (StatementType::CREATE_MATERIALIZED_VIEW) or error |
| Streaming job | Side effect | Fragment graph deployed to compute nodes for incremental maintenance |
| Catalog entry | Side effect | Materialized view registered in system catalog |
Usage Examples
Basic Aggregation MV
CREATE MATERIALIZED VIEW user_event_counts AS
SELECT
user_id,
event_type,
COUNT(*) AS event_count,
MAX(event_timestamp) AS last_event
FROM kafka_events
GROUP BY user_id, event_type;
Join with Temporal Filter
CREATE MATERIALIZED VIEW recent_orders AS
SELECT
o.order_id,
o.user_id,
u.username,
o.total_amount
FROM orders_source o
JOIN users_table u ON o.user_id = u.id
WHERE o.created_at > NOW() - INTERVAL '24 hours';