CertSafari
    Snowflake SnowPro Core Certification (COF-C03)· Lessons

    Domain 4 · Lesson 14/19

    Optimize Snowflake query performance: QAS, search optimization, clustering and materialized views

    Optimize query performance

    23 min read
    5.25% of exam
    9 sources
    Published 20 Oct 2026
    Docs as of 18 Oct 2026

    What you will be able to do

    • Match a slow-query symptom to the right lever: query acceleration, search optimization, a clustering key or a materialized view
    • Enable the query acceleration service, check which queries qualify with SYSTEM$ESTIMATE_QUERY_ACCELERATION, and cap its spend with QUERY_ACCELERATION_MAX_SCALE_FACTOR
    • Enable search optimization on specific columns and explain what it costs and when it starts working
    • Decide whether a table deserves a clustering key and choose its columns by filter use and cardinality
    • Judge when a materialized view beats the result cache, a regular view or a hand-maintained table

    Key concept

    Matching the lever to the query pattern — Each Snowflake optimization feature speeds up one kind of query and costs credits, storage or both. To choose one, find the pattern that makes the query slow, then pick the feature built for that pattern.

    1.Four levers for four query patterns

    Slow queries in Snowflake fall into a few patterns, and each optimization feature is built for one of them. The query acceleration service lends extra compute to outlier queries that scan a lot of data. The search optimization service finds a handful of rows in a huge table without reading most of it. A clustering key reorganises a table so that filters on the same few columns skip most of its micro-partitions. A materialized view stores an expensive result so it isn't recomputed every time someone asks for it.

    None of these features changes what a query returns. Search optimization, for example, is transparent to the people running queries: results are the same, and some queries simply finish sooner. All four have a price, paid in serverless credits, extra storage, background maintenance, or a mix of these. If you pick the wrong one, you pay that price and the slow query stays slow.

    Which lever fits which query pattern, and what it costs
    LeverQuery pattern it fitsWhat you pay for
    Query acceleration serviceA few outlier queries with large scans and selective filters, or statements that insert, copy, update or delete large amounts of dataServerless credits, billed by the second and capped by the scale factor
    Search optimization serviceSelective point lookups, text searches and substring searches that return few rowsStorage for the search access path plus compute for maintaining it
    Clustering keyMany queries that filter or sort on the same few columns of a multi-terabyte tableCredits for the initial clustering and for ongoing automatic reclustering
    Materialized viewA resource-heavy query whose results are used often and change rarelyStorage for the results plus background maintenance credits

    Checkpoint 1 of 10· Match them up

    Match each Snowflake optimization lever to the query pattern it is built for.

    Tap a term, then the definition that fits it.

    Sources12

    2.Query acceleration service for outlier queries

    Most warehouses run many ordinary queries and a few outliers that use far more resources than the rest. If you size the warehouse for the outliers, every query pays for them. The query acceleration service (QAS) is a third option alongside the two in Scale up vs scale out: a larger warehouse, which gives each cluster more compute, or a multi-cluster warehouse, which adds clusters to serve more concurrent queries. Once QAS is enabled on a warehouse, it sends parts of an outlier's work to shared compute that the service provides. That compute runs more of the scanning and filtering in parallel and cuts wall-clock time, while the warehouse itself stays the same size for every other query.

    QAS speeds up two kinds of work, and the second one is easy to forget:

    • Queries with large scans and selective filters, or large scans followed by an aggregation.
    • Statements that insert, copy, update or delete large amounts of data, such as big INSERT, COPY, UPDATE and DELETE operations.

    So a nightly UPDATE that rewrites most of a large table is exactly the kind of statement QAS can speed up. A clustering key won't help that job because it changes the table's layout, not how fast a write runs. A materialized view won't help either, because it stores query results and doesn't reduce what an UPDATE has to change.

    Enabling QAS when creating a warehouse, and on an existing warehousesql
    CREATE WAREHOUSE my_wh WITH ENABLE_QUERY_ACCELERATION = true;
    
    CREATE WAREHOUSE my_other_wh WITH ENABLE_QUERY_ACCELERATION = false;
    ALTER WAREHOUSE my_other_wh SET ENABLE_QUERY_ACCELERATION = true;

    Gen2 standard warehouses and multi-cluster warehouses have QAS turned on by default. Because the service runs on shared servers, its speed-up depends on server availability and can vary from one run to the next.

    Checkpoint 2 of 10· Check yourself

    On one warehouse, most queries finish quickly, but a few ad hoc analyst queries scan large parts of a big table and run for a long time. The warehouse isn't queuing, and the team doesn't want to pay more for the whole workload. Which change fits best?

    Checkpoint 3 of 10· Exam question

    A data engineering team runs ad hoc analytical queries against a 40 TB sales fact table using a Medium warehouse. Most queries finish in under 10 seconds, but a handful of queries that scan large portions of the table behind a highly selective filter occasionally take five to ten times longer than the rest, even though the warehouse is never queued. The team wants to reduce the wall-clock time of just these outlier queries without resizing the warehouse for the whole workload. Which approach best addresses this?

    Sources3456

    3.Finding queries that qualify for acceleration

    Turning QAS on doesn't mean every query gets accelerated. There's no fixed scan size that makes a query eligible. Eligibility depends on the query plan and the warehouse size, and Snowflake marks a query as eligible only when it is highly confident that acceleration would help. The common reasons a query is ruled out are:

    • Too few partitions in the scan, so the time spent acquiring extra resources cancels out the gain.
    • Filters that aren't selective enough, or a GROUP BY expression with too many distinct values.
    • A LIMIT clause that prevents acceleration. A LIMIT no longer disqualifies a query automatically: QAS now decides case by case, even for LIMIT without ORDER BY.
    • Functions with nondeterministic results, such as SEQ or RANDOM.

    To test a single query, pass the ID of a query that has already run to SYSTEM$ESTIMATE_QUERY_ACCELERATION. If the query is eligible, the function returns an estimated run time for each scale factor. In the output below, a query that took about 300 seconds is estimated at 120 seconds with a scale factor of 8. upperLimitScaleFactor is the point beyond which more compute stops helping. If the query is ineligible, estimatedQueryTimes comes back empty and ineligibleReason gives a reason such as NO_LARGE_ENOUGH_SCAN.

    SYSTEM$ESTIMATE_QUERY_ACCELERATION output for an eligible queryjson
    {
      "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
    }

    To review a whole account rather than one query, use the SNOWFLAKE.ACCOUNT_USAGE.QUERY_ACCELERATION_ELIGIBLE view. It records, for each query, how much of its execution time could have been accelerated. Rank queries by eligible_query_acceleration_time to find the best candidates, or group by warehouse_name to find the warehouse where enabling QAS would help most. The view's upper_limit_scale_factor column helps you choose a scale factor for that warehouse.

    Checkpoint 4 of 10· Check yourself

    QAS is enabled on a warehouse. You pass a 20-second query to SYSTEM$ESTIMATE_QUERY_ACCELERATION, and it returns status "ineligible" with ineligibleReason NO_LARGE_ENOUGH_SCAN. What best explains this result?

    Sources3

    4.Capping QAS spend with the scale factor

    QAS can make a warehouse use credits faster, and the scale factor is the setting that limits this. QUERY_ACCELERATION_MAX_SCALE_FACTOR caps how much compute the warehouse can lease for acceleration, as a multiple of the warehouse's own size. A Medium warehouse costs 4 credits per hour. With a scale factor of 5, it can lease up to five times its own size, which can add up to 20 credits per hour. You set the property with CREATE WAREHOUSE or ALTER WAREHOUSE. If acceleration credits are climbing during a reporting spike, lower this value. That keeps the feature on while putting a hard limit on what any accelerated query can borrow.

    The default depends on how QAS was enabled. If you set ENABLE_QUERY_ACCELERATION = TRUE yourself, the scale factor defaults to 8. If Snowflake enabled QAS automatically when it created a Gen2 or multi-cluster warehouse, the default is 2. The scale factor applies to the whole warehouse, not to each cluster, so a multi-cluster warehouse may need a higher value for every cluster to benefit.

    Billing is separate from warehouse usage. QAS is billed by the second, only while the service is in use, and costs the same however many queries are using it at once. The scale factor is a ceiling, not a target: a query requests only as much as its eligible work needs, limited by what the service has available. To compare credits before and after you enable QAS, query the QUERY_ACCELERATION_HISTORY view in ACCOUNT_USAGE.

    Checkpoint 5 of 10· Match them up

    A FinOps team is tuning a warehouse that uses query acceleration. Match each setting or view to what it does for that warehouse.

    Tap a term, then the definition that fits it.

    Checkpoint 6 of 10· Exam question

    After enabling the query acceleration service on a warehouse, a team notices serverless acceleration credits are consumed faster than expected during a monthly reporting spike. They want to cap how much serverless compute any single query can borrow without disabling the feature entirely. Which setting should they change?

    Sources3

    5.Search optimization for selective lookups

    Search optimization is for queries that look for a needle in a haystack. A point lookup returns one row or a small number of distinct rows, for example a dashboard with very selective filters, or an application fetching a few records by ID. The service also speeds up:

    • text and IP address searches with SEARCH and SEARCH_IP
    • substring and regular-expression predicates such as LIKE, ILIKE and RLIKE
    • equality, IN and NULL checks on elements of VARIANT, OBJECT and ARRAY columns
    • selected geospatial functions on GEOGRAPHY values

    It works through a persistent data structure called the search access path. For each micro-partition, the path records which column values might be found in it, so a lookup can skip every micro-partition that can't contain the value. This is the same partition-skipping idea that ordinary pruning uses, but driven by a separate structure rather than by how the table's rows are physically ordered. Search optimization can also be combined with QAS: search optimization first skips the micro-partitions a query doesn't need, then QAS takes on part of the remaining work for eligible queries.

    Enabling search optimization for equality lookups on one columnsql
    ALTER TABLE mytable ADD SEARCH OPTIMIZATION ON EQUALITY(mycol);

    The best practice is to enable search optimization only on the columns your lookups actually filter on, using the ON clause. Without an ON clause, ALTER TABLE ... ADD SEARCH OPTIMIZATION enables EQUALITY for every column of a supported type except semi-structured and GEOGRAPHY columns. Snowflake's optimizer decides which queries use the access path, and users can't force it either way.

    The access path isn't ready straight away. A background maintenance service builds it, which can take a long time on a large table, and queries get no speed-up until the build is finished. Check the search_optimization_progress column of SHOW TABLES before you measure any gain. After that, the service updates the path as loads and DML change the table. No warehouse is needed for this maintenance, but you pay for both its storage and its compute.

    How a predicate is written decides whether it can use the access path. WHERE c2 = 2 on a string column qualifies, because the implicit cast is applied to the constant. WHERE CAST(c2 AS NUMBER) = 2 doesn't qualify, because the cast is applied to the column. DELETE, UPDATE and MERGE can use search optimization to find the few rows they change. A statement that rewrites most of a table has almost nothing to skip, though, so for heavy writes QAS is the right lever.

    Checkpoint 7 of 10· Check yourself

    Minutes after running ALTER TABLE ... ADD SEARCH OPTIMIZATION ON EQUALITY(customer_id) on a 5 TB table, an engineer reruns a point lookup by customer_id. It is no faster than before. What should the engineer do next?

    Checkpoint 8 of 10· Exam question

    A nightly batch job issues a single UPDATE statement that modifies roughly 60% of the rows in a 2 TB table, and this statement alone accounts for most of the batch's total runtime even though the warehouse has spare capacity. Which Snowflake feature is designed to speed up exactly this kind of large-scale write operation?

    Sources1378

    6.Clustering keys and automatic clustering

    Snowflake usually produces well-clustered tables on its own. On very large tables, though, ongoing DML can gradually break up the natural ordering, so rows with similar values end up spread across many micro-partitions. A clustering key is a set of columns or expressions that Snowflake uses to keep similar rows together in the same micro-partitions. Two signs suggest a table needs one: queries are slower than expected or have gotten slower over time, and the table's clustering depth is large. For how depth is measured, see Micro-partitions, pruning and clustering depth.

    Clustering isn't meant for every table, because both the initial clustering and the ongoing maintenance cost credits. It pays off when the table meets all of these conditions:

    • The table has a large number of micro-partitions, which usually means several terabytes of data.
    • Queries are selective (they read a small share of rows) or they sort the data.
    • Most queries filter or sort on the same few columns.

    If your main goal is lower cost, you also want many queries for every round of DML. Group frequent DML into large, infrequent batches. Before you add a key, run a representative set of queries to record baseline timings.

    Choose key columns in this order. First, the columns used most in selective filters, such as the date column in fact tables queried by date range. Next, if there's room, columns that are often used in join predicates. If queries usually filter on two dimensions, a key on both columns can help. Keep a key to 3 or 4 columns or expressions at most, since more than that tends to add more cost than benefit.

    Judging candidate clustering columns by cardinality
    Candidate columnVerdictReason
    invoice_date on a fact table queried by date rangeGood choiceUsed in selective filters, with enough distinct values to prune well
    event type on an event tableGood if there are many event typesWith only a few types, low cardinality limits pruning
    IS_NEW_CUSTOMER (Boolean)Poor choiceTwo values give only minimal pruning
    Nanosecond timestampPoor choice as is; use an expression on itVery high cardinality makes rows hard to group and expensive to maintain. An expression that keeps the column's order reduces the number of distinct values

    You can define a key in CREATE TABLE or add it later with ALTER TABLE, and you can change or drop it at any time. Hybrid tables can't have a clustering key. After the key is set, automatic clustering handles all reclustering with no further work from you. That doesn't mean the rows are reordered right away: Snowflake reclusters only when the table will benefit, and the compute it uses consumes credits. Tables that are queried often and change rarely give the best return on those credits.

    Checkpoint 9 of 10· Match them up

    A data engineer is reviewing proposed clustering keys for a multi-terabyte table. Match each proposal to the verdict Snowflake's guidance gives it.

    Tap a term, then the definition that fits it.

    Sources4

    7.When a materialized view is worth it

    A materialized view stores the precomputed result of its SELECT, and a background service keeps that result up to date as the base table changes. As an optimization, it's worth creating only when all three of these are true: the view's results don't change often, the results are used much more often than they change, and the query is expensive in processing time, credits or intermediate storage. Good fits include expensive aggregations, analysis of semi-structured data, results much smaller than the base table, and queries on external tables. If the results change often, are rarely read, or are cheap to recompute, a regular view is the better choice.

    Compare it with the other ways of reusing a result. The query result cache is the fastest and least flexible option: it works only when the data hasn't changed and the query uses only deterministic functions. A materialized view is more flexible but usually slower than a cached result. A table you populate yourself on a schedule works while the source changes on a predictable schedule. If the source changes unpredictably, queries against that table can return out-of-date results. A materialized view always returns current data, however much DML has hit the base table.

    Materialized views can be clustered just like tables, so a view on a large table can also be ordered to match how it is filtered. The cost is storage plus maintenance credits. If the results are read only occasionally, even if more often than they change, the extra storage cost can be more than the performance gain is worth.

    Checkpoint 10 of 10· Match them up

    An analytics team is choosing how to reuse the result of an expensive, frequently-run aggregation. Pair each reuse option with the statement that describes it correctly.

    Tap a term, then the definition that fits it.

    Sources94

    Sources

    (9)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “Queries work the same as they do without search optimization; some are just faster.”
      ↩︎ Four levers for four query patterns
      “A point lookup query returns only one or a small number of distinct rows.”
      ↩︎ Search optimization for selective lookups
      “The search access path keeps track of which values of the table’s columns might be found in each of its micro-partitions”
      ↩︎ Search optimization for selective lookups
      “there is a cost for the storage and compute resources of maintenance”
      ↩︎ Search optimization for selective lookups
      “because the cast is on the table’s column”
      ↩︎ Search optimization for selective lookups
      “DELETE and UPDATE (and MERGE) can also use the search optimization service”
      ↩︎ Search optimization for selective lookups
      “The search optimization service is one of several ways to optimize query performance.”
      ↩︎ Key concept
      “Queries are not accelerated until the search access path has been fully built.”
      ↩︎ Exam trap 4
      “Queries are not accelerated until the search access path has been fully built.”
      ↩︎ Checkpoint
    2. 3.
      “offloading portions of the query processing work to shared compute resources that are provided by the service”
      ↩︎ Query acceleration service for outlier queries
      “Queries that insert, copy, update, or delete large amounts of data.”
      ↩︎ Query acceleration service for outlier queries
      “The Query Acceleration Service is also enabled by default in Snowflake Gen2 standard warehouses and multi-cluster warehouses.”
      ↩︎ Query acceleration service for outlier queries
      “Snowflake only marks a query as eligible if there is high confidence that the query would be accelerated if QAS was enabled.”
      ↩︎ Finding queries that qualify for acceleration
      “the benefits of query acceleration are offset by the latency in acquiring resources”
      ↩︎ Finding queries that qualify for acceleration
      “If the query is eligible for query acceleration, the function returns the estimated query execution time for different query acceleration scale factors.”
      ↩︎ Finding queries that qualify for acceleration
      “but now Snowflake automatically determines whether such queries can benefit from QAS.”
      ↩︎ Finding queries that qualify for acceleration
      “set an upper bound on the amount of compute resources a warehouse can lease for query acceleration”
      ↩︎ Capping QAS spend with the scale factor
      “leasing these resources can cost up to an additional 20 credits per hour”
      ↩︎ Capping QAS spend with the scale factor
      “When Snowflake automatically enables QAS for Gen2 or multi-cluster warehouses at creation time, the default scale factor is 2.”
      ↩︎ Capping QAS spend with the scale factor
      “The scale factor applies to the entire warehouse, whether it’s a single-cluster or multi-cluster warehouse.”
      ↩︎ Capping QAS spend with the scale factor
      “The query acceleration service is billed by the second, only when the service is in use.”
      ↩︎ Capping QAS spend with the scale factor
      “First, search optimization can prune the micro-partitions not needed for a query.”
      ↩︎ Search optimization for selective lookups
      “Queries that insert, copy, update, or delete large amounts of data.”
      ↩︎ Exam trap 1
      “Setting the scale factor to 0 eliminates the upper bound limit”
      ↩︎ Exam trap 2
      “don’t be concerned by a nonzero value for bytes_spilled_to_remote_storage in the QUERY_HISTORY view when QAS is enabled”
      ↩︎ Exam trap 3
      “Queries that insert, copy, update, or delete large amounts of data.”
      ↩︎ Checkpoint
      “When it is enabled for a warehouse, it can improve overall warehouse performance by reducing the impact of outlier queries”
      ↩︎ Checkpoint
      “If there aren’t enough partitions to scan, the benefits of query acceleration are offset by the latency in acquiring resources for the query acceleration service.”
      ↩︎ Checkpoint
      “Setting the scale factor to 0 eliminates the upper bound limit”
      ↩︎ Prediction
      “Setting the scale factor to 0 eliminates the upper bound limit and allows queries to lease as many resources as necessary”
      ↩︎ Checkpoint
    3. 4.
      “A high percentage of the queries can benefit from the same clustering key(s).”
      ↩︎ Query acceleration service for outlier queries
      “The clustering depth for the table is large.”
      ↩︎ Clustering keys and automatic clustering
      “Clustering keys are not intended for all tables due to the costs of initially clustering the data and maintaining the clustering.”
      ↩︎ Clustering keys and automatic clustering
      “Typically, this means that the table contains multiple terabytes (TB) of data.”
      ↩︎ Clustering keys and automatic clustering
      “For most tables, Snowflake recommends a maximum of 3 or 4 columns (or expressions) per key.”
      ↩︎ Clustering keys and automatic clustering
      “Snowflake recommends defining the key as an expression on the column, rather than on the column directly, to reduce the number of distinct values.”
      ↩︎ Clustering keys and automatic clustering
      “All future maintenance on the rows in the table (to ensure optimal clustering) is performed automatically by Snowflake.”
      ↩︎ Clustering keys and automatic clustering
      “clustering is generally most cost-effective for tables that are queried frequently and do not change frequently.”
      ↩︎ Clustering keys and automatic clustering
      “You can cluster materialized views, as well as tables.”
      ↩︎ When a materialized view is worth it
      “For most tables, Snowflake recommends a maximum of 3 or 4 columns (or expressions) per key.”
      ↩︎ Exam trap 5
      “A column with very low cardinality might yield only minimal pruning”
      ↩︎ Prediction
      “A column with very low cardinality might yield only minimal pruning, such as a column named IS_NEW_CUSTOMER that contains only Boolean values.”
      ↩︎ Checkpoint
    4. 5.
      “unlike upsizing a warehouse, it is only used for queries that benefit from increased compute power”
      ↩︎ Query acceleration service for outlier queries
    5. 6.
      “Multi-cluster virtual warehouses for scaling compute resources to meet concurrency needs.”
      ↩︎ Query acceleration service for outlier queries
    6. 7.
      “In general, enabling search optimization only for specific columns is the best practice.”
      ↩︎ Search optimization for selective lookups
    7. 8.
      “Users cannot control which queries search optimization is used for.”
      ↩︎ Search optimization for selective lookups
    8. 9.
      “The results of the view are used often (typically significantly more often than the query results change).”
      ↩︎ When a materialized view is worth it
      “materialized views can speed up expensive aggregation, projection, and selection operations, especially those that run frequently and that run on large data sets.”
      ↩︎ When a materialized view is worth it
      “Used only if data has not changed and if query only uses deterministic functions”
      ↩︎ When a materialized view is worth it
      “Materialized views are more flexible than, but typically slower than, cached results.”
      ↩︎ When a materialized view is worth it
      “sometimes your main query Q will return out-of-date results”
      ↩︎ When a materialized view is worth it
      “Materialized views are more flexible than, but typically slower than, cached results.”
      ↩︎ Exam trap 6

    Ready to test yourself?

    Practise the 21 questions on this subdomain.

    Spotted a mistake, or was something unclear? Tell us.