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;
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
