Rule 1: read less data
From lesson 2: Snowflake skips micro-partitions whose min/max values can't match your filter. That only works if similar values sit together. Let's prove how much it matters with 15 million orders from the sample data.
USE SCHEMA shopkart.analytics;
ALTER SESSION SET USE_CACHED_RESULT = FALSE;
-- 15 million orders, loaded in random order (like data arriving from many sources at once)
CREATE OR REPLACE TABLE big_orders AS
SELECT * FROM snowflake_sample_data.tpch_sf10.orders ORDER BY RANDOM();
-- Exactly the same rows, sorted by date (what clustering does for you)
CREATE OR REPLACE TABLE big_orders_sorted AS
SELECT * FROM big_orders ORDER BY o_orderdate;-- One week of orders, from each table
SELECT COUNT(*) AS orders, SUM(o_totalprice)::NUMBER AS revenue
FROM big_orders WHERE o_orderdate BETWEEN '1996-03-01' AND '1996-03-07';
SET q_random = LAST_QUERY_ID();
SELECT COUNT(*) AS orders, SUM(o_totalprice)::NUMBER AS revenue
FROM big_orders_sorted WHERE o_orderdate BETWEEN '1996-03-01' AND '1996-03-07';
SET q_sorted = LAST_QUERY_ID();
-- What did each query have to read?
SELECT 'random' AS tbl,
operator_statistics:pruning:partitions_scanned AS scanned,
operator_statistics:pruning:partitions_total AS total,
operator_statistics:io:bytes_scanned AS bytes_scanned
FROM TABLE(GET_QUERY_OPERATOR_STATS($q_random)) WHERE operator_type = 'TableScan'
UNION ALL
SELECT 'sorted', operator_statistics:pruning:partitions_scanned,
operator_statistics:pruning:partitions_total, operator_statistics:io:bytes_scanned
FROM TABLE(GET_QUERY_OPERATOR_STATS($q_sorted)) WHERE operator_type = 'TableScan';| ORDERS | REVENUE |
|---|---|
| 43692 | 6577454322 |
| ORDERS | REVENUE |
|---|---|
| 43692 | 6577454322 |
| TBL | SCANNED | TOTAL | BYTES_SCANNED |
|---|---|---|---|
| random | 24 | 24 | 73220096 |
| sorted | 1 | 24 | 753664 |
Same rows, same answer. But on the randomly ordered table every micro-partition had some March 1996 dates, so Snowflake had to read all 24 (73 MB). On the sorted table, one micro-partition held the whole week: 0.75 MB, about 97 times less. On our X-Small warehouse both queries finished in under 200 ms because 15 million rows is small for Snowflake; on a table 1,000 times bigger, that factor of 97 is the difference between seconds and many minutes (and credits).
-- How well is each table clustered on o_orderdate? (lower depth = better)
SELECT 'random' AS tbl,
PARSE_JSON(SYSTEM$CLUSTERING_INFORMATION('big_orders', '(o_orderdate)')):average_depth::NUMBER(10,1) AS average_depth
UNION ALL
SELECT 'sorted',
PARSE_JSON(SYSTEM$CLUSTERING_INFORMATION('big_orders_sorted', '(o_orderdate)')):average_depth::NUMBER(10,1);| TBL | AVERAGE_DEPTH |
|---|---|
| random | 24.0 |
| sorted | 2.0 |
Clustering depth measures how many micro-partitions overlap for the same value. 24 means every partition overlaps every other (no pruning possible); close to 1 is ideal.
Clustering keys
Data loaded in date order (like ShopKart's daily files) is naturally clustered by date. When it isn't, or your filters use another column, you can define a clustering key, and Snowflake's Automatic Clustering service keeps re-sorting the table in the background:
-- Ask Snowflake to keep big_orders clustered by date, automatically, in the background
ALTER TABLE big_orders CLUSTER BY (o_orderdate);
SHOW TABLES LIKE 'BIG_ORDERS';| name | rows | cluster_by | automatic_clustering |
|---|---|---|---|
| BIG_ORDERS | 15000000 | LINEAR(o_orderdate) | ON |
Reclustering runs on Snowflake's serverless compute whenever Snowflake decides the table would benefit, and bills credits for it. For our small 24-partition table, nothing had been reclustered when we checked a while later. That's normal: Snowflake doesn't spend credits re-sorting small tables, which is exactly why clustering keys are for big ones.
| Add a clustering key when... | Don't, when... |
|---|---|
| The table is large (many thousands of micro-partitions, often 1 TB+) | The table is small: pruning barely matters |
| Queries filter or join on the same columns again and again | Every query filters on different columns |
| Query Profile shows most partitions scanned for selective filters | Data already arrives in filter order (e.g. by date) |
| The table changes slowly | The table is rewritten constantly (reclustering never ends, costs a lot) |
Choose columns used in filters, with a sensible number of distinct values: a date (not a timestamp to the second), a region, a category. You can cluster on expressions like TO_DATE(order_ts).
More ways to read less
| Do | Because |
|---|---|
| SELECT only the columns you need | Storage is columnar: SELECT * reads every column |
| Filter early, on raw columns | WHERE YEAR(order_ts) = 2026 can prune less than WHERE order_ts >= '2026-01-01' |
| Make joins one-to-one where expected | A missing join key creates an 'exploding join' (rows multiply) |
| Use LIMIT for exploring | Snowflake can stop early |
| Search Optimization Service (Enterprise) | Fast point lookups (WHERE email = ...) on huge tables |
| Materialized views / dynamic tables | Pre-compute expensive aggregations that many people query |
Rule 2: read the Query Profile
In Snowsight, open Monitoring โ Query History, click a query, then Query Profile. It shows the query's steps as a tree with the time spent in each. What to look for:
| You see | It means | Fix |
|---|---|---|
| Partitions scanned โ partitions total on a filtered query | No pruning | Better filters, clustering, or reorder the data |
| Bytes spilled to local / remote storage | Not enough memory | Process less data; bigger warehouse for that job |
| A Join with far more output rows than input | Exploding join (duplicate keys) | Fix join keys; de-duplicate first |
| Most time in one TableScan | Reading lots of data | Fewer columns, better pruning |
| Queued time (in Query History) | Warehouse is busy | Multi-cluster warehouse, or move workloads apart |
You can get the same numbers in SQL with GET_QUERY_OPERATOR_STATS(query_id), which is how we measured pruning above.
Rule 3: size and run warehouses well
| Lever | Guideline |
|---|---|
| Separate warehouses per workload | Loading, transformations, BI, data science: easier sizing and clear costs |
| Right size | Start X-Small or Small; size up only if big queries are slow or spill. Each size doubles credits per hour. |
| AUTO_SUSPEND | 60 s for ad-hoc and ELT; a few minutes for busy BI warehouses (keeps the cache warm) |
| Multi-cluster for concurrency | Many users queuing โ more clusters (Enterprise), not a bigger size |
| Batch small jobs | Ten jobs at 10-minute intervals wake the warehouse ten times (60 s minimum each) |
| Query timeouts | STATEMENT_TIMEOUT_IN_SECONDS stops runaway queries |
Rule 4: watch and cap the spend
The very first thing we did on our trial account was cap the course warehouses:
-- Run by ACCOUNTADMIN: a credit limit for the course warehouses (we set this up first thing)
CREATE RESOURCE MONITOR IF NOT EXISTS tt_monitor
WITH CREDIT_QUOTA = 20 -- credits per month
TRIGGERS ON 80 PERCENT DO NOTIFY -- email the admins
ON 100 PERCENT DO SUSPEND; -- stop new queries, let running ones finish
ALTER WAREHOUSE shopkart_wh SET RESOURCE_MONITOR = tt_monitor;At 80% of 20 credits the admins get an email; at 100% the warehouses stop accepting new queries. You can also set DO SUSPEND_IMMEDIATE (cancel running queries too) and monitors for the whole account. Resource monitors only watch warehouses; serverless features (Snowpipe, serverless tasks, clustering) are tracked with budgets.
-- Run by ACCOUNTADMIN: credits per warehouse per day (ACCOUNT_USAGE can lag by up to 3 hours)
SELECT warehouse_name,
start_time::DATE AS day,
ROUND(SUM(credits_used), 2) AS credits
FROM snowflake.account_usage.warehouse_metering_history
WHERE start_time >= DATEADD(day, -7, CURRENT_DATE())
GROUP BY 1, 2
ORDER BY credits DESC;| WAREHOUSE_NAME | DAY | CREDITS |
|---|---|---|
| SHOPKART_WH | 2026-11-22 | 0.57 |
| CLOUD_SERVICES_ONLY | 2026-11-21 | 0.00 |
| CLOUD_SERVICES_ONLY | 2026-11-22 | 0.00 |
| TT_WH | 2026-11-22 | 0.00 |
| COMPUTE_WH | 2026-11-22 | 0.00 |
That's our real warehouse bill for building this course on an X-Small warehouse, including the 15-million-row tables: about half a credit (the view can lag by a few hours). Short queries plus a 60-second auto-suspend keep costs tiny.
SNOWFLAKE.ACCOUNT_USAGE has views for everything: WAREHOUSE_METERING_HISTORY, QUERY_HISTORY (find the most expensive queries), AUTOMATIC_CLUSTERING_HISTORY, PIPE_USAGE_HISTORY and more. Snowsight's Admin โ Cost Management page draws them as charts.
A cost checklist for interviews (and real life)
| # | Check |
|---|---|
| 1 | Every warehouse has auto-suspend and auto-resume |
| 2 | Warehouses are right-sized and separated by workload |
| 3 | Resource monitors and budgets alert before money runs out |
| 4 | Expensive queries are found (QUERY_HISTORY) and tuned with Query Profile |
| 5 | Large tables prune well; clustering only where it pays off |
| 6 | Dynamic table lags and task schedules match real business needs |
| 7 | Transient tables and shorter Time Travel for re-creatable, high-churn data |
| 8 | Use the result cache: identical dashboard queries are free for 24 h |
๐ฏ Interview questions on this topic
Try to answer out loud first, then tap to check.
Q1How do you improve query performance in Snowflake?Fresher+
Q2What is a clustering key and when would you use one?1โ3 yrs+
Q3What does spilling mean and how do you fix it?1โ3 yrs+
Q4How do you control Snowflake costs?1โ3 yrs+
Q5Dashboards are slow every morning at 9 a.m. but fine at noon. How do you diagnose it?3+ yrs+
Key takeaways
- โOrdering data for your filters cut bytes read by about 97 times.
- โMeasure with Query Profile and metering before changing anything.
- โMost savings come from warehouse habits: size, suspend, separate.
- โCap spending from day one with resource monitors and budgets.
Frequently asked questions
Does Snowflake need indexes?
Not for normal analytics. Snowflake skips micro-partitions using min/max metadata (pruning), so what matters is how well the data is ordered for your filters. For very large tables you can add a clustering key; for needle-in-a-haystack lookups there's the Search Optimization Service (Enterprise).
When should I add a clustering key?
Only on large tables (roughly a terabyte or more, or thousands of micro-partitions) that are queried with filters on the same columns, where Query Profile shows poor pruning. Small tables don't benefit, and automatic clustering costs credits to maintain, especially on tables that change a lot.
What is spilling?
When a query needs more memory than the warehouse has, Snowflake writes intermediate data to local disk, then to remote storage. It makes queries much slower. Fix it by processing less data (filter early, avoid exploding joins) or using a bigger warehouse.
What usually costs the most in Snowflake?
Warehouse compute, by far: warehouses left running, too big for their work, or woken up constantly by frequent jobs and dashboards. Storage is usually small. Serverless features (Snowpipe, tasks, clustering, dynamic tables on serverless) add up too, so watch them.
How do I stop a surprise bill?
Resource monitors with credit quotas that notify and suspend warehouses, budgets for serverless features, auto-suspend on every warehouse, a dedicated warehouse per workload so you can see who uses what, and a weekly look at WAREHOUSE_METERING_HISTORY.
๐ง Quick check: performance and cost
1. Our filter on the randomly ordered table scanned 24 of 24 micro-partitions. On the sorted table?
2. SYSTEM$CLUSTERING_INFORMATION average_depth: which is better?
3. A query spills gigabytes to remote storage. First thing to try?
4. Which does a resource monitor control?
5. Best warehouse setup for ELT jobs and BI dashboards?
Checking your accessโฆ