Databricks

Databricks SQL Caching: Result Cache / Disk Cache / Materialized Views

2026-03-26
更新: 2026-03-27
NicheeLab Editorial Team

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.

Comparison Table for the Three Cache Layers

AspectResult CacheDisk CacheMaterialized View
What is cachedQuery result setsData files from remote storagePre-computed aggregate results (as tables)
Layer of operationQuery planner (decided before execution)Storage I/O layer (SSD)Table storage (Delta format)
Storage locationWarehouse internal memory / metadataLocal SSD on the warehouse nodeCloud storage (persistent)
Lifetime24 hours (or until data changes)Until the warehouse stopsPersistent until explicitly dropped
When the warehouse stopsLostLostPreserved (persisted as a table)
Invalidation conditionsSource table data changes or 24 hours elapsesOPTIMIZE / VACUUM / file changesUpdated by manual or automatic refresh
Warehouse requirementMust be re-run on the same warehouseMust be accessed from the same warehouse nodeNot required (readable from any warehouse)
User configurationNot required (automatic)Not required (automatic)Requires a CREATE MATERIALIZED VIEW statement

Result Cache in Detail

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.

Hit Conditions

  • The SQL text matches exactly (whitespace and case differences are significant)
  • The source table data has not changed (detected via the Delta log version)
  • The query contains no non-deterministic functions (CURRENT_TIMESTAMP, rand, uuid, etc.)
  • Less than 24 hours have elapsed since the previous cache entry
  • The query is run on the same warehouse

When the Cache Does Not Hit

  • Ad-hoc queries where WHERE clause parameters differ each time
  • After INSERT/UPDATE/MERGE/DELETE has been applied to the source table
  • When the same query is run from a different warehouse
  • Queries that include CURRENT_DATE() (the cache is invalidated when the date rolls over)

Disk Cache in Detail

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.

How It Works

  1. When a query runs, the required Parquet files are fetched from remote storage
  2. The fetched files are cached on the local SSD
  3. Subsequent queries that need the same files skip the remote I/O and read directly from the SSD
  4. When the SSD reaches capacity, entries are evicted using LRU

When the Cache Is Invalidated

  • OPTIMIZE (file compaction) is run on the table
  • VACUUM runs and removes old files
  • A new version is added to the Delta log via INSERT, MERGE, etc.
  • The warehouse is stopped or restarted

Materialized Views in Detail

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'
);

Choosing Between Result Cache and Materialized View

  • The same query is run frequently → Result Cache is enough (no configuration required)
  • Different query patterns but the same aggregate results are needed → Materialized View
  • The source table changes often and fresh results are required → Result Cache (auto-invalidated on data changes)
  • The source table changes rarely and you want to pre-compute heavy aggregations → Materialized View

Cache Warm-Up Strategies

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.

StrategyHow to apply itEffect
Extend the Auto Stop intervalSet Auto Stop to 30 minutes or longerShort idle periods do not stop the warehouse → caches are preserved
Warm up with scheduled queriesAuto-run key queries before the workday beginsBoth the Disk Cache and Result Cache are warmed up in advance
Leverage Materialized ViewsPre-compute heavy aggregations as Materialized ViewsPersistent speedup that is independent of warehouse stops
Schedule dashboard refreshesSchedule the refresh 30 minutes before the workday startsUsers hit a pre-warmed Result Cache when they arrive

Cost Optimization Tips

  • Extending Auto Stop helps caching but incurs idle DBU costs → tune the value based on the workload pattern
  • Splitting across many small warehouses fragments the cache → consolidate onto the same warehouse where possible
  • Schedule OPTIMIZE outside of dashboard hours → run OPTIMIZE overnight, then run warm-up queries in the morning
  • Weigh the refresh cost of Materialized Views against the query speedup → match the refresh frequency to the source table's update frequency

Points the Exam Tests

  • "Why is the same SELECT slower after an INSERT into the table?" → The Result Cache was invalidated
  • "Why are queries slow right after a warehouse restart?" → Both the Disk Cache and the Result Cache were lost
  • "Why are queries temporarily slow after OPTIMIZE?" → The Disk Cache is invalidated (because files are restructured)
  • "How can you serve fast aggregate results regardless of warehouse stops?" → Materialized View
  • "What is the difference between Result Cache and Disk Cache?" → Result Cache reuses result sets; Disk Cache keeps data files on SSD

Check with a Sample Question

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?

  1. Scale up the warehouse by one tier to increase processing capacity
  2. Set a scheduled dashboard refresh for 8:30 so that the warehouse starts up and the caches warm up before the workday begins
  3. Apply Z-ORDER to every table to improve scan efficiency
  4. Extend the Result Cache TTL to 48 hours

正解: 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.

Frequently Asked Questions

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.

Check what you learned with practice questions

Practice with certification-focused question sets

無料で問題を解いてみる
Author

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.


Related articles
Databricks

Databricks Certifications: All 7 Exams, Difficulty & Study Plan (2026)

Complete guide to all 7 Databricks certifications — Data Eng...

Databricks

Databricks Exam Difficulty Ranking: All 7 Certs Compared (2026)

Every Databricks certification ranked by difficulty, with st...

Databricks

Databricks Study Guide: Fastest Pass Route & Time Estimates (2026)

How to pass Databricks certifications efficiently. Official ...

Databricks

Databricks Data Engineer Associate: Complete Guide (2026)

Domain-by-domain breakdown of the Databricks Certified Data ...

Databricks

Databricks Data Engineer Professional: Complete Guide (2026)

Tactics for the Databricks Certified Data Engineer Professio...

Browse all Databricks articles (110)
© 2026 NicheeLab All rights reserved.