What you will be able to do
- Explain how a materialized view differs from a standard view
- Write a CREATE MATERIALIZED VIEW statement and know which compute can run it
- Choose between SCHEDULE, TRIGGER ON UPDATE and a manual REFRESH to keep a materialized view current
- Recognise when a materialized view is refreshed incrementally and when it is fully recomputed
Key concept
Materialized view — A view that stores its query results ahead of time and refreshes them later. A standard view runs its query again each time you read it. A materialized view does the work once per refresh, so you read results that are already computed.
1.What a materialized view is, and why it is faster than a view
You query a materialized view the same way you query a table. What sets it apart is when the work happens. A standard view stores only its query, so every SELECT against it runs that query again. A materialized view stores the query's results and refreshes them on a set interval, so a reader gets results that were computed earlier. Because the results are precomputed, queries against a materialized view can run much faster than queries against a regular view.
A materialized view is more than a saved query. Databricks describes it as a declarative pipeline object made of three parts: the query that defines it, a flow that updates it, and the cached results. Unity Catalog stores the view's metadata, and the cached data itself lives in cloud storage. If you create a materialized view outside a Lakeflow pipeline (a *standalone* materialized view), Databricks creates a pipeline to update it for you. That pipeline is listed under Jobs & Pipelines with the pipeline type MV/ST. Materialized views defined inside a pipeline show the type ETL.
The documentation lists these typical uses: keeping a BI dashboard up to date with low query latency for its users, replacing complex ETL orchestration with plain SQL, building layered transformations, and any workload that needs consistent performance with up-to-date insights.
Checkpoint 1 of 5· Check yourself
A dashboard reads from a standard view over a large join, and every page load is slow. Why would switching to a materialized view speed it up?
A materialized view caches its results ahead of time, so reads don't repeat the join. It isn't a millisecond-latency mechanism, and it does run the full query logic.
“Because a materialized view is precomputed, queries against it can run much faster than against regular views.”Source: docs.databricks.com
2.Creating a materialized view with CREATE MATERIALIZED VIEW
You create a standalone materialized view with a single SQL statement. You can submit it from the SQL editor, the Databricks SQL CLI or the Databricks SQL API. Not every warehouse can run it, though: materialized views can only be created on a Pro or Serverless SQL warehouse, or inside a pipeline. A Classic SQL warehouse is not on that list.
-- This query defines the materialized view:
CREATE OR REPLACE MATERIALIZED VIEW mv1
AS SELECT
date,
sum(sales) AS sum_of_sales
FROM
base_table1
GROUP BY
date;The CREATE is synchronous: it doesn't return until the view exists and the initial data load has finished. The user who runs it becomes the view's owner. Because the initial load and later refreshes run on a serverless pipeline, they don't use your SQL warehouse's compute.
| Clause | What it does |
|---|---|
| OR REPLACE | Replaces the view and its content if it already exists |
| IF NOT EXISTS | Ignores the statement if a view with that name already exists; you may use at most one of this or OR REPLACE |
| column_list | Optionally names and types the output columns; can also add comments, masks and CONSTRAINT ... EXPECT data quality expectations |
| CLUSTER BY / PARTITIONED BY | Clusters or partitions the stored results; the two cannot be combined |
| SCHEDULE / TRIGGER ON UPDATE | Sets how the view refreshes (covered in the next section) |
| WITH ROW FILTER / MASK | Adds row-level filtering or column masking for fine-grained access control |
Checkpoint 2 of 5· Check yourself
An analyst's CREATE MATERIALIZED VIEW statement is rejected. Which compute choice is the most likely cause?
The only places you can create a materialized view are a Pro or Serverless SQL warehouse, or a pipeline. A Classic warehouse is not one of them.
“Materialized views can only be created using a Pro or Serverless SQL warehouse, or within a pipeline.”Source: docs.databricks.com
Checkpoint 3 of 5· Exam question
A data analyst at a retail company needs to ingest a continuously growing, append-only clickstream events feed from cloud storage into Databricks, processing each new file exactly once with the lowest possible latency for downstream near-real-time dashboards. Which dataset type should the analyst use to define this in a Lakeflow Spark Declarative Pipeline?
Correct answer: A — Define the dataset as a streaming table so each new record is processed exactly once as it arrives, minimizing latency for the append-only feed.
- A. Streaming tables assume an append-only source and process each record exactly once as it lands, which delivers the millisecond-level latency this continuously growing clickstream feed needs.
- B. Materialized views recompute cached aggregates on a refresh cadence rather than incrementally processing each arriving record, so they suit periodic summaries rather than lowest-latency ingestion.
- C. A plain view is evaluated on demand and never persists data, so it adds no ingestion mechanism at all and cannot efficiently absorb a continuously arriving feed.
- D. A manually refreshed external table depends on an analyst triggering each reload, which cannot deliver exactly-once, low-latency processing of new files as they arrive.
3.Keeping it current: schedules, triggers and manual refresh
A materialized view is only as current as its last refresh. A refresh updates the view to match the base tables as they were at the moment it ran. You have three ways to start one. A schedule, written as SCHEDULE EVERY n HOURS/DAYS/WEEKS or SCHEDULE CRON with a Quartz cron string, runs on a timer. TRIGGER ON UPDATE refreshes the view when an upstream source changes, at most once per AT MOST EVERY interval. That interval defaults to 1 minute and can't be set lower. Databricks recommends triggers for production workloads, especially when upstream data doesn't arrive on a predictable schedule. Finally, REFRESH MATERIALIZED VIEW runs a refresh on demand without restating the query. It waits for the refresh to finish unless you add ASYNC.
-- Refresh nightly at 3:30 AM UTC.
-- The cron expression uses six space-separated fields: seconds minutes hours day-of-month month day-of-week
-- Use '?' for either day-of-month or day-of-week to leave it unspecified.
CREATE OR REPLACE MATERIALIZED VIEW daily_revenue_by_region
SCHEDULE CRON '0 30 3 * * ?' AT TIME ZONE 'UTC'
AS SELECT
date_trunc('day', order_time) AS sales_date,
region,
sum(revenue) AS total_revenue,
count(*) AS order_count
FROM
orders
GROUP BY sales_date, region;Checkpoint 4 of 5· Fill the gap
Upstream loads arrive at unpredictable times. Which keyword makes this view refresh whenever base_table1 changes?
-- Refresh automatically when the source table is updated.
CREATE OR REPLACE MATERIALIZED VIEW mv_trigger
? ON UPDATE
AS SELECT
date,
sum(sales) AS sum_of_sales
FROM
base_table1
GROUP BY
date;TRIGGER ON UPDATE refreshes the view when upstream data changes. SCHEDULE runs on a fixed timer, and REFRESH is a separate statement you run yourself.
Source: docs.databricks.comEach refresh uses one of two methods. An incremental refresh finds the changes since the last update and merges only the new or modified data. A full refresh runs the whole query again and replaces the stored results. Databricks uses a full refresh when an incremental one isn't possible or wouldn't save money. In the docs' example, a view grouped by country gets 200 new customers in three countries, and only those three rows are rewritten. Either way the result is always correct, even for data that arrives late or out of order. One definition choice rules out incremental refresh entirely: if the view includes CONSTRAINT ... EXPECT expectations, it is fully refreshed on every update.
Checkpoint 5 of 5· Match them up
Match each refresh behaviour to its description
Tap a term, then the definition that fits it.
Databricks chooses between incremental and full refresh, but adding expectations forces a full refresh every time. ASYNC turns the normally blocking refresh into a non-blocking one.
“A materialized view whose definition includes expectations is fully refreshed on each update and does not support incremental refresh.”Source: docs.databricks.com
Exam traps
Each one states something that sounds right. Open it to see what is actually true.
1.Creating or refreshing a materialized view from a SQL warehouse uses that warehouse's compute.Why is that wrong?
The warehouse only submits the statement. The initial load and every later refresh run on a serverless pipeline that Databricks creates for the view.
Covered in Creating a materialized view with CREATE MATERIALIZED VIEW
2.Any SQL warehouse type can create a materialized view.Why is that wrong?
Only a Pro or Serverless SQL warehouse, or a pipeline, can create one.
Covered in Creating a materialized view with CREATE MATERIALIZED VIEW
3.TRIGGER ON UPDATE keeps a materialized view current within milliseconds of every source change.Why is that wrong?
A trigger refreshes at most once per AT MOST EVERY interval, which can't be less than 1 minute. Materialized views are not designed for low-latency use cases.
Covered in Keeping it current: schedules, triggers and manual refresh
Sources
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“Standalone materialized views have a type of MV/ST.”
↩︎ What a materialized view is, and why it is faster than a view“They are not designed for low-latency use cases.”
↩︎ Keeping it current: schedules, triggers and manual refresh“Unlike standard views, which recompute results on every query, materialized views cache the results and refresh them on a specified interval.”
↩︎ Key concept“Because a materialized view is precomputed, queries against it can run much faster than against regular views.”
↩︎ Checkpoint - 2.
“Keeping a BI dashboard up to date with minimal end-user query latency.”
↩︎ What a materialized view is, and why it is faster than a view“the CREATE MATERIALIZED VIEW command blocks until the materialized view is created and the initial data load finishes.”
↩︎ Creating a materialized view with CREATE MATERIALIZED VIEW“Use this approach for production workloads, especially when upstream dependencies don't run on predictable schedules.”
↩︎ Keeping it current: schedules, triggers and manual refresh“The system evaluates the view's query to identify changes that happened after the last update and merges only the new or modified data.”
↩︎ Keeping it current: schedules, triggers and manual refresh“This does not consume SQL warehouse compute. Instead, a serverless pipeline is used for creation and subsequent refreshes.”
↩︎ Exam trap 1“This does not consume SQL warehouse compute. Instead, a serverless pipeline is used for creation and subsequent refreshes.”
↩︎ Prediction - 3.https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-materialized-viewOfficial docs
“You may specify at most one of IF NOT EXISTS or OR REPLACE.”
↩︎ Creating a materialized view with CREATE MATERIALIZED VIEW“Materialized views can only be created using a Pro or Serverless SQL warehouse, or within a pipeline.”
↩︎ Exam trap 2“The AT MOST EVERY clause defaults to 1 minute, and cannot be less than 1 minute.”
↩︎ Exam trap 3“Materialized views can only be created using a Pro or Serverless SQL warehouse, or within a pipeline.”
↩︎ Checkpoint“A materialized view whose definition includes expectations is fully refreshed on each update and does not support incremental refresh.”
↩︎ Checkpoint