Result reuse, warehouse cache and metadata
Persisted results can avoid re-executing eligible queries; warehouse cache can avoid some remote reads during execution. They are different optimizations.
Your learning goal
Run a controlled cache comparison and explain reuse conditions, invalidation, expiration and suspension behavior.
Understand the idea
A concrete example
A reusable persisted result can bypass warehouse query execution. Local cached data still needs operators to perform filtering, joining and aggregation. Metadata may avoid scanning some data without reusing an earlier full result.
| Concept | What it means |
|---|---|
| Persisted result | A stored completed query result reusable when eligibility conditions hold. |
| Warehouse cache | Data retained locally by a running warehouse for subsequent reads. |
| Metadata optimization | Use table metadata to plan, prune or answer eligible operations. |
Remember: Name the cache layer, document the conditions and compare like-for-like runs. Preserve normal settings after the experiment.
Explain it step by step · full theory
Learning goals and prerequisites
Run a controlled cache comparison and explain reuse conditions, invalidation, expiration and suspension behavior.
Use the M15_LAB setup from lesson 1. Know SELECT, joins, aggregates and window functions from Modules 03–04. Follow the supplied examples with an authorized warehouse and an isolated learning role. Keep the same data and account context when comparing runs.
Identify which work was avoided
A reusable persisted result can bypass warehouse query execution. Local cached data still needs operators to perform filtering, joining and aggregation. Metadata may avoid scanning some data without reusing an earlier full result.
Do not call every fast repeated query a result-cache hit. Inspect history and Profile; bytes scanned and cache percentage describe a different layer from full result reuse.
Understand persisted-result eligibility
Results normally persist for 24 hours. Reuse requires eligible SQL and unchanged contributing data and other conditions such as compatible parameters and access. Query text differences, including aliases or case, can prevent reuse.
Time-dependent or other non-reusable functions can require execution. A matching query is not an unconditional guarantee of reuse. Reuse resets the retention timer within Snowflake’s documented maximum of 31 days from initial execution.
Warehouse suspension changes the experiment
A suspended warehouse loses its local data cache; persisted results have a separate lifecycle. Frequent suspend/resume can therefore trade idle savings against startup and cold-read work.
USE_CACHED_RESULT=FALSE disables persisted-result reuse for the session. It does not flush warehouse cache or turn off metadata pruning. Never suspend a shared production warehouse just to make a benchmark cold.
Record warm and cold conditions honestly
Compare multiple runs with the same warehouse, input, result-reuse setting and workload. Separate cold-start observations from warmed runs. Re-enable normal session behavior after the exercise.
Inspect scan percentages rather than assuming a warehouse is fully warm. Local cache contents depend on prior reads and capacity; another workload can change them.
Common mistakes and next action
It disables persisted result reuse, not warehouse-local data caching.
Name the cache layer, document the conditions and compare like-for-like runs. Preserve normal settings after the experiment.
Words used in this lesson
- Persisted result
- A stored completed query result reusable when eligibility conditions hold.
- Warehouse cache
- Data retained locally by a running warehouse for subsequent reads.
- Metadata optimization
- Use table metadata to plan, prune or answer eligible operations.
See how it works
Choose a step to explore the idea at your own pace.
Open the interactive explanation
Result reuse, warehouse cache and metadata
Result reuse
An eligible matching request can return stored result rows.
Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.
Read the complete diagram explanation
- Result reuse
An eligible matching request can return stored result rows.
SQL + conditions → Persisted result → No full rerun
- Warehouse cache
Otherwise execute operators, possibly reading cached table data.
Plan executes → Local data → Compute still works
- Suspension
Local data cache is lost on suspension; persisted result eligibility is separate.
Suspend → Local cache lost → Results separate
- Controlled comparison
Disable result reuse for execution comparisons and record warm/cold conditions.
Same data → Same settings → Saved query IDs
Try the SQL or command
Read → predict → run in your learning environment → compare. You can also learn by reading without an account.
New to SQL? Where to run it and how to read it
A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.
- No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
- For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
- Read the entire example, including comments beginning with
--. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor. - Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
- SELECT / FROM
- Choose the values to return / identify their input.
- VALUES / COLUMN1
- VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
- AS / WITH
- AS gives a result a readable name. WITH names a temporary query step within one statement.
- NULL / ::
- NULL means missing or unknown. The :: notation converts a value to a named data type.
- Session
- One connection and its settings. Keep related transaction steps in the same session.
- Database.schema.table
- A full address for stored data. It is separate from the warehouse that processes queries.
Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →
Help with common practice errors
- No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
- Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
- Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
- Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.
Before running this lesson
Manual examples for L2_OBJECTS_LAB.M15_LAB. Select an authorized warehouse and a role with database/schema access and permission to create the lab objects. Setup runs once with fresh names. Optional paid services require their stated privileges and edition. SQL and performance timings have not been executed or measured for this lesson.
Observe an eligible repeated result
ALTER SESSION SET USE_CACHED_RESULT=TRUE;
SELECT SUM(AMOUNT) AS PAID_REVENUE FROM ORDERS WHERE STATUS='paid';
SET cache_run_a=LAST_QUERY_ID();
SELECT SUM(AMOUNT) AS PAID_REVENUE FROM ORDERS WHERE STATUS='paid';
SET cache_run_b=LAST_QUERY_ID();What to expect and why
Both totals are 650. Inspect those IDs to determine whether reuse occurred; do not infer it solely from elapsed time.
Measure executed work separately
ALTER SESSION SET USE_CACHED_RESULT=FALSE;
SELECT SUM(AMOUNT) AS PAID_REVENUE FROM ORDERS WHERE STATUS='paid';
SET executed_run=LAST_QUERY_ID();
ALTER SESSION SET USE_CACHED_RESULT=TRUE;
SELECT QUERY_ID,QUERY_TAG,TOTAL_ELAPSED_TIME,COMPILATION_TIME,EXECUTION_TIME,
QUEUED_OVERLOAD_TIME,QUEUED_PROVISIONING_TIME,BYTES_SCANNED,
PARTITIONS_SCANNED,PARTITIONS_TOTAL,PERCENTAGE_SCANNED_FROM_CACHE,
BYTES_SPILLED_TO_LOCAL_STORAGE,BYTES_SPILLED_TO_REMOTE_STORAGE
FROM TABLE(L2_OBJECTS_LAB.INFORMATION_SCHEMA.QUERY_HISTORY_BY_SESSION(RESULT_LIMIT=>1000))
WHERE QUERY_TAG LIKE 'learnsnowflake_m15%'
ORDER BY START_TIME DESC;What to expect and why
Local warehouse caching and metadata optimizations remain possible. Restore the session setting before ordinary work.
Check your understanding
Choose an answer, then check your reasoning. This is practice, not a scored test.
Try it yourself
Explain how a query can execute with zero result reuse and still benefit from cached table data.
Compare your reasoning
Name the cache layer, document the conditions and compare like-for-like runs. Preserve normal settings after the experiment.
Key takeaway
Name the cache layer, document the conditions and compare like-for-like runs. Preserve normal settings after the experiment.
Connect this lesson to the learning path
By Rohit Ray · Independent educational lesson · Explore this visual lab