What you will be able to do
- Tell the query result cache, metadata-based results and the warehouse cache apart by where they live and what clears each one
- Predict whether a repeated query will reuse a persisted result, and name the change that stops it
- Post-process an earlier result with RESULT_SCAN
- Measure warehouse cache use and choose an AUTO_SUSPEND value that keeps it warm for the workload
- Benchmark a query with USE_CACHED_RESULT turned off so that result reuse does not hide its real run time
Key concept
Cache lifetime follows the layer — Persisted query results and table metadata are held outside the virtual warehouse, so they are still there after a warehouse suspends. The warehouse cache is table data on the warehouse's own compute, and it is lost when the warehouse suspends.
1.Three caches and where each one lives
Snowflake can answer a query without doing all of the work again in three ways, and each way is lost at a different moment. The query result cache returns a result that was already computed. A metadata-based result answers the query from what Snowflake already knows about the table, without reading any rows. The warehouse cache keeps table data that a running warehouse has already read, so later queries on the same warehouse can skip some reads from storage. To tell the three apart on the exam, ask what each one depends on.
The answer comes from the architecture. Using Snowflake's three layers: storage, compute, cloud services as the frame: the cloud services layer "handles request query caching" and runs on a distributed metadata store, while the warehouse cache sits on the warehouse's compute nodes. That is why a suspended warehouse keeps returning 24-hour-old results and serving COUNT(*) from metadata, yet its next scan of a table starts with an empty local cache.
| Cache | What it holds | Needs a running warehouse? | What clears it or switches it off |
|---|---|---|---|
| Query result cache | The finished result of an earlier query | No | Expiry after 24 hours (extended each time the result is reused, up to 31 days), changed data, or USE_CACHED_RESULT = FALSE |
| Metadata | Per-micro-partition facts such as the range of values in each column | No | Kept up to date by Snowflake as the table changes |
| Warehouse cache | Table data the warehouse has already scanned | Yes | Dropped when the warehouse suspends; size grows with warehouse size |
Checkpoint 1 of 10· Match them up
Match each Snowflake cache to what it holds and what happens to it
Tap a term, then the definition that fits it.
The result cache and metadata live in the cloud services layer, so they don't need a running warehouse. The warehouse cache sits on the warehouse's own compute nodes, so it is lost on suspend and its size depends on the warehouse size.
“Each warehouse, when running, maintains a cache of table data accessed as queries are processed by the warehouse.”Source: docs.snowflake.com
2.When a persisted result is reused
When a query repeats and its data has not changed, Snowflake returns the stored result and skips execution entirely. In the docs' words, "Snowflake bypasses query execution and, instead, retrieves the result directly from the cache." This only happens under a strict set of conditions, and the first one surprises most people: the query text must match exactly.
SELECT DISTINCT(severity) FROM weather_events; SELECT DISTINCT(severity) FROM weather_events; SELECT DISTINCT(severity) FROM weather_events we; select distinct(severity) from weather_events;Snowflake does not clean up the text before matching. It does not remove aliases, fold case or work out that two queries mean the same thing. Changing an alias from O to o is enough to miss the cache. The other conditions concern what the query calls and who runs it.
- No non-reusable functions. A function that returns different results for successive runs of the same query rules out reuse. Snowflake gives
UUID_STRING,RANDOMandRANDSTRas examples, and the same logic covers any function whose value changes from one run to the next. The function is not evaluated once and stored with the result. - No external functions.
- No hybrid tables. A query that selects from a hybrid table does not benefit from the result cache, even when it also joins a standard table.
- The right privileges. For a SELECT, the role running it needs access to every table in the cached query. For a SHOW, the role must be the same role that produced the cached result.
Checkpoint 2 of 10· Check yourself
Each query below is run a second time with exactly the same text, and none of the tables has changed. Which rerun cannot be answered from the query result cache?
RANDOM is a non-reusable function. It returns a different value on each run, so Snowflake executes the query again instead of returning the stored result. The other three meet the conditions for reuse: a different role is fine for a SELECT if it has privileges on every table, the result cache does not depend on the warehouse, and a SHOW query is reused when the same role runs it.
“The query does not include non-reusable functions, which return different results for successive runs of the same query.”Source: docs.snowflake.com
Checkpoint 3 of 10· Exam question
A developer rewrites a report query, changing only a table alias from uppercase O to lowercase o; the join logic and filters are otherwise identical to a query that ran minutes earlier against unchanged data. Will the rewritten query reuse the earlier persisted result?
Correct answer: C — No, differing syntax such as alias casing changes the query's text fingerprint and defeats exact-match reuse of the persisted result.
- A. Result cache matching relies on the submitted SQL text rather than a normalized logical plan, so alias stripping does not describe how Snowflake decides reuse.
- B. Warehouse allocation is unrelated to alias text changes; a warehouse is only needed when the result cache cannot be reused, not because an alias changed.
- C. Even a cosmetic change like alias casing alters the exact SQL text Snowflake compares, so the rewritten query is treated as a different statement and cannot reuse the earlier persisted result.
- D. Snowflake does not normalize casing or aliasing before comparing query text, so this claim about automatic normalization is incorrect.
Checkpoint 4 of 10· Exam question
A dashboard query embeds CURRENT_TIMESTAMP() to stamp each report and is executed twice, a few minutes apart, against unchanged source data. How does the query result cache behave across these two executions?
Correct answer: B — The query never qualifies for result cache reuse because a non-deterministic function like CURRENT_TIMESTAMP() returns a different value on every execution.
- A. The local disk cache is a warehouse-level data cache, not a substitute check performed before the result cache, so this describes the wrong order of operations.
- B. Functions like
CURRENT_TIMESTAMP()are non-deterministic, so Snowflake cannot guarantee identical output on repeat calls and excludes such queries from persisted result reuse. - C. The function is re-evaluated on every execution rather than cached alongside the result, so this description of one-time evaluation is incorrect.
- D. Warehouse state does not control whether a non-deterministic function's output is cached; the function itself is what disqualifies the query from reuse, regardless of suspension.
3.How long a result lives and what invalidates it
A persisted result lasts 24 hours, and each reuse restarts that 24 hours. Snowflake resets the retention period every time the result is reused, up to 31 days after the query first ran. After that the result is purged, and the next run computes and stores a new one. A dashboard query that runs every hour can therefore be served from cache for a month, but no longer.
Results larger than 100 KB come with a separate 6-hour limit, and it applies to the security token used to fetch them, not to the result. While the result is still in cache, a client can request a new token. Smaller results do not use a token. The Spark connector's token lasts 24 hours regardless of result size.
No. A result is invalidated by changes to the data behind it, and also by changes to how that data is stored. A stored result stops being reusable in these cases:
- the table data contributing to the result has changed
- the table's micro-partitions have been reclustered or consolidated because of changes elsewhere in the table
- a configuration option that affected how the result was produced has changed
External tables follow the same 24-hour rule and add two more invalidating events. Any DDL that changes the external table definition invalidates results, and so does any refresh, automatic or manual, that changes which files are registered in the table's metadata. The reverse also holds, and it causes problems: if AUTO_REFRESH = FALSE or the refresh is misconfigured, new files in cloud storage do not invalidate anything, and queries keep returning outdated cached results.
Checkpoint 5 of 10· Check yourself
A BI dashboard runs the same query text every hour against a table that nobody writes to. The result is 2 MB. Which statement about how long Snowflake can keep reusing that result is correct?
Each reuse restarts the 24-hour retention period, up to a maximum of 31 days from the first run. After that, the result is purged. The 6-hour limit applies only to the security token used to fetch large results. Reclustering the micro-partitions invalidates the result even when no rows have changed.
“Snowflake resets the 24-hour retention period for the result, up to a maximum of 31 days”Source: docs.snowflake.com
4.Turning result reuse off with USE_CACHED_RESULT
Result reuse is on by default and controlled by one parameter, USE_CACHED_RESULT. It can be overridden at the account, user and session level (see Parameter types and precedence (account, object, session)). Setting it to FALSE for a session makes every query in that session compute its answer from current data. This is what you need while checking a fix during an incident, or while timing a query.
alter session set use_cached_result = false;Each setting affects only its own cache. USE_CACHED_RESULT controls only result reuse, so the warehouse cache stays warm and repeated scans still benefit from it. AUTO_SUSPEND controls only how long the warehouse cache survives and has no effect on result reuse. Settings such as clustering keys or statement timeouts do not turn either cache on or off.
Set USE_CACHED_RESULT = FALSE in the test session and leave the warehouse running with its usual AUTO_SUSPEND. The queries are computed fresh, but they still read table data from the warm warehouse cache.
Checkpoint 6 of 10· Fill the gap
You are timing a query and need every run in your session to compute its answer from current data instead of returning a stored result. Which parameter completes this statement?
alter session set ? = false;USE_CACHED_RESULT is the only parameter that controls result reuse, and setting it to FALSE makes each query in the session compute from current data. AUTO_SUSPEND is a warehouse property that affects only the warehouse cache. Query tags and statement timeouts do not turn either cache on or off.
Source: docs.snowflake.comCheckpoint 7 of 10· Exam question
During an incident investigation, an engineer needs every query in the current session to recompute against live data instead of returning persisted results, so recent fixes can be verified. Which setting achieves this?
Correct answer: C — Setting the session parameter USE_CACHED_RESULT to false, which forces every query to bypass the persisted result cache and recompute against current data.
- A. Clustering keys affect micro-partition organization and pruning, not whether the result cache is consulted, so removing one does not force recomputation.
- B. Keeping a warehouse resumed has no bearing on result cache lookups, which occur in the cloud services layer regardless of warehouse suspend state.
- C. The
USE_CACHED_RESULTsession parameter directly controls whether Snowflake checks the persisted result cache, so setting it false guarantees fresh recomputation for every query in the session. - D. A statement timeout only limits how long a query may run; it does not change whether the result cache is checked before execution begins.
5.Post-processing a result with RESULT_SCAN
A persisted result can also be queried. The RESULT_SCAN table function returns an earlier query's result as a table, so you can filter, join or aggregate it. This helps in two situations. One is building a complex query in steps, where each new layer reads the previous result instead of recomputing it. The other is output that SQL cannot otherwise use: you cannot call a stored procedure inside a larger SQL statement, and SHOW, DESCRIBE and CALL return results that are hard to reuse, so post-processing their stored result is the way to work with them.
SELECT "schema_name", "name" as "table_name", "rows" FROM table(RESULT_SCAN(LAST_QUERY_ID())) WHERE "rows" = 0;LAST_QUERY_ID() points RESULT_SCAN at the statement you just ran. The SHOW output columns are lowercase, so they must be written in double quotes. The pipe operator ->> does the same job without first displaying the output of the SHOW or SELECT.
Checkpoint 8 of 10· Fill the gap
SHOW TABLES has just run. The statement below lists only the empty tables by querying the stored output of that SHOW command as if it were a table. Which table function completes it?
SELECT "schema_name", "name" as "table_name", "rows" FROM table( ? (LAST_QUERY_ID())) WHERE "rows" = 0;RESULT_SCAN returns a previous query's persisted result as a table, so you can filter it with WHERE. LAST_QUERY_ID() points it at the SHOW TABLES statement. QUERY_HISTORY returns metadata about queries, not their result rows. FLATTEN expands semi-structured values, and GET_QUERY_OPERATOR_STATS returns execution statistics.
Source: docs.snowflake.comSources3
6.Queries answered from metadata alone
Some queries never reach a warehouse because Snowflake already knows the answer. For each micro-partition it stores metadata that includes the range of values in each column and the number of distinct values (see Micro-partitions, pruning and clustering depth). A query such as SELECT COUNT(*) FROM …, or SELECT CURRENT_DATABASE(), is computed purely from metadata, without reading table data, and no virtual warehouse processes it.
Query Profile shows which shortcut served a fast query. A Metadata-based Result node means the answer came from metadata. A Query Result Reuse node means an earlier result was returned. Neither uses warehouse time, which explains a query that finished in milliseconds with no warehouse credits. Client commands work the same way: SHOW TABLES does not need a warehouse to retrieve its data, so no warehouse charges apply.
Checkpoint 9 of 10· Check yourself
Your team's only warehouse is suspended, and nobody may resume it or spend warehouse credits. Which of these statements can still return its answer?
SHOW TABLES gets its data without a warehouse, so it runs and no warehouse charges apply. The first-time AVG must read table rows on a warehouse. The warehouse cache was dropped when the warehouse suspended and only exists on a running warehouse. USE_CACHED_RESULT = FALSE makes every query compute again from current data, which also needs a warehouse.
“SHOW TABLES does not require a warehouse to retrieve data, so no charges apply.”Source: docs.snowflake.com
7.The warehouse cache: measuring it and keeping it warm
A running warehouse keeps the table data it reads, and later queries on the same warehouse can read that data from the cache instead of from the table. Larger warehouses have more compute resources and therefore a larger cache. Unlike a reused result, a query that uses this cache still runs on the warehouse: it scans less remote data, but it still uses compute.
You can measure the cache for one query or for a whole warehouse. For one query, open the query profile, select the table scan operator, and read Percentage scanned from cache under Statistics. For a warehouse, weight that percentage by bytes scanned across a month of QUERY_HISTORY. A low figure on a warehouse that runs frequent, similar queries suggests that tuning the cache could improve performance. This query needs the shared SNOWFLAKE database, which by default only ACCOUNTADMIN can query.
SELECT warehouse_name
,COUNT(*) AS query_count
,SUM(bytes_scanned) AS bytes_scanned
,SUM(bytes_scanned*percentage_scanned_from_cache) AS bytes_scanned_from_cache
,SUM(bytes_scanned*percentage_scanned_from_cache) / SUM(bytes_scanned) AS percent_scanned_from_cache
FROM snowflake.account_usage.query_history
WHERE start_time >= dateadd(month,-1,current_timestamp())
AND bytes_scanned > 0
GROUP BY 1
ORDER BY 5;The main control is AUTO_SUSPEND and AUTO_RESUME. Every suspension empties the cache, and an idle warehouse that is still running keeps using credits. The right value depends on the gap between related queries.
| Workload | Suggested auto-suspend | Reason |
|---|---|---|
| Tasks | Immediate | Nothing on the warehouse reuses the cache between task runs |
| DevOps, DataOps, Data Science | About 5 minutes | Ad hoc, one-off queries gain little from the cache |
| BI and SELECT query warehouses | At least 10 minutes | Keeps the cache warm for users running similar queries |
These are starting points, not fixed rules. If a warehouse runs one query every 30 minutes, a 10-minute suspend gets the worst of both: it pays for 10 idle minutes each cycle and still finds the cache empty when the next query arrives. In Snowsight, the Suspend After field is in minutes. In SQL, AUTO_SUSPEND is in seconds, so 10 minutes is written as 600.
ALTER WAREHOUSE my_wh SET AUTO_SUSPEND = 600;Checkpoint 10 of 10· Fill the gap
A BI warehouse serves analysts who run similar queries, so it should stay up for 10 minutes after its last query to keep its cache warm. Which value completes the statement?
ALTER WAREHOUSE my_wh SET AUTO_SUSPEND = ? ;In SQL, AUTO_SUSPEND is given in seconds, so 10 minutes is 600. Only the Snowsight Suspend After field takes minutes, which means 10 here would suspend the warehouse after 10 seconds and drop the cache almost at once. A value of 0 is not the 10-minute setting asked for, and 36000 is 10 hours.
Source: docs.snowflake.comPractise it for real
Separate the result cache from the warehouse cache in a benchmark on the TPC-H sample data
1.Run
use database snowflake_sample_data;anduse schema tpch_sf1;, thenalter session set query_tag = 'tpch_test';Why: The query tag lets you find exactly these runs later in Query History and QUERY_HISTORY.
You should see: The session context is set and the statements succeed.
2.Run
alter session set use_cached_result = false;Why: Without this, the second run of any query would return the stored result and you would be timing a cache lookup instead of the query.
You should see: Every later query in this session is computed again from the data.
3.Run the same TPC-H query (for example, the lineitem pricing summary) three times in a row on one running warehouse.
Why: The first run reads from storage. Later runs can read from the warehouse cache, which stays active because only result reuse was turned off.
You should see: The later runs are usually faster than the first, and their table scan shows a non-zero Percentage scanned from cache.
4.Query snowflake.account_usage.query_history filtered on query_tag = 'tpch_test', reading total_elapsed_time and execution_time.
Why: This records the timings outside Snowsight so you can compare runs.
You should see: One row per run. Account usage views can lag, so recent runs may take a little time to appear.
Stuck? Get a nudge
If every run takes almost no time, check whether the use_cached_result setting was applied in the same session as the queries.
Sources
(9)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“performs query compilation and optimization, handles request query caching, and more.”
↩︎ Three caches and where each one lives“using a highly available, distributed metadata store for global state management”
↩︎ Three caches and where each one lives - 2.
“This cache is dropped when the warehouse is suspended, which might result in slower initial performance for some queries after the warehouse is resumed.”
↩︎ Three caches and where each one lives“SHOW TABLES does not require a warehouse to retrieve data, so no charges apply.”
↩︎ Queries answered from metadata alone“the larger the warehouse and, therefore, more compute resources in the warehouse, the larger the cache”
↩︎ The warehouse cache: measuring it and keeping it warm“This cache is dropped when the warehouse is suspended, which might result in slower initial performance for some queries after the warehouse is resumed.”
↩︎ Key concept“Each warehouse, when running, maintains a cache of table data accessed as queries are processed by the warehouse.”
↩︎ Checkpoint - 3.
“Snowflake bypasses query execution and, instead, retrieves the result directly from the cache.”
↩︎ When a persisted result is reused“which return different results for successive runs of the same query”
↩︎ When a persisted result is reused“UUID_STRING, RANDOM, and RANDSTR are good examples of non-reusable functions.”
↩︎ When a persisted result is reused“If the query was a SHOW query, the role executing the query must match the role that generated the cached results.”
↩︎ When a persisted result is reused“Meeting all these conditions does not guarantee that Snowflake reuses the query results.”
↩︎ When a persisted result is reused“Snowflake resets the 24-hour retention period for the result, up to a maximum of 31 days”
↩︎ How long a result lives and what invalidates it“the security token used to access large persisted query results (i.e. greater than 100 KB in size) expires after 6 hours.”
↩︎ How long a result lives and what invalidates it“Any configuration options that affect how the result was produced have not changed.”
↩︎ How long a result lives and what invalidates it“result reuse is enabled, but can be overridden at the account, user, and session level using the USE_CACHED_RESULT session parameter.”
↩︎ Turning result reuse off with USE_CACHED_RESULT“You can perform post-processing by using the RESULT_SCAN table function.”
↩︎ Post-processing a result with RESULT_SCAN“You can also use the pipe operator (->>) instead of the RESULT_SCAN function to process the results of a previous command.”
↩︎ Post-processing a result with RESULT_SCAN“Any difference in syntax, including lowercase versus uppercase, or the use of table aliases, will inhibit 100% cache reuse.”
↩︎ Exam trap 1“The table’s micro-partitions have not changed (e.g. been reclustered or consolidated) due to changes to other data in the table.”
↩︎ Exam trap 2“result reuse is enabled, but can be overridden at the account, user, and session level using the USE_CACHED_RESULT session parameter.”
↩︎ Exam trap 3“For persisted query results of all sizes, the cache expires after 24 hours.”
↩︎ Exam trap 5“Any difference in syntax, including lowercase versus uppercase, or the use of table aliases, will inhibit 100% cache reuse.”
↩︎ Prediction“The query does not include non-reusable functions, which return different results for successive runs of the same query.”
↩︎ Checkpoint - 4.
“Queries that select from hybrid tables do not benefit from the query results cache.”
↩︎ When a persisted result is reused“check the Percentage scanned from cache under Statistics.”
↩︎ The warehouse cache: measuring it and keeping it warm - 5.
“Changes in the set of files in cloud storage that are registered in the external table metadata.”
↩︎ How long a result lives and what invalidates it“which lead to outdated query results”
↩︎ How long a result lives and what invalidates it - 6.
“turn off the query result cache for your session”
↩︎ Turning result reuse off with USE_CACHED_RESULT - 7.
“A query whose result is computed based purely on metadata, without accessing any data. These queries are not processed by a virtual warehouse.”
↩︎ Queries answered from metadata alone“A query that reuses the result of a previous query.”
↩︎ Queries answered from metadata alone - 8.
“The range of values for each of the columns in the micro-partition.”
↩︎ Queries answered from metadata alone - 9.
“Snowflake recommends setting auto-suspend to at least 10 minutes to maintain the cache for users.”
↩︎ The warehouse cache: measuring it and keeping it warm“if a warehouse executes a query every 30 minutes, it does not make sense to set the auto-suspend setting to 10 minutes.”
↩︎ The warehouse cache: measuring it and keeping it warm“change the auto-suspend time limit, which is specified in seconds, not minutes.”
↩︎ Exam trap 4