Have you ever noticed that the same Databricks SQL query is sometimes fast and sometimes slow? Most of that variability comes from caching behavior. Databricks SQL has three distinct cache layers, each operating at a different layer with its own retention and invalidation rules. This article breaks down all three so you can run queries efficiently and keep costs under control.
| Aspect | Result Cache | Disk Cache | Materialized View |
|---|---|---|---|
| What is cached | Query result sets | Data files from remote storage | Pre-computed aggregate results (as tables) |
| Layer of operation | Query planner (decided before execution) | Storage I/O layer (SSD) | Table storage (Delta format) |
| Storage location | Warehouse internal memory / metadata | Local SSD on the warehouse node | Cloud storage (persistent) |
| Lifetime | 24 hours (or until data changes) | Until the warehouse stops | Persistent until explicitly dropped |
| When the warehouse stops | Lost | Lost | Preserved (persisted as a table) |
| Invalidation conditions | Source table data changes or 24 hours elapses | OPTIMIZE / VACUUM / file changes | Updated by manual or automatic refresh |
| Warehouse requirement | Must be re-run on the same warehouse | Must be accessed from the same warehouse node | Not required (readable from any warehouse) |
| User configuration | Not required (automatic) | Not required (automatic) | Requires a CREATE MATERIALIZED VIEW statement |
The Result Cache returns the previous result as-is when the exact same SQL text is re-executed on the same warehouse. It skips compilation, optimization, and data scanning entirely, so a cache hit returns in tens of milliseconds.
The Disk Cache stores Parquet files fetched from remote storage (S3 / ADLS / GCS) on the local SSD of the warehouse node. While the Result Cache is a query-result-level cache, the Disk Cache is a data-file-level cache.
A Materialized View pre-computes query results and stores them as a Delta table. Unlike the Result Cache and Disk Cache, which are tied to the warehouse lifecycle, a Materialized View is persisted in cloud storage and is therefore unaffected by warehouse stops or restarts.
-- Create a Materialized View
CREATE MATERIALIZED VIEW sales_summary AS
SELECT
region,
product_category,
DATE_TRUNC('month', order_date) AS month,
COUNT(*) AS order_count,
SUM(amount) AS total_amount
FROM catalog.schema.orders
GROUP BY region, product_category, DATE_TRUNC('month', order_date);
-- Manual refresh
REFRESH MATERIALIZED VIEW sales_summary;
-- Configure automatic refresh
ALTER MATERIALIZED VIEW sales_summary
SET TBLPROPERTIES (
'pipelines.autoOptimize.managed' = 'true'
);Stopping or restarting a warehouse wipes both the Disk Cache and the Result Cache. The following strategies help avoid the classic 'only the first query is slow' problem when dashboards see a morning access spike.
| Strategy | How to apply it | Effect |
|---|---|---|
| Extend the Auto Stop interval | Set Auto Stop to 30 minutes or longer | Short idle periods do not stop the warehouse → caches are preserved |
| Warm up with scheduled queries | Auto-run key queries before the workday begins | Both the Disk Cache and Result Cache are warmed up in advance |
| Leverage Materialized Views | Pre-compute heavy aggregations as Materialized Views | Persistent speedup that is independent of warehouse stops |
| Schedule dashboard refreshes | Schedule the refresh 30 minutes before the workday starts | Users hit a pre-warmed Result Cache when they arrive |
Data Analyst Associate
問題 1
A BI team checks dashboards every morning at 9:00. The SQL Warehouse stops overnight via Auto Stop (set to 10 minutes). Users report that the morning dashboard load is 'very slow only on the first run.' The warehouse size and the queries themselves are appropriate. Which is the most effective fix?
正解: B
The root cause is that the overnight stop wipes both the Disk Cache and the Result Cache. By scheduling a refresh before the workday begins, the warehouse startup → query execution → cache generation all complete in advance, so users hit warm caches at 9:00. Scaling up does not fundamentally solve the first-run I/O cost. Z-ORDER is a separate optimization for filter efficiency. And the Result Cache TTL is not user-configurable.
Is there a way to explicitly clear the Result Cache?
There is no user-facing command to manually clear the Result Cache. It is automatically invalidated when the underlying table data changes, and it is also cleared on warehouse restart. To bypass the cache for testing, the common workarounds are to slightly modify the query text (for example, by adding a comment) or to restart the warehouse.
Can Materialized Views be used outside of SQL Warehouse?
CREATE and REFRESH for Materialized Views can be run on a SQL Warehouse or on a Databricks cluster (DBR 14.2 and later). However, the automatic refresh feature only works on a SQL Warehouse or in a DLT (Delta Live Tables) pipeline. Read access (SELECT) is available from regular clusters as well.
What happens when the Disk Cache runs out of capacity?
The Disk Cache is managed with an LRU (Least Recently Used) policy. When the SSD fills up, the oldest cache entries are automatically evicted. Cache for frequently accessed tables is preserved, while low-frequency tables are evicted first, so no special action is usually required. To increase cache capacity, scaling up the warehouse size also increases the SSD capacity.
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.
Databricks Certifications: All 7 Exams, Difficulty & Study Plan (2026)
Complete guide to all 7 Databricks certifications — Data Eng...
Databricks Exam Difficulty Ranking: All 7 Certs Compared (2026)
Every Databricks certification ranked by difficulty, with st...
Databricks Study Guide: Fastest Pass Route & Time Estimates (2026)
How to pass Databricks certifications efficiently. Official ...
Databricks Data Engineer Associate: Complete Guide (2026)
Domain-by-domain breakdown of the Databricks Certified Data ...
Databricks Data Engineer Professional: Complete Guide (2026)
Tactics for the Databricks Certified Data Engineer Professio...