What you will be able to do
- Explain what the result, metadata and warehouse caches each keep, how long they last and what clears them
- Set a warehouse's auto-suspend to fit how often its queries arrive
- Decide when the search optimization service, the query acceleration service, a materialized view or clustering fits a slow query, and what each one costs
1.Result, metadata and warehouse caches
Snowflake can skip work at three levels, and each fails for a different reason. The result cache skips running a repeated query. Metadata answers some queries without reading any data. The warehouse cache saves a running warehouse from re-reading table data it read recently. When a repeated query is slow, the first step is to work out which of these should have helped and why it didn't.
The result cache (persisted query results) keeps the result of every query for 24 hours. A repeat that qualifies returns the stored result without running the query. Each reuse resets the 24-hour clock, up to 31 days from the first run, after which the next run builds a fresh result. Reuse requires all of the following. The query text must match exactly. It must not call non-reusable functions such as UUID_STRING, RANDOM or RANDSTR, or external functions, and must not read hybrid tables. The underlying data must be unchanged, and so must its micro-partitions: reclustering or consolidation counts as a change. The role must have privileges on every table involved, and settings that affect the result must not have changed. Even then, reuse is not guaranteed. The USE_CACHED_RESULT parameter turns reuse on or off at account, user or session level.
Metadata answers some queries without any compute. A query such as SELECT COUNT(*) FROM … or SELECT CURRENT_DATABASE() can be answered from metadata alone, and its Query Profile shows a single Metadata-based Result operator with no warehouse involved. A reused result shows as Query Result Reuse instead.
The warehouse cache holds table data that a running warehouse has read, and any query on the same warehouse can use it. It is dropped when the warehouse suspends, so the auto-suspend setting directly affects performance. An idle warehouse still burns credits, though. If queries arrive every 30 minutes, a 10-minute suspend timer pays for idle time and the cache is gone before the next query anyway. To see how well the cache works, compare the share of bytes scanned from cache per warehouse in QUERY_HISTORY.
| Workload | Auto-suspend | Reason |
|---|---|---|
| Tasks | Immediate | Each run is self-contained |
| 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 |
ALTER WAREHOUSE my_wh SET AUTO_SUSPEND = 600;Checkpoint 1 of 6· Match them up
Match each warehouse workload to the auto-suspend setting Snowflake recommends for it
Tap a term, then the definition that fits it.
The warehouse cache is dropped when the warehouse suspends. BI users repeat similar queries, so their warehouse should stay up longer to keep the cache warm. Ad-hoc work gains little from the cache, and each task run is self-contained, so for those an idle warehouse just burns credits.
“For query warehouses, for example BI and SELECT use cases, Snowflake recommends setting auto-suspend to at least 10 minutes to maintain the cache for users.”Source: docs.snowflake.com
Checkpoint 2 of 6· Check yourself
A dashboard sends the exact same query text every morning, and the underlying table never changes. Every other condition for result reuse is met. How long can Snowflake keep returning the persisted result?
Each reuse resets the 24-hour retention period, but there is a hard limit of 31 days from the first run. After that the result is purged and the next run builds a new one. The persisted result does not depend on the warehouse cache, so suspending the warehouse does not drop it.
“up to a maximum of 31 days from the date and time that the query was first executed”Source: docs.snowflake.com
2.Search optimization for selective point lookups
The search optimization service (SOS) is for needle-in-a-haystack filters on large tables. Its main target is selective point lookups, where a query returns one or a few distinct rows, such as a critical dashboard filtered to one customer. It also speeds up equality and IN predicates, substring and regular-expression searches (LIKE, ILIKE, RLIKE), SEARCH and SEARCH_IP, lookups on elements of semi-structured and structured columns, and some geospatial functions.
SOS builds and maintains a persistent structure called a search access path. It records which values might appear in each micro-partition, so more micro-partitions can be skipped than min/max ranges alone allow. Clustering helps range filters on the clustered column, while SOS helps when the filter value is scattered across the table. A background maintenance service builds the path and keeps it current as data changes. It needs no warehouse of yours, but you pay for its storage and compute. Queries are not accelerated until the path is fully built, and the search_optimization_progress column in SHOW TABLES shows how far along it is.
ALTER TABLE test_table ADD SEARCH OPTIMIZATION;Casting the column defeats SOS, just as wrapping a column defeats pruning. WHERE c2 = 2 on a string column can use the service, because the implicit cast applies to the constant. WHERE CAST(c2 AS NUMBER) = 2 cannot, because the cast applies to the column. Predicates that SOS supports individually can be combined with AND and still qualify.
Checkpoint 3 of 6· Check yourself
Support engineers query a multi-terabyte tickets table with WHERE error_message ILIKE '%timeout 504%'. Only a handful of rows match, and they are scattered across the whole table. The Query Profile shows Partitions scanned close to Partitions total and no spilling. Which change targets this query?
Search optimization builds a search access path that records which values might appear in each micro-partition. That lets it skip partitions for substring searches like ILIKE when the matches are scattered across the table. Clustering helps equality and range filters on the clustered column. A warmer cache or a larger warehouse does not reduce how many partitions the query scans.
“Search optimization service | Equality searches. Substring and regular expression searches.”Source: docs.snowflake.com
Sources4
3.Query acceleration for outlier scans
The query acceleration service (QAS) handles a different problem: a few outlier queries that need far more resources than the rest of a warehouse's workload. Instead of resizing the whole warehouse for them, QAS offloads parts of their work, mainly scanning and filtering, to shared serverless compute. It suits large scans with selective filters or aggregations, large inserts and copies, ad-hoc analytics and queries whose data volume is hard to predict. Speed-ups can vary over time, because the service depends on available servers.
You enable it with ENABLE_QUERY_ACCELERATION = TRUE on CREATE WAREHOUSE or ALTER WAREHOUSE. It is on by default for Gen2 standard and multi-cluster warehouses. To find candidates, query the QUERY_ACCELERATION_ELIGIBLE view in SNOWFLAKE.ACCOUNT_USAGE, or pass a past query's ID to SYSTEM$ESTIMATE_QUERY_ACCELERATION. Common reasons a query is ineligible: too few partitions to scan, filters that aren't selective enough, a GROUP BY with too many distinct values, a LIMIT that prevents acceleration, or nondeterministic functions such as SEQ or RANDOM.
{
"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
}Cost is controlled with QUERY_ACCELERATION_MAX_SCALE_FACTOR, a multiplier on the warehouse's own size. At a scale factor of 5, a Medium warehouse (4 credits per hour) can lease up to five times its size, which costs up to 20 extra credits per hour. QAS is billed per second, only while it is in use, and separately from the warehouse. The default is 8, or 2 when QAS is switched on automatically for a Gen2 warehouse. A value of 0 removes the upper limit. The scale factor applies to the whole warehouse, so a multi-cluster warehouse may need a higher one.
Checkpoint 4 of 6· Check yourself
An outlier report runs on a Medium warehouse (4 credits per hour). QUERY_ACCELERATION_MAX_SCALE_FACTOR is set to 5. What does query acceleration add to the bill?
The scale factor multiplies the warehouse size: 4 credits × 5 = up to 20 extra credits per hour. QAS is billed separately, by the second, and only while it is in use.
“The query acceleration service is billed by the second, only when the service is in use. These credits are billed separately from warehouse usage.”Source: docs.snowflake.com
Checkpoint 5 of 6· Fill the gap
Before you enable QAS, you want to know whether one past query would benefit and how fast it could run at each scale factor. Which function completes this statement?
SELECT PARSE_JSON( ? ('8cd54bf0-1651-5b1c-ac9c-6a9582ebd20f'));SYSTEM$ESTIMATE_QUERY_ACCELERATION takes the ID of a past query and returns whether it is eligible, with estimated run times at each scale factor. QUERY_ACCELERATION_ELIGIBLE is an ACCOUNT_USAGE view that you query, not a function that takes a query ID.
Source: docs.snowflake.comSources5
4.Choosing between caching, clustering, materialized views, SOS and QAS
Pick the fix that matches the query's shape, because each option costs something different. Search optimization and query acceleration can work on the same query: SOS first prunes the micro-partitions that aren't needed, then QAS offloads part of the remaining work.
| Option | Helps | Storage cost | Compute cost |
|---|---|---|---|
| Search optimization service | Equality, substring, regex, VARIANT and geospatial searches | Yes | Yes |
| Query acceleration service | Large scans with selective filters or aggregation | No | Yes |
| Materialized view | Equality, range and sort on the rows and columns it holds | Yes | Yes |
| Clustering the table | Equality and range searches on the key | Yes | Yes |
For a repeated, expensive aggregation, the result cache is free but fragile. It needs identical query text and unchanged data, and it lasts only until the 24-hour window lapses. A table can have only one clustering key, and a key speeds up filtering but does not save the aggregation work. A materialized view stores its rows and columns ahead of time, so it serves every version of the dashboard query that falls within them. It can also carry a different clustering key from its base table, or hold JSON that has been flattened once. The trade-off is that it only helps the rows and columns it includes, and you pay storage and compute to maintain it. How to create and maintain one is covered in Regular, secure and materialized views.
Checkpoint 6 of 6· Match them up
A slow dashboard query could be fixed in several ways, and each fix costs something different. Pair each option with the description that fits it.
Tap a term, then the definition that fits it.
Each option suits a different query shape. A materialized view serves any query within the rows and columns it holds. A table allows only one clustering key. QAS adds compute but stores nothing. The result cache costs nothing but breaks when the query text or the data changes.
“Materialized views improve performance only for the subset of rows and columns included in the materialized view.”Source: docs.snowflake.com
Sources6
Sources
(6)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“For persisted query results of all sizes, the cache expires after 24 hours.”
↩︎ Result, metadata and warehouse caches“UUID_STRING, RANDOM, and RANDSTR are good examples of non-reusable functions.”
↩︎ Result, metadata and warehouse caches“can be overridden at the account, user, and session level using the USE_CACHED_RESULT session parameter.”
↩︎ Result, metadata and warehouse caches“Snowflake resets the 24-hour retention period for the result, up to a maximum of 31 days”
↩︎ Exam trap 1“Any difference in syntax, including lowercase versus uppercase, or the use of table aliases, will inhibit 100% cache reuse.”
↩︎ Prediction“up to a maximum of 31 days from the date and time that the query was first executed”
↩︎ Checkpoint - 2.
“A query whose result is computed based purely on metadata, without accessing any data. These queries are not processed by a virtual warehouse.”
↩︎ Result, metadata and warehouse caches - 3.
“the cache is dropped when the warehouse is suspended.”
↩︎ Result, metadata and warehouse caches“a running warehouse consumes credits even if it is not processing queries.”
↩︎ Exam trap 2“For query warehouses, for example BI and SELECT use cases, Snowflake recommends setting auto-suspend to at least 10 minutes to maintain the cache for users.”
↩︎ Checkpoint - 4.
“A point lookup query returns only one or a small number of distinct rows.”
↩︎ Search optimization for selective point lookups“Queries are not accelerated until the search access path has been fully built.”
↩︎ Search optimization for selective point lookups“However, there is a cost for the storage and compute resources of maintenance.”
↩︎ Search optimization for selective point lookups - 5.
“reducing the impact of outlier queries, which are queries that use more resources than the typical query.”
↩︎ Query acceleration for outlier scans“set an upper bound on the amount of compute resources a warehouse can lease for query acceleration.”
↩︎ Query acceleration for outlier scans“The query acceleration service is billed by the second, only when the service is in use.”
↩︎ Query acceleration for outlier scans“These credits are billed separately from warehouse usage.”
↩︎ Exam trap 3“The query acceleration service is billed by the second, only when the service is in use. These credits are billed separately from warehouse usage.”
↩︎ Checkpoint - 6.
“Materialized views improve performance only for the subset of rows and columns included in the materialized view.”
↩︎ Choosing between caching, clustering, materialized views, SOS and QAS“First, search optimization can prune the micro-partitions that aren’t needed for a query.”
↩︎ Choosing between caching, clustering, materialized views, SOS and QAS“Search optimization service | Equality searches. Substring and regular expression searches.”
↩︎ Checkpoint