Skip to main content

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:

  1. Result Cache
  2. Metadata Cache
  3. 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 TypeScopeLifetimeNotes
Result CacheAccount24 hoursQuery-level, identical queries only
Metadata CacheWarehouse + globalUntil invalidatedAuto-prunes partitions, speeds compilation
Warehouse CacheWarehouseSession-basedIntermediate 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

Career