How materialized view incremental refresh handles real data changes
In Part 1, Green Leaf Data Architect Jessica Hudzik set up a Databricks materialized view on a 7.2-million-row NYC taxi trips table and turned on row tracking so it could refresh incrementally. In Part 2, she changes the source data in several ways and watches how Databricks handles each refresh. The changes include a single-row update, a multi-million-row update, a small date-based change, a large insert, and an attempt to force a full rebuild.
For each scenario, she makes the change, refreshes the view, then checks two places: the query performance stats and the event log, which shows which refresh type the optimizer chose.
Scenario 1: Update a single row (0:00)
Using the unique trip ID added in Part 1, Jessica raises the improvement surcharge by 10% on one record, then refreshes the view. Running the refresh command does the same thing as starting the view’s pipeline from Jobs & Pipelines.
The results (1:30): The refresh read about 3.5 MB and wrote only 3.65 KB, which is roughly the size of that one row. The stats still list 7.2 million rows read, but they also show that 99% of the data was pruned during the scan. The rows-read figure seems to include metadata Databricks uses for incremental refresh, so bytes read is the better measure. A drop-and-recreate table would have rewritten all 7.2 million rows to pick up that one change.
Check the refresh type in the event log (3:28)
The materialized view’s event log records how each refresh ran. Look at the planning information events. Despite the name, these entries describe what happened in completed refreshes, not a plan. The first two entries show complete recomputes from creating the view before and after row tracking was turned on. The single-row update shows as row-based.
Scenario 2: Update a third of the table (5:10)
Next, Jessica updates every record where vendor ID equals 1, which changes 2.48 million rows, about a third of the table.
The results (6:14): The row counts look odd here. The stats show 21 million rows read on a 7.2-million-row table, likely because of metadata reads or shuffling. They also show 7.2 million rows written. The scan still pruned most of the files, and the event log shows the optimizer chose a row-based refresh again.
Scenario 3: Make a small date-based change (7:58)
She updates 28 records by changing their pickup date.
The results (8:32): The refresh wrote only about 6 KB and pruned 99% of the data, about 300 MB, during the scan. The event log shows another row-based refresh.
Scenario 4: Insert new data (9:15)
Jessica loads the two remaining taxi files for November and December, adding about 13.7 million new records to the source table.
The results (10:06): The refresh wrote only the new rows, about 13 million, without touching the existing data. The event log shows a new refresh type, append-only. Databricks recognized that nothing existing had changed and simply added the new records.
Scenario 5: Try to force a complete recompute (10:52)
To push the optimizer toward a full rebuild, Jessica adds 10 to the vendor ID on every row. Vendor ID is the partition column, so all 20 million records change. When she was preparing the demo, the same test led to a complete recompute once and a row-based refresh another time.
The results (12:03): The refresh read 105 million rows, likely from metadata reads or updates being handled as a delete plus an insert. It wrote exactly the number of rows that changed. The event log shows the optimizer chose row-based again.
Inside the optimizer’s decision (13:07)
Beyond the message column, each event log entry has a details field with JSON showing how the optimizer weighed its options. For this refresh, both complete recompute and row-based were listed as possible. Row-based had a higher estimated cost, and the optimizer still chose it. Databricks gives row-based maintenance extra weight because updating the view in place is less disruptive to downstream workloads than rebuilding it.
Key takeaways
- Small changes mean small writes. Single-row and 28-row updates wrote only a few kilobytes, while a drop-and-recreate table rewrites millions of rows every time.
- Databricks matches the refresh type to the change. Updates ran as row-based refreshes, and inserts ran as append-only.
- The event log shows what happened. Check the planning information events and their details JSON to see which refresh type was chosen and why.
Frequently asked questions
How do I see whether a materialized view refreshed incrementally?
Look at the planning information events in the materialized view’s event log. The message shows the refresh type, such as row-based, append-only or complete recompute.
Why does the rows-read number look higher than my table size?
Rows read can include metadata Databricks uses for incremental refresh, as well as shuffled data. Bytes read and the percentage of data pruned give a clearer picture of how much work the refresh did.
Can I control whether Databricks does a full or incremental refresh?
You can explicitly request a full refresh. Otherwise, the cost optimizer decides, and it tends to favor row-based maintenance to limit downstream impact.
What happens to a materialized view when I insert new data?
If the source table only gains new rows, Databricks can run an append-only refresh that writes just the new data.
Part one covered the foundational concepts. This follow-up focuses on what happens when those concepts are put into action.