Module 16 · Lesson 7 of 10Detailed study · about 20 min

Weigh the cost of clustering, Search Optimization and Materialized Views

Measure initial work, recurring maintenance credits and extra storage against query compute savings and latency requirements.

Think about what happens after the feature is enabled

A lookup takes 20 seconds and a proposed feature reduces it to 6. Before enabling the feature on every table, check how often the query runs, how often the table changes and whether 6 seconds solves a business problem. Much of the new spend may happen after the first speed test.

Automatic Clustering reorganizes table micro-partitions to improve pruning. It can spend background compute and increase stored historical bytes as old partitions are replaced. Search Optimization builds and maintains search access paths. A Materialized View stores a precomputed result and uses background compute to maintain it when its source changes.

Search Optimization and Materialized Views require Enterprise Edition or higher. Initial builds and steady-state maintenance are different costs. Frequent changes can make upkeep expensive, and maintaining multiple features on the same hot table can increase the combined work.

Where to look after enabling a performance feature
FeatureRecurring workHistory to inspect
Automatic ClusteringRewrite affected micro-partitionsAUTOMATIC_CLUSTERING_HISTORY
Search OptimizationKeep access paths in step with data changesSEARCH_OPTIMIZATION_HISTORY
Materialized ViewMaintain a stored result when the base changesMATERIALIZED_VIEW_REFRESH_HISTORY

Compare maintenance and query savings over the same week

Suppose weekly query compute across a defined workload falls from 12 to 7 credits. The feature uses 4 maintenance credits that week. That saves 1 compute credit before extra storage and any one-time setup. A second candidate drops the query compute to 9 but uses 5 for maintenance, which raises net compute by 2. A shorter query can still be worth a premium when a service requires it. Make that decision explicit.

Use a representative workload and confirm identical business results. Inspect actual metering to see whether lower execution compute became lower warehouse compute. A busy warehouse may use the freed time for other queries without lowering its total. Use query attribution to diagnose the workload, then reconcile the account or warehouse-level outcome separately.

Measure the build window and several normal update cycles, including busy days. Record extra storage in its own unit. Start with a narrowly scoped trial, choose a review date and define the condition that would justify removing the feature.

Know what each service buys and what keeps charging

Clustering Classic bills serverless compute for reorganizing storage. Optima Clustering uses ingested uncompressed volume and an overlap factor for its ongoing bill. Many backfills touch older value ranges and can drive more work. Check SYSTEM$CLUSTERING_INFORMATION to identify the clustering version before explaining the meter. Use the current consumption table for rates.

Search Optimization is useful for repeated selective lookups on large tables. Skip a broad rollout when few queries benefit or the table changes heavily. A Materialized View can help repeated supported queries against a base table. Frequent changes, extra storage, and query shapes it cannot support can outweigh the gain. Count build costs separately. Measure maintenance over a normal write cycle.

A Dynamic Table runs its refresh on the configured warehouse, uses Cloud Services for checks and stores its result. Target lag is a freshness goal rather than a refresh schedule. Use it when the maintained result and freshness justify the expense. Use actual refresh states and query IDs before considering a looser lag. Query Acceleration offloads eligible work to separately metered compute and requires Enterprise Edition or higher. Compare measured credits and elapsed time at the same result and concurrency.

Select one intervention for the measured bottleneck
FeatureGood candidateFirst cost evidence
Automatic ClusteringRecurring range filters scan too many partitionsClustering version, Automatic Clustering history and storage
Search OptimizationFrequent lookups match a small shareBuild and maintenance history, storage and scan outcome
Materialized ViewFrequently reused supported resultsMaintenance history, storage and query outcome
Dynamic TableAn explicitly maintained result needs a freshness targetRefresh history, assigned warehouse and stored result
Query AccelerationAn eligible scan-heavy query misses its deadlineQuery estimate, actual QAS credits and warehouse metering

Module 12 · Read refresh history before changing the warehouse →

Module 15 · Query Acceleration and Snowflake Optima →

Compare maintenance and acceleration on the same window

Use the read-only usage role and aligned UTC dates. The hourly service meter reports raw credits. Filter by relevant service and inspect absolute consumption. Use the detailed histories linked in this lesson for object-level follow-up. Keep QAS query attribution as a drill-down of QAS usage, so it does not get counted again. Dynamic Table refreshes use a warehouse and need a refresh-to-query investigation instead of a second added service total.

SQL · configuration template
ALTER SESSION SET TIMEZONE = 'UTC';
SELECT service_type, SUM(credits_used) AS raw_credits
FROM SNOWFLAKE.ACCOUNT_USAGE.METERING_HISTORY
WHERE start_time >= '2026-10-05'::DATE AND start_time < '2026-10-12'::DATE
  AND service_type IN ('AUTO_CLUSTERING','SEARCH_OPTIMIZATION','MATERIALIZED_VIEW','QUERY_ACCELERATION')
GROUP BY service_type ORDER BY raw_credits DESC;

Find the Dynamic Table refresh queries to investigate

Substitute the Dynamic Table and choose a recent window. This Information Schema function covers the last seven days and any refreshes still running. Each refresh can have a QUERY_ID you can use to look up execution and attributed compute. A no-data or skipped cycle may have no warehouse query. Use the warehouse meter to reconcile full running cost. Compare last successful data timestamps and failure counts before changing target lag.

SQL · configuration template
SELECT name, refresh_action, state, refresh_start_time, data_timestamp, query_id
FROM TABLE(<LAB_DB>.INFORMATION_SCHEMA.DYNAMIC_TABLE_REFRESH_HISTORY(
  NAME => '<LAB_DB>.<LAB_SCHEMA>.<DYNAMIC_TABLE>',
  DATA_TIMESTAMP_START => DATEADD('day', -2, CURRENT_TIMESTAMP()),
  DATA_TIMESTAMP_END => CURRENT_TIMESTAMP(), RESULT_LIMIT => 500
))
ORDER BY refresh_start_time DESC;

Explain the decision in an interview

Start with the rule, then say what you would check in a real account.

Does a faster query always reduce the bill?

I compare the warehouse’s running compute before and after. I then add recurring feature maintenance, amortize the initial build over the chosen window and price the extra storage separately.

A freshly clustered table gets a large backfill. What would you inspect?

I would confirm its clustering version, compare the ingested volume and overlap, check maintenance and storage, then see whether query pruning actually improved.

How would you reduce Dynamic Table cost without breaking freshness?

I would find expensive refreshes, identify their modes and query profiles, then test one change. I would compare the last successful data timestamp with the agreed freshness target.

Words used in this lesson
Maintenance credits
Credits used to keep a performance feature current as data changes.
Pruning
Skipping data partitions that cannot satisfy a query filter.
Churn
How much data changes in a given time.

See how it works

Choose a step to explore the idea at your own pace.

Open the interactive explanation
Interactive explainer1 / 2

Weigh the cost of clustering, Search Optimization and Materialized Views

12 before
7 after
5 avoided

Measure the read benefit

The candidate workload goes from 12 query credits to 7.

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
  1. Measure the read benefit

    The candidate workload goes from 12 query credits to 7.

    12 before → 7 after → 5 avoided

  2. Include the upkeep

    Add 4 maintenance credits. That leaves 1 compute credit saved before storage and setup.

    7 query → 4 upkeep → 11 recurring compute

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.

  1. No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
  2. 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.
  3. 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.
  4. 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.

Compare recurring compute economics

SQL · runnable example
WITH trials AS (
  SELECT column1 AS trial, column2 AS before_credits,
         column3 AS after_credits, column4 AS maintenance_credits
  FROM VALUES ('A search paths', 12, 7, 4),
              ('B stored result', 12, 9, 5)
)
SELECT trial, before_credits,
       after_credits + maintenance_credits AS recurring_credits,
       before_credits - after_credits - maintenance_credits AS net_credits_saved
FROM trials
ORDER BY trial;

What to expect and why

One row represents a candidate for the same weekly workload. Positive net_credits_saved means less measured compute for the modeled workload. Review storage separately and add any one-time build in the evaluation horizon.

Expected result for the supplied input (not live output)
TRIALBEFORE_CREDITSRECURRING_CREDITSNET_CREDITS_SAVED
A search paths12111
B stored result1214-2

Read a week of Automatic Clustering credits

SQL · runnable example
ALTER SESSION SET TIMEZONE = 'UTC';

SELECT database_name,
       schema_name,
       table_name,
       SUM(credits_used) AS clustering_credits
FROM snowflake.account_usage.automatic_clustering_history
WHERE start_time >= DATEADD(day, -8, CURRENT_DATE())
  AND start_time < DATEADD(day, -1, CURRENT_DATE())
GROUP BY database_name, schema_name, table_name
ORDER BY clustering_credits DESC;

What to expect and why

Run with approved history access to find the tables behind recurring clustering credits. Use the two companion history references for per-feature maintenance at the same time grain. For Search Optimization, consult the current schema because Snowflake has changed its object identifier columns.

Check your understanding

Choose an answer, then check your reasoning. This is practice, not a scored test.

Weekly query compute falls by 3 credits and maintenance adds 5. What happens to recurring compute?

Try it yourself

Trial A saves 1 compute credit each steady week and needs 6 credits to build. When does it first recover the build credits, ignoring storage?

Compare your reasoning

After six steady weeks it breaks even on compute in this model. A sustained saving begins in week seven. Extra storage can move or erase that break-even point.

Connect this lesson to the learning path

Official sources and curriculum

Module 16 · See module scope

By Rohit Ray · Independent educational lesson · Explore this visual lab