Materialized Views and choosing a maintained result
A materialized view stores the output of a supported query and maintains it as the base table changes, trading background work and storage for repeated read savings.
Your learning goal
Compare standard views, materialized views and dynamic tables using freshness, query restrictions, maintenance and workload reuse.
Understand the idea
A concrete example
Suppose many dashboards request paid revenue by day. Repeatedly grouping a large order table can be wasteful. A maintained daily aggregate can make the read smaller, but every base change now creates maintenance responsibility.
| Concept | What it means |
|---|---|
| Standard view | A stored query definition, without its own persisted result data. |
| Materialized view | A maintained result for a restricted single-table query. |
| Dynamic table | A persisted transformation refreshed toward a target lag. |
| Maintenance | Work to reconcile stored derived data with changes. |
Remember: Choose maintained data only when reuse offsets maintenance. Compare query restrictions and freshness contracts before selecting an object.
Explain it step by step · full theory
Learning goals and prerequisites
Compare standard views, materialized views and dynamic tables using freshness, query restrictions, maintenance and workload reuse.
Use the M15_LAB setup from lesson 1. Know SELECT, joins, aggregates and window functions from Modules 03–04. Follow the supplied examples with an authorized warehouse and an isolated learning role. Keep the same data and account context when comparing runs.
Start from repeated computation
Suppose many dashboards request paid revenue by day. Repeatedly grouping a large order table can be wasteful. A maintained daily aggregate can make the read smaller, but every base change now creates maintenance responsibility.
A seldom-used report on a rapidly changing table may cost more to maintain than to compute when requested. Include read frequency, change rate and storage in the decision.
Choose the right abstraction
A standard view centralizes SQL and presents current underlying data when executed; its definition alone does not precompute the answer. Eligible persisted result reuse is a separate mechanism.
A materialized view can be used directly or through an optimizer rewrite of a compatible base-table query. Queries return current data even if some maintenance is pending, by processing the necessary base changes. A dynamic table instead exposes its last refreshed state and targets a configured lag; it supports broader pipeline patterns. See Module 12 for refresh-mode and target-lag decisions.
Respect the restricted query shape
Materialized Views require Enterprise Edition or higher. This lab needs CREATE MATERIALIZED VIEW on the schema, SELECT on the base table and container access. Use an authorized role.
The supported definition is based on one base table. Joins and window functions are not supported; neither are arbitrary nested queries or all aggregate forms. Grouping expressions must be selected. Do not assume every working SELECT can become a materialized view.
Evaluate changes and maintenance
Compare the repeated aggregate before and after, with the same cache conditions. Inspect whether the plan actually uses the view. Review background consumption and query frequency before keeping it.
Suspending maintenance is not a free way to keep a continuously fresh materialization. For the optional lab, drop the lab view after investigation. Never delete a shared object as a cost experiment.
Compare the freshness contract
| Object | Stored data | Freshness and use |
|---|---|---|
| Standard view | No independent materialized data | Runs its definition against underlying objects |
| Materialized view | Maintained eligible result | Current answer; restricted definitions; optimizer may reuse |
| Dynamic table | Persisted transformation result | Last refreshed state; target lag and refresh costs; broader pipeline logic |
Common mistakes and next action
Materialized-view definitions have restrictions including single-table input and no joins.
Choose maintained data only when reuse offsets maintenance. Compare query restrictions and freshness contracts before selecting an object.
Words used in this lesson
- Standard view
- A stored query definition, without its own persisted result data.
- Materialized view
- A maintained result for a restricted single-table query.
- Dynamic table
- A persisted transformation refreshed toward a target lag.
- Maintenance
- Work to reconcile stored derived data with changes.
See how it works
Choose a step to explore the idea at your own pace.
Open the interactive explanation
Materialized Views and choosing a maintained result
Repeated aggregate
Several reports repeatedly ask for the same eligible daily totals.
Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.
Read the complete diagram explanation
- Repeated aggregate
Several reports repeatedly ask for the same eligible daily totals.
Base orders → Group daily → Repeated reads
- Maintain
A new paid order changes a daily aggregate and creates background work.
Jan 1 +20 → Refresh work → Stored result
- Read current answer
The read uses maintained data and handles needed base changes; profile the actual path.
Daily aggregate → Current Jan 1 = 320 → Read + maintenance trade-off
Try the SQL or command
Read → predict → run in your learning environment → compare. You can also learn by reading without an account.
New to SQL? Where to run it and how to read it
A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.
- No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
- For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
- Read the entire example, including comments beginning with
--. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor. - Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
- SELECT / FROM
- Choose the values to return / identify their input.
- VALUES / COLUMN1
- VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
- AS / WITH
- AS gives a result a readable name. WITH names a temporary query step within one statement.
- NULL / ::
- NULL means missing or unknown. The :: notation converts a value to a named data type.
- Session
- One connection and its settings. Keep related transaction steps in the same session.
- Database.schema.table
- A full address for stored data. It is separate from the warehouse that processes queries.
Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →
Help with common practice errors
- No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
- Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
- Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
- Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.
Before running this lesson
Manual examples for L2_OBJECTS_LAB.M15_LAB. Select an authorized warehouse and a role with database/schema access and permission to create the lab objects. Setup runs once with fresh names. Optional paid services require their stated privileges and edition. SQL and performance timings have not been executed or measured for this lesson.
Baseline and standard view
SELECT ORDER_DATE,SUM(AMOUNT) AS REVENUE FROM ORDERS
WHERE STATUS='paid' GROUP BY ORDER_DATE ORDER BY ORDER_DATE;
CREATE VIEW PAID_DAILY_V AS
SELECT ORDER_DATE,SUM(AMOUNT) AS REVENUE FROM ORDERS
WHERE STATUS='paid' GROUP BY ORDER_DATE;What to expect and why
Expected daily totals are Jan 1=300, Jan 2=150, Feb 1=80, Feb 2=120. The standard view stores the definition, not a separate maintained aggregate.
| ORDER_DATE | REVENUE |
|---|---|
| 2026-01-01 | 300.00 |
| 2026-01-02 | 150.00 |
| 2026-02-01 | 80.00 |
| 2026-02-02 | 120.00 |
Optional Enterprise materialization
-- Paid optional exercise: uncomment only after approval in your account.
-- CREATE TABLE ORDERS_MV_TEST CLONE ORDERS;
-- CREATE MATERIALIZED VIEW PAID_DAILY_MV AS
-- SELECT ORDER_DATE,SUM(AMOUNT) AS REVENUE FROM ORDERS_MV_TEST
-- WHERE STATUS='paid' GROUP BY ORDER_DATE;
-- SELECT * FROM PAID_DAILY_MV ORDER BY ORDER_DATE;
-- INSERT INTO ORDERS_MV_TEST VALUES(107,1,'2026-01-01',20,'paid');
-- SELECT * FROM PAID_DAILY_MV ORDER BY ORDER_DATE;
-- DROP MATERIALIZED VIEW PAID_DAILY_MV;
-- DROP TABLE ORDERS_MV_TEST;What to expect and why
Only the disposable clone changes. The January 1 aggregate becomes 320. Current results do not prove background maintenance completed or was free. Keep the shared ORDERS fixture unchanged.
Check your understanding
Choose an answer, then check your reasoning. This is practice, not a scored test.
Try it yourself
Choose a standard view, MV or dynamic table for a rarely used query, a repeated eligible single-table aggregate and a multi-stage transformation with freshness tolerance.
Compare your reasoning
Choose maintained data only when reuse offsets maintenance. Compare query restrictions and freshness contracts before selecting an object.
Key takeaway
Choose maintained data only when reuse offsets maintenance. Compare query restrictions and freshness contracts before selecting an object.
Connect this lesson to the learning path
Official sources and curriculum
Module 15 · See module scope
By Rohit Ray · Independent educational lesson · Explore this visual lab