Result Caching, Metadata Caching & Warehouse Caching
β¨ Story Time β βWhy Is the Query Suddenly So Fast?ββ
Meet Ravi, a BI engineer. Yesterday, his dashboard queries were taking 10 seconds, but today:
βWaitβ¦ why is it only 0.5 seconds now?β
No changes in SQL, no new indexes.
The reason? Snowflake caching magic.
Snowflake has three types of caching:
- Result Cache
- Metadata Cache
- Warehouse (Local Disk / SSD) Cache
Letβs explore each one and how it works.
1οΈβ£ Result Cache β Lightning-Fast Query Resultsβ
- Stores query results for 24 hours
- Applies at the account level
- Used when the same exact query is run again
Example:β
SELECT COUNT(*)
FROM SALES
WHERE REGION = 'Europe';
- First run: scans 10GB β takes 8 seconds
- Second run: uses result cache β returns instantly (less than 0.01s)
β Key points:
- Query must be identical
- Query on the same data
- No DML changes on underlying tables
2οΈβ£ Metadata Cache β Smart Catalog Speedβ
Metadata cache stores:
- Table definitions
- Column types
- Micro-partition statistics
- Min/Max values
- Table size
Purpose:β
- Accelerates query compilation
- Reduces time spent reading table metadata
Example:β
Query:
SELECT *
FROM ORDERS
WHERE CUSTOMER_ID = 12345;
Snowflake first checks metadata cache:
- Min/Max per micro-partition
- Prunes irrelevant partitions
β Result: fewer partitions read β faster query.
3οΈβ£ Warehouse Cache (Local SSD / SSD Cache)β
- Caches recently accessed micro-partitions on the warehouse level
- Applies to intermediate results
- Faster than reading from cloud storage (S3/Azure Blob/GCS)
Behavior:β
- Cache is per warehouse
- If you resize warehouse β cache cleared
- Active queries benefit more
- Improves large table scans and repeated transformations
Example:β
Transforming SALES table:
SELECT CUSTOMER_ID, SUM(AMOUNT)
FROM SALES
GROUP BY CUSTOMER_ID;
- First run: reads from cloud β 12 seconds
- Second run (same warehouse, same table): warehouse cache β 4 seconds
π How These Caches Work Togetherβ
| Cache Type | Scope | Lifetime | Notes |
|---|---|---|---|
| Result Cache | Account | 24 hours | Query-level, identical queries only |
| Metadata Cache | Warehouse + global | Until invalidated | Auto-prunes partitions, speeds compilation |
| Warehouse Cache | Warehouse | Session-based | Intermediate data + table blocks, faster scans |
Snowflake automatically chooses which cache to use based on query, table, and warehouse state.
π§ͺ Real-World Story β Raviβs Dashboardβ
Ravi noticed:
- Query A ran first at 10s β result cached β 0.01s next run
- Query B scanned large table β warehouse cache reduced runtime by 3Γ
- Metadata cache prevented unnecessary compilation for 50+ queries
Lesson:
βCaching isnβt magic β itβs automatic, and it works best when queries are repeated.β
π‘ Practical Tips to Leverage Cachingβ
β Result Cacheβ
- Useful for dashboards or repeated queries
- Avoid DML between runs if you want speed
β Metadata Cacheβ
- Automatically maintained
- Design queries to benefit from partition pruning
β Warehouse Cacheβ
- Keep the same warehouse active for repeated jobs
- Avoid unnecessary resize operations
β οΈ Common Misconceptionsβ
- βI need to enable caching manually.β β β False, Snowflake caches automatically.
- βCaching increases storage cost.β β β False, cached data is ephemeral and included in warehouse usage.
- βAll queries benefit equally.β β β Only repeated queries, same warehouse, or unchanged tables benefit.
π Summaryβ
Snowflake caching layers are key for high performance without manual tuning:
- Result Cache: Instant query returns for identical queries
- Metadata Cache: Speeds query compilation and pruning
- Warehouse Cache: Reduces repeated large table scans
When used properly, caching dramatically improves:
- BI dashboard response time
- ETL pipeline efficiency
- Daily analytical workloads
Snowflake handles caching automatically β your job is to design queries and workloads that benefit from it.
π Next Topic
Performance Tuning Techniques for Daily Company Work