Database / Snowflake Interview Questions
What is result caching in Snowflake and under what conditions does it apply?
Result caching stores the complete output of a query in the Cloud Services layer for 24 hours. When an identical query runs again within that window, Snowflake returns the cached result instantly — no warehouse compute is consumed, no storage is read, and no credits are charged. This is Snowflake's most impactful zero-cost optimization for repeated analytical queries and dashboards.
For the result cache to apply, all five conditions must hold:
- The SQL text is character-for-character identical (whitespace counts).
- The same virtual warehouse is used (or the session's warehouse context matches).
- The same role context is active (ensures the user still has access to the underlying data).
- No DML (INSERT, UPDATE, DELETE, MERGE, COPY INTO) has touched any underlying table since the result was cached.
- The query contains no non-deterministic functions:
CURRENT_TIMESTAMP(),CURRENT_DATE(),RANDOM(),UUID_STRING(),SEQ4(), etc.
Common cache-busting mistakes: adding LIMIT 10, appending a comment, changing column aliases, or calling GETDATE() in a WHERE clause. Verify cache usage by checking QUERY_TYPE = 'RESULT_REUSE' in SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY.
-- First execution: runs on warehouse, result cached
SELECT region, SUM(revenue) AS total
FROM sales
GROUP BY region;
-- Second execution (identical SQL): served from cache, 0 credits
SELECT region, SUM(revenue) AS total
FROM sales
GROUP BY region;
-- Disabling result cache for benchmarking
ALTER SESSION SET USE_CACHED_RESULT = FALSE;
More Related questions...