Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing
Back
  1. Home
  2. Interview prep
  3. Snowflake caching layers

Snowflake, BigQuery & Databricks · Snowflake

Snowflake caching layers

Mediumwarehouses-05
snowflakecachingresult-cachemetadata

Question

What caches does Snowflake have?

Solution

Snowflake has three caches: a result cache, a local disk cache on each warehouse, and the metadata cache. They sit at different levels, and only the first two save you real compute.

Result cache

If you run the exact same query again, and the underlying data has not changed, Snowflake returns the stored result without using a warehouse at all. It is kept for 24 hours, and the clock extends each time the result is reused (up to a limit of 31 days). It works across users, as long as they have the right privileges. The query text must match, and queries that call non-deterministic functions such as CURRENT_TIMESTAMP() or RANDOM() are not cached. This is why a dashboard that refreshes often can cost almost nothing.

Warehouse (local disk) cache

When a warehouse reads micro-partitions from storage, it keeps them on its local SSD. A later query that needs the same data reads it from there, which is faster than going to object storage. This cache belongs to the warehouse, and it disappears when the warehouse suspends. That is the trade-off with aggressive auto-suspend: you save idle credits, but you lose the warm cache.

Metadata cache

Some answers come from the metadata that the cloud services layer already holds, such as COUNT(*) on a whole table, or MIN and MAX of a column. These return quickly with no warehouse running.

Benchmarking

To test real performance, switch off the result cache for your session, otherwise your second run looks suspiciously fast:

ALTER SESSION SET USE_CACHED_RESULT = FALSE;

Also remember that the first run on a fresh warehouse has a cold local cache, so compare like with like.

Quick summary for interviews

Same query, same data: result cache, free. Same data, different query: warehouse cache, faster. Simple counts and min/max: metadata. Mentioning the auto-suspend trade-off shows you understand the cost side.

PreviousNext