CertSafari
    Snowflake SnowPro Advanced: Data Engineer (DEA-C02)· Lessons

    Domain 3 · Lesson 12/22

    Clustering depth, clustering keys and Automatic Clustering

    Use system functions to analyze micro-partitions.

    19 min read
    4.67% of exam
    5 sources
    Published 20 Oct 2026
    Docs as of 18 Oct 2026

    What you will be able to do

    • Explain what clustering depth and overlap measure, and why an empty table reports 0 and a populated one at least 1
    • Call SYSTEM$CLUSTERING_DEPTH and SYSTEM$CLUSTERING_INFORMATION with the right arguments and read their output
    • Decide when a table is worth a clustering key, and choose key columns and expressions with suitable cardinality
    • Describe how Automatic Clustering reclusters in the background, how to suspend or resume it, and how Optima Clustering differs from Clustering Classic

    Key concept

    Clustering depth — Clustering depth is the average number of micro-partitions whose value ranges overlap, measured for a chosen set of columns. A low depth means a filter on those columns only has to touch a few partitions. A high depth means the same values are spread across many partitions.

    1.What clustering depth and overlap measure

    Clustering depth tells you how far apart the rows for one value are spread across micro-partitions. Snowflake splits every table into micro-partitions and stores metadata for each one, and pruning uses that metadata to skip partitions a query does not need (see Micro-partitions and pruning). The metadata that matters here is the range of values each column holds in each partition. Snowflake records the minimum and maximum of every column, partition by partition.

    Two partitions overlap on a column when their value ranges intersect. Suppose partition 1 holds sale_date values from January to June and partition 2 holds March to September. A filter on April cannot skip either of them. Depth counts how many partitions are stacked over the same point in the value range. Snowflake tracks three numbers for a table: the total number of micro-partitions, how many of them overlap on a given set of columns, and the depth of that overlap. Clustering depth is the average of that depth across the table. The smaller it is, the fewer partitions a query on those columns has to open.

    The scale has a fixed floor. A populated table always has a depth of 1 or more, because every value sits in at least one partition. An empty table has no micro-partitions, so its clustering depth is 0, even if a clustering key is already defined. At the good end of the scale, a partition whose range overlaps no other partition is in a constant state: reclustering cannot improve it, so maintenance leaves it out when computing depth and overlap. Large tables never need every partition to reach a constant state. It is neither likely nor required for good query performance.

    Checkpoint 1 of 9· Check yourself

    A multi-terabyte sales table reports an average clustering depth of 6 on sale_date. Queries that filter on sale_date still meet their response-time targets and have not slowed down over the past months. What is the best conclusion?

    Sources12

    2.Reading SYSTEM$CLUSTERING_DEPTH and SYSTEM$CLUSTERING_INFORMATION

    Snowflake exposes this metadata through two system functions. SYSTEM$CLUSTERING_DEPTH returns one number: the average depth of the table, measured either on the columns you pass or on the table's clustering key. SYSTEM$CLUSTERING_INFORMATION returns a JSON string that includes that depth along with the partition counts, overlap figures and the clustering version. Neither function needs a clustering key to exist. You can measure any columns of any table, which is how you test whether a table that has no key would benefit from one.

    SYSTEM$CLUSTERING_DEPTH syntax: every argument is a quoted string, and the optional predicate is written without WHEREsql
    SYSTEM$CLUSTERING_DEPTH( '<table_name>' , '( <col1> [ , <col2> ... ] )' [ , '<predicate>' ] )

    Whether you must pass the column list depends on whether the table has a key. On a table without a clustering key, SYSTEM$CLUSTERING_DEPTH needs the column list and returns an error if you leave it out. On a clustered table the list is optional, and if you omit it the function measures the defined key. SYSTEM$CLUSTERING_INFORMATION follows the same pattern. On a clustered table the table name is enough. On an unclustered table, or to test other columns than the key, you add the columns as a second argument, such as '(sale_date)'. The optional predicate of SYSTEM$CLUSTERING_DEPTH limits the calculation to a range of values.

    Part of a real SYSTEM$CLUSTERING_INFORMATION result for a table measured on (col1, col3)text
    "cluster_by_keys" : "LINEAR(COL1, COL3)", | | "version" : "CLASSIC", | | "total_partition_count" : 1156, | | "total_constant_partition_count" : 0, | | "average_overlaps" : 117.5484, | | "average_depth" : 64.0701,

    That table is badly clustered, and three fields show it. None of its 1,156 partitions has reached a constant state. average_overlaps is high, so each partition shares its value range with many others. average_depth is high too, so a query on those columns has to open many partitions for any single value. A table at depth 850 with 700 average overlaps is the same diagnosis at a larger scale: its partitions overlap heavily on the measured key, and a filter on that key scans far more partitions than it would on a table with depth near 4. Depth describes how the partitions are laid out. It does not depend on the warehouse that runs the function, and it is not a placeholder.

    Fields in the SYSTEM$CLUSTERING_INFORMATION JSON result
    FieldWhat it tells you
    cluster_by_keysThe columns or expressions the figures were measured on; these can be any columns in the table
    versionCLASSIC or OPTIMA: which Automatic Clustering version the table uses
    notesSuggestions for more efficient clustering, such as a warning that the clustering column's cardinality is extremely high; may be empty
    total_partition_countTotal number of micro-partitions in the table
    total_constant_partition_countPartitions in a constant state on these columns; the higher it is, the more partitions queries can prune. Not available under Optima Clustering
    average_overlaps / average_depthHow much partition value ranges overlap, and the average depth of that overlap
    partition_depth_histogramHow many partitions fall into each depth bucket. Not available under Optima Clustering

    Checkpoint 2 of 9· Check yourself

    You suspect a large events table, which has no clustering key, would benefit from clustering on event_date. Before changing the table, you want to measure how well it is clustered on that column today. Which approach works?

    Checkpoint 3 of 9· Exam question

    A data engineer runs SYSTEM$CLUSTERING_INFORMATION('sales_fact', '(sale_date)') on a 40 TB table and sees average_depth of 850 with average_overlaps of 700, while a similarly sized table with well-tuned clustering reports a depth near 4. What does the high average_depth value most directly indicate?

    Sources324

    3.When a clustering key is worth its cost

    A clustering key tells Snowflake which columns or expressions to use to keep related rows in the same micro-partitions. Once a table has a key, Snowflake handles the maintenance itself. That maintenance costs money, though. Clustering the data the first time uses credits, and so does keeping it clustered. Each recluster also writes new micro-partitions, and the old ones stay in Time Travel and Fail-safe for at least 8 days, or up to 97 days with extended Time Travel. Even a few new rows can force Snowflake to rewrite every partition that holds those values. A key is worth it only if queries are fast enough to pay for all of this, or if you need the fastest possible response time whatever the cost.

    A table is a good candidate when it meets all of these criteria:

    • It holds a large number of micro-partitions, typically multiple terabytes of data.
    • Its queries are selective (they read a small share of rows) or they sort the data, for example with ORDER BY.
    • Most queries filter or sort on the same few columns.
    • It is queried often and changed rarely, so queries far outnumber INSERT, UPDATE and DELETE statements.

    Two signs suggest a table needs a key: queries are slower than expected or have degraded over time, and its clustering depth is large. Before adding a key, run a representative set of queries to set a performance baseline, and start with one or two tables. If a table you want to cluster gets a lot of DML, combine those statements into large, infrequent batches. You can set a key with CREATE TABLE ... CLUSTER BY, and add, change or drop it later with ALTER TABLE. Hybrid tables cannot have one, because their data is always ordered by primary key.

    Pick key columns by how queries use them. The first choice is columns that appear in selective filters, such as invoice_date in date-range queries. If there is room for more, add columns used in join predicates. Columns used only in GROUP BY or ORDER BY help less. When they compete with filter or join columns, choose the filter and join columns. Keep the key to three or four columns or expressions. Beyond that, costs usually rise faster than the benefit. Key columns can be any data type except GEOGRAPHY, VARIANT, OBJECT or ARRAY. Expressions on paths inside a VARIANT column are allowed.

    Checkpoint 4 of 9· Check yourself

    Your team wants to try a clustering key on just one table first. Which table is the strongest candidate?

    Sources2

    4.Choosing key cardinality

    Cardinality, the number of distinct values in a key, has to sit between two limits. It must be high enough for pruning to skip partitions, and low enough for Snowflake to group rows that share a value into the same micro-partitions. A key outside that range fails in one of two ways.

    A key with too few values gives little pruning. A Boolean column such as IS_NEW_CUSTOMER or is_refunded has only two values. Every partition still ends up holding rows for one or both of them, so a filter on the flag skips almost nothing. The type is not the problem: Booleans are allowed as keys, and so are non-numeric columns. The problem is that two values cannot split a multi-terabyte table into many narrow ranges. An event-type column has the same weakness if the table has only a handful of event types.

    A key with too many values costs more than it returns. The higher a key's cardinality, the more it costs to keep the table clustered on it. A unique key or a nanosecond timestamp is rarely worth it unless the table is used mainly for point lookups. The fix is to cluster on an expression over the column that has fewer distinct values but keeps their order. TO_DATE(event_time) reduces billions of timestamps to one value per day. Because each partition's minimum and maximum still follow date order, range filters can still prune. Watch the notes field of SYSTEM$CLUSTERING_INFORMATION, which may warn you when a key's cardinality is extremely high.

    Clustering on expressions: a timestamp cast to a date, and a string cut to its first ten characterssql
    CREATE OR REPLACE TABLE t2 (c1 timestamp, c2 STRING, c3 NUMBER) CLUSTER BY (TO_DATE(C1), substring(c2, 0, 10));

    Checkpoint 5 of 9· Fill the gap

    Column c1 holds high-precision timestamps. To make it a workable clustering key, the key must have fewer distinct values but still keep their order, so range filters on c1 can still prune. Which function completes the key?

    CREATE OR REPLACE TABLE t2 (c1 timestamp, c2 STRING, c3 NUMBER) CLUSTER BY ( ? (C1), substring(c2, 0, 10));

    Checkpoint 6 of 9· Exam question

    A team defines a clustering key directly on an event_time column stored with nanosecond precision on a 5 TB events table, expecting better pruning, but query latency and clustering depth do not improve after reclustering completes. What is the most likely cause and correct fix?

    Checkpoint 7 of 9· Exam question

    An analyst is considering a clustering key for a transactions table and is deciding between the is_refunded boolean flag and the customer_id column, which has millions of distinct values. Why is is_refunded a poor clustering key choice on its own?

    Sources24

    5.How Automatic Clustering maintains a key

    Automatic Clustering is the Snowflake service that reclusters clustered tables. Once a key is defined, you do not monitor the table or assign a warehouse. Snowflake watches DML on the table, decides when reclustering would help, and runs it on its own serverless compute. Reclustering is DML in its own right: it deletes the affected rows and inserts them again, grouped by the key. It does not block your own DML on the table while it runs. Snowflake reclusters only when the table would benefit, so defining a key does not rewrite anything right away.

    Suspending Automatic Clustering on a table; RESUME RECLUSTER turns it back onsql
    ALTER TABLE t1 SUSPEND RECLUSTER;

    You can pause clustering on one table, or stop it altogether. ALTER TABLE ... SUSPEND RECLUSTER stops all reclustering on the table, and therefore its clustering charges, until you run RESUME RECLUSTER. Dropping the clustering key ends all future reclustering. Check a table's status in the automatic_clustering column of SHOW TABLES, or in the AUTO_CLUSTERING_ON column of the TABLES views. Three behaviours catch people out:

    • A table created with CREATE TABLE ... CLONE from a clustered table starts with Automatic Clustering suspended, even when the source table's clustering is running. This also applies when you clone the whole schema or database.
    • Changing the clustering key resumes Automatic Clustering. Re-running ALTER TABLE ... CLUSTER BY with the word LINEAR added counts as a change, even if the columns stay the same.
    • Resuming clustering on a table that has had a lot of DML, or whose key has changed, can trigger a large amount of reclustering and the credits that go with it.

    Checkpoint 8 of 9· Fill the gap

    A clustered table t1 is running up clustering charges during a month-long bulk backfill. You want to stop all reclustering for now but keep the clustering key so you can turn maintenance back on afterwards. Which keyword completes the statement?

    ALTER TABLE t1  ?  RECLUSTER;

    Sources5

    6.Optima Clustering and Clustering Classic

    Automatic Clustering now comes in two versions. Optima Clustering is the newer engine, and tables that get a clustering key on or after September 1, 2026 use it. Clustering Classic keeps running on tables that were already clustered before then. Those tables stay on Classic indefinitely. Changing their key with ALTER TABLE does not move them to Optima, and there is no migrate command. To see which version a table uses, check the version field of SYSTEM$CLUSTERING_INFORMATION. To compare costs over time, query the VERSION column of the AUTOMATIC_CLUSTERING_HISTORY view.

    Optima Clustering and Clustering Classic compared
    AspectOptima ClusteringClustering Classic
    Which tables use itTables that get a clustering key on or after September 1, 2026Tables that were already clustered, indefinitely
    Key length usedUp to 1 KB in total across all key columnsOnly the first 5 bytes of each key column
    Billing basisUncompressed GB ingested × per-GB rate × overlap factorServerless compute for the first clustering and ongoing maintenance, plus any extra Fail-safe storage
    Fields missing from SYSTEM$CLUSTERING_INFORMATIONtotal_constant_partition_count and partition_depth_histogramNone
    Suspending to save moneyGenerally not cost-effective, because resuming charges a catch-up cost for data ingested while suspendedStops reclustering credits while suspended

    Optima's charges depend on how your data arrives. The overlap factor runs from 0 to 1 and measures how much of the newly ingested data needs active clustering. Hourly appends clustered on TO_DATE(ingestion_time) arrive already in order, so the factor is close to 0 and the charge is small or zero. Updates that change key values usually have a factor of 1 and are billed at the full rate. In both versions, changing the key triggers a one-time clustering cost. Under Optima, that cost is based on the table's size at the time of the change. To stop paying for Optima clustering for good, drop the key rather than suspending it.

    The 5-byte limit in Classic changes how you design string keys. If the first characters of a column are the same in every row, such as a shared prefix, Classic sees almost no distinct values. The fix is to cluster on a substring that starts after the shared characters.

    Clustering on a substring that skips a shared prefixsql
    create or replace table t3 (vc varchar) cluster by (SUBSTRING(vc, 5, 5));

    Checkpoint 9 of 9· Check yourself

    A sales table got its clustering key in March 2026. In October 2026, a data engineer runs ALTER TABLE ... CLUSTER BY to give it a new key, hoping to move it to Optima Clustering's ingestion-based billing. What happens to the table's Automatic Clustering version?

    Sources52

    Sources

    (5)

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

    1. 1.
      “The range of values for each of the columns in the micro-partition.”
      ↩︎ What clustering depth and overlap measure
      “A table with no micro-partitions (i.e. an unpopulated/empty table) has a clustering depth of 0.”
      ↩︎ What clustering depth and overlap measure
      “The clustering depth for a table is not an absolute or precise measure of whether the table is well-clustered.”
      ↩︎ What clustering depth and overlap measure
      “The smaller the average depth, the better clustered the table is with regards to the specified columns.”
      ↩︎ Key concept
      “If queries on a table are performing as needed or expected, the table is likely well-clustered.”
      ↩︎ Checkpoint
    2. 2.
      “is therefore excluded when computing depth and overlap for future maintenance”
      ↩︎ What clustering depth and overlap measure
      “This function can be run on any columns on any table, regardless of whether the table has an explicit clustering key”
      ↩︎ Reading SYSTEM$CLUSTERING_DEPTH and SYSTEM$CLUSTERING_INFORMATION
      “The table contains a large number of micro-partitions. Typically, this means that the table contains multiple terabytes (TB) of data.”
      ↩︎ When a clustering key is worth its cost
      “clustering is generally most cost-effective for tables that are queried frequently and do not change frequently.”
      ↩︎ When a clustering key is worth its cost
      “minimum of 8 days and up to 97 days for extended Time Travel”
      ↩︎ When a clustering key is worth its cost
      “For most tables, Snowflake recommends a maximum of 3 or 4 columns (or expressions) per key.”
      ↩︎ When a clustering key is worth its cost
      “which can be of any data type, except GEOGRAPHY, VARIANT, OBJECT, or ARRAY”
      ↩︎ When a clustering key is worth its cost
      “favor the columns used in the filter and join operations”
      ↩︎ When a clustering key is worth its cost
      “A column with very low cardinality might yield only minimal pruning, such as a column named IS_NEW_CUSTOMER that contains only Boolean values.”
      ↩︎ Choosing key cardinality
      “In general, if a column (or expression) has higher cardinality, then maintaining clustering on that column is more expensive.”
      ↩︎ Choosing key cardinality
      “Clustering Classic: For each column in the clustering key, Clustering Classic uses only the first 5 bytes.”
      ↩︎ Optima Clustering and Clustering Classic
      “The expression should preserve the original ordering of the column so that the minimum and maximum values in each partition still enable pruning.”
      ↩︎ Exam trap 1
      “a column that contains nanosecond timestamp values would not make a good clustering key.”
      ↩︎ Prediction
    3. 3.
      “The average depth of a populated table (i.e. a table containing data) is always 1 or more.”
      ↩︎ Reading SYSTEM$CLUSTERING_DEPTH and SYSTEM$CLUSTERING_INFORMATION
      “For a table with no clustering key, this argument is required. If this argument is omitted, an error is returned.”
      ↩︎ Reading SYSTEM$CLUSTERING_DEPTH and SYSTEM$CLUSTERING_INFORMATION
      “if the argument is omitted, Snowflake uses the defined clustering key to calculate the depth.”
      ↩︎ Reading SYSTEM$CLUSTERING_DEPTH and SYSTEM$CLUSTERING_INFORMATION
    4. 4.
      “This example indicates that the test2 table is not well-clustered for the following reasons:”
      ↩︎ Reading SYSTEM$CLUSTERING_DEPTH and SYSTEM$CLUSTERING_INFORMATION
      “High average of overlap depth across micro-partitions.”
      ↩︎ Reading SYSTEM$CLUSTERING_DEPTH and SYSTEM$CLUSTERING_INFORMATION
      “this field might contain a warning if the cardinality of the clustering column is extremely high”
      ↩︎ Choosing key cardinality
      “For tables that use Optima Clustering, the following fields aren’t available: total_constant_partition_count partition_depth_histogram”
      ↩︎ Exam trap 4
    5. 5.
      “Snowflake performs automatic reclustering in the background, and you do not need to specify a warehouse to use.”
      ↩︎ How Automatic Clustering maintains a key
      “Automatic Clustering is transparent and does not block DML statements issued against tables while they are being reclustered.”
      ↩︎ How Automatic Clustering maintains a key
      “is considered a change to the clustering key even if the column doesn’t change.”
      ↩︎ How Automatic Clustering maintains a key
      “Starting September 1, 2026, newly clustered tables use Optima Clustering.”
      ↩︎ Optima Clustering and Clustering Classic
      “Clustering cost = uncompressed GB ingested × per uncompressed GB billing rate × overlap factor”
      ↩︎ Optima Clustering and Clustering Classic
      “Using suspend and resume primarily to control costs is generally not cost-effective under Optima Clustering.”
      ↩︎ Optima Clustering and Clustering Classic
      “The new table starts with Automatic Clustering suspended, even if Automatic Clustering for the source table is not suspended.”
      ↩︎ Exam trap 2
      “Changing the clustering key with an ALTER TABLE statement doesn’t move a table to Optima Clustering, and there is no migrate command.”
      ↩︎ Exam trap 3
      “Changing the clustering key with an ALTER TABLE statement doesn’t move a table to Optima Clustering, and there is no migrate command.”
      ↩︎ Checkpoint

    Ready to test yourself?

    Practise the 18 questions on this subdomain.

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