Materialized Views (MVs) are a Snowflake performance optimization feature that physically stores the result of a SELECT statement and automatically refreshes it when the base table changes. By precomputing the results of frequently executed aggregation or filtering queries, MVs dramatically reduce query response times. They are available on Enterprise Edition or higher.
Unlike a regular view, a Materialized View physically stores the SELECT result as micro-partitions. When DML operations occur on the base table, Snowflake's background service (Serverless) automatically refreshes the MV's contents.
| Aspect | Regular View | Materialized View |
|---|---|---|
| Data storage | None (SELECT runs at query time) | Yes (results stored as micro-partitions) |
| Query speed | Scans the base table | Reads precomputed results directly |
| Maintenance | None | Automatic (Serverless Credits) |
| Storage | None | Consumes storage for the result set |
| Edition | All editions | Enterprise or higher |
-- Create an MV that aggregates sales by day and region
CREATE OR REPLACE MATERIALIZED VIEW analytics.daily_sales_mv
AS
SELECT
order_date,
region,
COUNT(*) AS order_count,
SUM(amount) AS total_amount,
AVG(amount) AS avg_amount
FROM analytics.orders
WHERE order_date >= '2025-01-01'
GROUP BY order_date, region;
-- Inspect the MV
SHOW MATERIALIZED VIEWS IN SCHEMA analytics;
-- Query the MV (access it like a regular table)
SELECT *
FROM analytics.daily_sales_mv
WHERE region = 'APAC'
AND order_date >= '2026-03-01'
ORDER BY order_date;When a query against the base table matches an MV's definition, Snowflake's optimizer automatically rewrites the query to reference the MV. Users do not need to reference the MV explicitly.
-- The optimizer automatically routes this query to daily_sales_mv
SELECT region, SUM(amount) AS total
FROM analytics.orders
WHERE order_date >= '2026-03-01'
GROUP BY region;
-- You can see MATERIALIZED_VIEW_MATCH in the Query Profile steps| Restriction category | Detail |
|---|---|
| Table references | SELECT from a single table only (no JOINs) |
| Aggregation | GROUP BY and aggregate functions (SUM/COUNT/MIN/MAX/AVG) are allowed |
| Window functions | OVER clause is not allowed |
| Subqueries | Not allowed |
| HAVING / ORDER BY / LIMIT | Not allowed |
| UDF | Not allowed |
| Non-deterministic functions | CURRENT_TIMESTAMP() and similar are not allowed |
| Base table changes | Dropping a column or changing a type on the base table invalidates the MV |
MV refreshes run automatically on Serverless compute and do not consume your user Warehouse resources. Refresh frequency tracks the rate of DML operations on the base table.
-- Inspect refresh history (last 7 days)
SELECT *
FROM TABLE(INFORMATION_SCHEMA.MATERIALIZED_VIEW_REFRESH_HISTORY(
DATE_RANGE_START => DATEADD(DAY, -7, CURRENT_DATE()),
DATE_RANGE_END => CURRENT_DATE()
))
ORDER BY start_time DESC;
-- Long-term cost analysis via the Account Usage view
SELECT
table_name,
materialized_view_name,
SUM(credits_used) AS total_credits
FROM SNOWFLAKE.ACCOUNT_USAGE.MATERIALIZED_VIEW_REFRESH_HISTORY
WHERE start_time >= DATEADD(MONTH, -1, CURRENT_TIMESTAMP())
GROUP BY table_name, materialized_view_name
ORDER BY total_credits DESC;You can also define Clustering Keys on the Materialized View itself. When the MV's result set is large, adding Clustering Keys further improves partition pruning accuracy for queries against the MV.
-- Add Clustering Keys to the MV
ALTER MATERIALIZED VIEW analytics.daily_sales_mv
CLUSTER BY (order_date);| Aspect | Materialized View | Dynamic Table |
|---|---|---|
| JOIN | Not allowed | Allowed |
| Subqueries | Not allowed | Allowed |
| Window functions | Not allowed | Allowed |
| Refresh control | Automatic (refreshed immediately when base table changes) | Specify acceptable latency via TARGET_LAG |
| Automatic query rewrite | Yes (optimizer automatically references the MV) | No (you query the Dynamic Table explicitly) |
| Pipeline DAG | Self-contained within a single view | DAG automatically built from references between Dynamic Tables |
| When to use | Speeding up aggregations or filters on a single table | Complex multi-table transformation pipelines |
Performance Optimization
問題 1
On Enterprise Edition, a daily aggregation query against a single large table takes tens of seconds every time it runs on a BI dashboard. You want to precompute the aggregation results to speed it up. Which feature is most appropriate?
正解: B
Materialized Views are the best fit for speeding up aggregation queries against a single table. MVs are automatically refreshed when the base table changes, and the optimizer automatically rewrites queries against the base table to use the MV. Dynamic Tables are appropriate when you hit MV restrictions such as multi-table JOINs, but for single-table aggregations MVs win thanks to automatic rewrite. Result Cache caches query results but is not permanent and is invalidated when the base table changes.
When are Materialized View maintenance costs incurred?
Materialized View maintenance costs are incurred when DML operations (INSERT/UPDATE/DELETE/MERGE) are performed on the base table, because Snowflake's background service automatically refreshes the view contents. The charges appear as Serverless Credits and scale with the base table update frequency and the complexity of the MV's SELECT statement. Use the MATERIALIZED_VIEW_REFRESH_HISTORY table function to inspect refresh history and credit consumption. For very frequently updated tables, MV maintenance costs can become excessive, so validate cost-effectiveness up front.
Are there SQL syntax restrictions for Materialized Views?
Yes — the SELECT statement in a Materialized View has several restrictions. JOINs are not allowed; only SELECTs from a single table are supported. Subqueries, window functions (OVER clause), HAVING, ORDER BY, and LIMIT are not allowed. GROUP BY and aggregate functions (SUM/COUNT/MIN/MAX/AVG) are supported. UDFs (user-defined functions) are also not allowed. If you hit any of these limits, consider using Dynamic Tables instead.
How do I choose between Materialized Views and Dynamic Tables?
Materialized Views precompute and cache aggregation or filtering results from a single table, and queries are transparently rewritten to reference the MV. Dynamic Tables let you declaratively define complex transformations including multi-table JOINs and subqueries, with TARGET_LAG controlling refresh latency. Use MVs to speed up simple aggregations or filters, and Dynamic Tables for complex transformation pipelines. Dynamic Tables require Enterprise Edition or higher.
Practice with certification-focused question sets
無料で問題を解いてみるNicheeLab Editorial Team
NicheeLab editorial team focused on data engineering and cloud certification learning. Content is structured around practical study needs and official exam domains.
Snowflake Certifications: All 11 Exams Explained (2026)
Every SnowPro certification — Associate, Core, Specialty, Ad...
Snowflake Exam Difficulty Ranking: All 11 Certs Compared (2026)
All 11 SnowPro exams ranked by difficulty with study-time es...
Snowflake Study Guide: Fastest Pass Route by Exam (2026)
How to pass SnowPro certifications efficiently — official ma...
SnowPro Core (COF-C03): Complete Exam Guide (2026)
Pass the SnowPro Core exam — six domains, scope, sample ques...
SnowPro Associate Platform (SOL-C01): Complete Guide (2026)
The entry-level SnowPro Associate exam — scope, weighting, s...