What you will be able to do
- Explain when the result cache is reused, how long a result lasts, what stops reuse, and how USE_CACHED_RESULT controls it
- Size AUTO_SUSPEND so the warehouse cache survives between related queries
- Recognise queries answered from metadata without a warehouse
- Choose between search optimization, a materialized view and clustering for a slow query
- Make external tables fast with partition columns and materialized views
- Find queries eligible for the query acceleration service and set its scale factor
1.The result cache: persisted query results
The fastest query is one Snowflake doesn't run. When a query finishes, its result is persisted for 24 hours. If the same query comes in again and nothing it depends on has changed, Snowflake returns the stored result and skips execution. Each reuse resets the 24-hour period, up to 31 days from the first run. After that, the result is purged and the next run computes a new one.
Reuse is strict. All of the following must hold:
- The query text matches exactly. A different letter case or an added table alias is enough to prevent reuse.
- The query uses no non-reusable functions such as UUID_STRING, RANDOM or RANDSTR, and no external functions.
- The query does not select from hybrid tables.
- The data in the tables behind the result has not changed, and the table's micro-partitions have not been reclustered or consolidated.
- Configuration options that affect the result are unchanged.
- The role has the privileges on every table in the cached query. For SHOW, it must be the same role that produced the result.
Even when every condition is met, Snowflake doesn't guarantee reuse. The USE_CACHED_RESULT parameter, which is on by default, can switch reuse off at the account, user or session level. Benchmarking is the usual reason to turn it off, so that repeated runs measure real execution. A reused result also lets you build on earlier output: RESULT_SCAN, or the ->> pipe operator, lets you query the result of a SHOW, DESCRIBE or CALL like a table.
Checkpoint 1 of 5· Check yourself
At 09:00 an analyst runs SELECT DISTINCT(severity) FROM weather_events;. The table's data does not change after that. Which of these reruns at 10:00 is blocked from reusing the persisted result?
Result reuse needs the query text to match exactly, so changing the keywords to lowercase is enough to block it. A persisted result lasts 24 hours whatever happens to the warehouse. A different role can reuse it if it has privileges on the tables. USE_CACHED_RESULT is on by default.
“Any difference in syntax, including lowercase versus uppercase, or the use of table aliases, will inhibit 100% cache reuse.”Source: docs.snowflake.com
Sources1
2.Warehouse cache, metadata answers and AUTO_SUSPEND
A running warehouse keeps a local cache of the table data its queries have read. A later query on the same warehouse that needs the same data reads it from the cache instead of remote storage. The cache only lives as long as the warehouse runs. Suspending drops it, so the first query after a resume reads everything from remote storage again. Each TableScan reports the share it read from cache as percentage scanned from cache. The column percentage_scanned_from_cache in ACCOUNT_USAGE.QUERY_HISTORY lets you compute that share per warehouse. A low share on a warehouse with frequent, similar queries means the cache is being lost.
AUTO_SUSPEND is a trade-off between keeping the cache and paying for idle time, because a running warehouse uses credits even when no query is running. The guidance:
- Tasks: suspend immediately.
- DevOps, DataOps and data science: about 5 minutes, because ad-hoc queries gain little from the cache.
- BI and SELECT warehouses: at least 10 minutes, so dashboard users keep a warm cache.
Match the setting to how often queries actually arrive. If queries come every 30 minutes, a 10-minute suspend pays for idle time and still loses the cache before the next query. AUTO_SUSPEND is set in seconds, not minutes.
ALTER WAREHOUSE my_wh SET AUTO_SUSPEND = 600;Some queries need neither cache because they never touch table data. A query such as SELECT COUNT(*) FROM a table, or SELECT CURRENT_DATABASE(), can be answered from metadata alone. Its profile shows a single Metadata-based Result operator, and no virtual warehouse processes it. Suspending a warehouse has no effect on these queries.
| Cache | What it holds | Needs a running warehouse? | What makes it unusable |
|---|---|---|---|
| Result cache (persisted query results) | Final result of a query | No | 24 hours without reuse (31-day maximum), changed data, different query text, USE_CACHED_RESULT = FALSE |
| Warehouse (local disk) cache | Table data read by recent queries | Yes | Warehouse suspends |
| Metadata | Per-micro-partition values such as ranges and distinct counts | No | Not lost on suspend; answers queries such as COUNT(*) as a Metadata-based Result |
Checkpoint 2 of 5· Fill the gap
A BI warehouse's dashboard users should keep a warm cache through 10 minutes of idle time. Which value completes this statement?
ALTER WAREHOUSE my_wh SET AUTO_SUSPEND = ? ;AUTO_SUSPEND is set in seconds, not minutes, so 10 minutes is 600. With 10, the warehouse would suspend after 10 seconds and drop its cache between dashboard queries. 600000 is 10 minutes counted in milliseconds.
Source: docs.snowflake.comCheckpoint 3 of 5· Exam question
A BI team runs the same set of dashboards against one warehouse from 08:00 to 18:00. The warehouse has AUTO_SUSPEND = 30 and users complain the first query after each pause is slow, although result cache is not applicable. What is the best explanation and remedy?
Correct answer: D — Suspending drops the local disk cache, so queries re-read data from remote storage; raise AUTO_SUSPEND so the cache survives the pauses
- A. Incorrect. Persisted results are held independently of the warehouse for 24 hours, so suspending does not invalidate them.
- B. Incorrect. Resume provisions the configured size and does not start with a smaller cluster; slowness comes from a cold data cache rather than cluster count.
- C. Incorrect. The metadata cache lives in the cloud services layer and is not affected by warehouse suspension.
- D. Correct. The local SSD data cache belongs to the running warehouse nodes and is lost on suspend, so the first queries after resume read from remote storage; a longer AUTO_SUSPEND during working hours keeps it warm.
3.Search optimization, materialized views or clustering
When a query needs lasting help rather than a warm cache, there are three table-level options. Each targets a different access pattern.
| Optimization | Helps with | Storage cost | Compute cost |
|---|---|---|---|
| Search optimization service | Equality searches, substring and regular expression searches, text and IP address searches, elements in VARIANT and structured types, GEOGRAPHY functions | Yes | Yes |
| Materialized view | Equality searches, range searches, sort operations; only for the rows and columns it contains | Yes | Yes |
| Clustering the table | Equality and range searches; one clustering key per table | Yes | Yes |
| Query acceleration service | Queries with filters or aggregation over large scans | No | Yes |
Search optimization suits selective point lookups, meaning queries expected to return a few rows, such as id = 3 or id IN (2, 3). It is a table property. Once enabled it is used automatically, and a query needs only SELECT on the table. To enable it you need OWNERSHIP of the table and the ADD SEARCH OPTIMIZATION privilege on its schema. Enable it on the specific columns you search rather than the whole table, so you don't pay to build access paths for columns nobody filters on. Adding it to a multi-terabyte table can cause a short burst of credit use while those paths are built.
ALTER TABLE mytable ADD SEARCH OPTIMIZATION ON EQUALITY(mycol);A materialized view is the better choice when the same subset of a table is read again and again with range filters or sorts. It can also store flattened JSON or VARIANT data so the flattening happens once. Because a table can have only one clustering key, a materialized view is also a way to give the same data a second clustering key. It only helps queries that stay within its rows and columns. The object itself is taught in Views, secure views and materialized views.
External tables get the same performance treatment. Queries on a large external table run fastest through a materialized view built over it. Partition columns, declared with CREATE EXTERNAL TABLE ... PARTITION BY as expressions on the file path, let a query read only the slices of files it needs rather than the whole data set. Plan the folder layout (date, time, country) before you create the table. The table's definition is covered in External tables.
Checkpoint 4 of 5· Match them up
A team has four slow workloads on the same large table. Match each optimization to the workload it fits best.
Tap a term, then the definition that fits it.
Search optimization is for selective lookups. A materialized view serves repeated range or sort access to a fixed subset, and can give the data a second clustering key. Clustering allows only one key per table. Query acceleration adds compute for large scans with filters or aggregation, and has no storage cost.
“You can also use materialized views to define different clustering keys on the same source table, or a subset of that table”Source: docs.snowflake.com
4.The query acceleration service and its scale factor
The query acceleration service (QAS) is for outlier queries that use far more resources than a warehouse's typical query. It offloads parts of their scanning and filtering to shared compute that runs in parallel. Eligible queries come in two shapes: large scans with an aggregation or a selective filter, and large scans that insert or copy many rows. A query is not eligible if it scans too few partitions, if its filter isn't selective enough or its GROUP BY cardinality is too high, if its LIMIT prevents acceleration, or if it uses nondeterministic functions such as SEQ or RANDOM. QAS works alongside search optimization. Search optimization prunes partitions first, and QAS then speeds up the remaining work.
Turn QAS on with ENABLE_QUERY_ACCELERATION = TRUE on CREATE WAREHOUSE or ALTER WAREHOUSE. Gen2 standard warehouses and multi-cluster warehouses have it on by default. QUERY_ACCELERATION_MAX_SCALE_FACTOR caps how much compute the warehouse can lease, as a multiple of its own size. A MEDIUM warehouse costs 4 credits per hour, so a scale factor of 5 allows up to 20 extra credits per hour. The default is 8 when you enable QAS explicitly, and 2 when Snowflake enables it automatically on a Gen2 warehouse. 0 removes the cap. QAS is billed by the second, only while in use, and separately from warehouse credits.
To find candidates, query SNOWFLAKE.ACCOUNT_USAGE.QUERY_ACCELERATION_ELIGIBLE. It lists eligible_query_acceleration_time and upper_limit_scale_factor per query, which you can aggregate by warehouse. To check one past query, call SYSTEM$ESTIMATE_QUERY_ACCELERATION with its query ID. For an eligible query it returns estimated run times at different scale factors. For an ineligible one it returns an ineligibleReason such as NO_LARGE_ENOUGH_SCAN.
{
"estimatedQueryTimes": {
"1": 171,
"10": 115,
"2": 152,
"4": 133,
"8": 120
},
"ineligibleReason": null,
"originalQueryTime": 300.291,
"queryUUID": "8cd54bf0-1651-5b1c-ac9c-6a9582ebd20f",
"status": "eligible",
"upperLimitScaleFactor": 10
}Returns diminish at the higher factors. The scale factor caps what QAS may lease, and it uses only what the query needs. A moderate cap such as 4 gets most of the speed-up while limiting the most extra credits the warehouse can spend.
Checkpoint 5 of 5· Check yourself
To stop query acceleration spending on a MEDIUM warehouse that has ENABLE_QUERY_ACCELERATION = TRUE, an admin runs ALTER WAREHOUSE ... SET QUERY_ACCELERATION_MAX_SCALE_FACTOR = 0. What is the result?
A scale factor of 0 removes the cap instead of disabling the service, so the change can raise QAS spending. To turn query acceleration off, set ENABLE_QUERY_ACCELERATION = FALSE on the warehouse.
“Setting the scale factor to 0 eliminates the upper bound limit and allows queries to lease as many resources as necessary and as available”Source: docs.snowflake.com
Practise it for real
Find a query that query acceleration could speed up, estimate the gain, and enable QAS with a bounded scale factor.
1.Run: SELECT query_id, eligible_query_acceleration_time FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_ACCELERATION_ELIGIBLE WHERE start_time > DATEADD('day', -7, CURRENT_TIMESTAMP()) ORDER BY eligible_query_acceleration_time DESC;
Why: This ranks last week's queries by how much of their run time QAS could take over.
You should see: A list of query IDs. An empty result means no recent query was eligible.
2.Pass the top query ID to SELECT PARSE_JSON(SYSTEM$ESTIMATE_QUERY_ACCELERATION('<query_id>'));
Why: This shows the estimated run time at each scale factor before you spend anything.
You should see: status 'eligible' with estimatedQueryTimes per scale factor, or 'ineligible' with an ineligibleReason.
3.Run ALTER WAREHOUSE <warehouse_name> SET ENABLE_QUERY_ACCELERATION = true; and set QUERY_ACCELERATION_MAX_SCALE_FACTOR to the point where the estimates level off.
Why: The scale factor sets the most extra credits QAS can spend.
You should see: The statement succeeds.
4.Run SHOW WAREHOUSES LIKE '<warehouse_name>' ->> SELECT "name", "enable_query_acceleration", "query_acceleration_max_scale_factor" FROM $1;
Why: This confirms both settings took effect.
You should see: enable_query_acceleration is true, and the scale factor is the value you chose.
Stuck? Get a nudge
Remember that an ACCOUNT_USAGE view can lag by up to 45 minutes, so a query you ran just now may not appear yet.
Sources
(8)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“Snowflake resets the 24-hour retention period for the result, up to a maximum of 31 days from the date and time”
↩︎ The result cache: persisted query results“UUID_STRING, RANDOM, and RANDSTR are good examples of non-reusable functions.”
↩︎ The result cache: persisted query results“can be overridden at the account, user, and session level using the USE_CACHED_RESULT session parameter.”
↩︎ The result cache: persisted query results“For persisted query results of all sizes, the cache expires after 24 hours.”
↩︎ Exam trap 1“Any difference in syntax, including lowercase versus uppercase, or the use of table aliases, will inhibit 100% cache reuse.”
↩︎ Exam trap 2“Any difference in syntax, including lowercase versus uppercase, or the use of table aliases, will inhibit 100% cache reuse.”
↩︎ Checkpoint - 2.
“Snowflake recommends setting auto-suspend to at least 10 minutes to maintain the cache for users.”
↩︎ Warehouse cache, metadata answers and AUTO_SUSPEND“Keep in mind that a running warehouse consumes credits even if it is not processing queries.”
↩︎ Warehouse cache, metadata answers and AUTO_SUSPEND“the cache is dropped when the warehouse is suspended.”
↩︎ Prediction - 3.
“A query whose result is computed based purely on metadata, without accessing any data.”
↩︎ Warehouse cache, metadata answers and AUTO_SUSPEND“These queries are not processed by a virtual warehouse.”
↩︎ Warehouse cache, metadata answers and AUTO_SUSPEND - 4.
“Point lookup queries are queries that are expected to return a small number of rows.”
↩︎ Search optimization, materialized views or clustering - 5.
“In general, enabling search optimization only for specific columns is the best practice.”
↩︎ Search optimization, materialized views or clustering - 6.
“Materialized views improve performance only for the subset of rows and columns included in the materialized view.”
↩︎ Search optimization, materialized views or clustering“A table can be clustered only on a single key, which can contain one or more columns or expressions.”
↩︎ Search optimization, materialized views or clustering“Search optimization and query acceleration can work together to optimize query performance.”
↩︎ The query acceleration service and its scale factor“You can also use materialized views to define different clustering keys on the same source table, or a subset of that table”
↩︎ Checkpoint - 7.
“For optimal performance when querying large data files, create and query materialized views over external tables.”
↩︎ Search optimization, materialized views or clustering“query response time is faster when processing a small part of the data instead of scanning the entire data set.”
↩︎ Search optimization, materialized views or clustering - 8.
“it can improve overall warehouse performance by reducing the impact of outlier queries”
↩︎ The query acceleration service and its scale factor“Large scans with an aggregation or selective filter.”
↩︎ The query acceleration service and its scale factor“The scale factor is a cost control mechanism that allows you to set an upper bound on the amount of compute resources”
↩︎ The query acceleration service and its scale factor“To identify the queries or warehouses that might benefit from the query acceleration service, you can query the QUERY_ACCELERATION_ELIGIBLE view.”
↩︎ The query acceleration service and its scale factor“Setting the scale factor to 0 eliminates the upper bound limit”
↩︎ Exam trap 3“Setting the scale factor to 0 eliminates the upper bound limit and allows queries to lease as many resources as necessary and as available”
↩︎ Checkpoint