CertSafari
    Databricks Certified Data Engineer Associate· Lessons

    Domain 6 · Lesson 28/33

    Liquid clustering and predictive optimization on Databricks

    Understand the features of Liquid Clustering and predictive optimization

    19 min read
    2% of exam
    3 sources
    Published 22 Oct 2026
    Docs as of 30 Sep 2026

    What you will be able to do

    • Enable liquid clustering with CLUSTER BY on new and existing tables, and choose up to four clustering keys
    • Explain why changing clustering keys leaves existing files alone, and use OPTIMIZE FULL to recluster them
    • Convert a partitioned table to liquid clustering with REPLACE PARTITIONED BY WITH CLUSTER BY
    • Describe how CLUSTER BY AUTO selects and changes keys, and why it depends on predictive optimization
    • State which operations predictive optimization runs, which tables it skips, and how its setting is inherited from account to table
    • Find predictive optimization history and skip reasons in system tables and Catalog Explorer

    Key concept

    Liquid clustering — A data layout in which a Delta or Iceberg table declares clustering keys and OPTIMIZE groups files by those keys incrementally. You can change the keys at any time without rewriting the table, and it takes the place of both partitioning and ZORDER.

    1.Why liquid clustering replaces partitioning and ZORDER

    Liquid clustering controls how a table's rows are laid out in its files. Similar rows sit together, so a query filtering on a clustering key can skip files that cannot match. It does the jobs that Hive-style partitioning and ZORDER used to do, with one big difference: you can redefine the clustering keys without rewriting the data already in the table. A partition column is fixed when the table is created. Clustering keys can change as the queries against the table change.

    A table uses one layout scheme, never a mix. Clustering is not compatible with partitioning or ZORDER, so a table is clustered or it is partitioned, never both. This affects tooling too: nothing about liquid clustering depends on Z-order statistics, and adding ZORDER to a clustered table is not an option. Liquid clustering is generally available for Delta Lake tables on Databricks Runtime 15.4 LTS and above, is in Public Preview for Apache Iceberg tables, and also works for streaming tables and materialized views.

    Databricks recommends liquid clustering for every new table. It helps most in the places where partitioning causes trouble:

    • queries that filter on high-cardinality columns
    • tables with heavy data skew
    • fast-growing tables that would otherwise need constant tuning
    • tables with concurrent writers
    • tables whose access patterns vary or change over time
    • tables where any partition key would return too many or too few partitions

    Checkpoint 1 of 9· Check yourself

    Queries on a new events table filter mostly on customer_id, a high-cardinality column. The team expects those filter patterns to change over the next year. Which layout setup fits Databricks guidance?

    Sources1

    2.Enabling CLUSTER BY and choosing keys

    You turn clustering on by adding CLUSTER BY to the table definition. In a CREATE TABLE ... AS SELECT, the clause goes right after the table name, not inside the SELECT. In Python and Scala, clusterBy(...) on the DataFrame writer or the DeltaTable builder does the same thing. DataFrame writers can only set clustering keys when they create or overwrite the table. An append can't change them, so you change keys with SQL ALTER TABLE, separately from the write.

    Creating an empty table clustered on one columnsql
    CREATE TABLE table1 (col0 INT, col1 STRING) CLUSTER BY (col0);

    On an existing table that is not partitioned, use ALTER TABLE ... CLUSTER BY (...). Enabling clustering upgrades a Delta table to writer version 7 and reader version 3. Clients that don't support those protocols can no longer read it, and the protocol can't be downgraded.

    Enabling liquid clustering on an existing unpartitioned Delta tablesql
    ALTER TABLE <table_name>
    CLUSTER BY (<clustering_columns>)

    A table can have at most four clustering keys. Pick them from the columns that appear most often in query filters. The order in which you list them doesn't matter. If two columns are highly correlated, one of them is enough. More keys isn't always better: on tables under 10 TB, filtering on a single column performs worse with four keys than with two, although the gap disappears as the table grows. Every key also needs statistics collected, and by default a Delta table collects statistics only for its first 32 columns. A key placed at column 40 therefore needs its statistics configuration changed first.

    Checkpoint 2 of 9· Fill the gap

    This PySpark snippet creates table2 from a DataFrame and enables liquid clustering on col0. Which writer method goes in the blank?

    df = spark.read.table("table1")
    df.write. ? ("col0").saveAsTable("table2")

    Checkpoint 3 of 9· Exam question

    How many columns can be specified as liquid clustering keys on a single Delta table?

    Sources1

    3.OPTIMIZE does the clustering, and changing keys does not recluster

    Declaring keys organizes nothing. **OPTIMIZE is what clusters the data**, and it works incrementally: each run rewrites only the files that haven't been clustered yet. That's why most OPTIMIZE runs on a clustered table finish quickly. Without predictive optimization, Databricks recommends scheduling OPTIMIZE yourself, every one or two hours for tables with many inserts or updates.

    Because changing keys costs almost nothing, existing files keep the layout of the old keys. ALTER TABLE ... CLUSTER BY (new_column1, new_column2) only changes how later writes and later OPTIMIZE runs lay out data. Setting the keys to NONE works the same way: it doesn't undo the layout already written, it just stops future OPTIMIZE runs from clustering.

    Forcing every record to be reclustered under the current keyssql
    OPTIMIZE table_name FULL;

    **OPTIMIZE ... FULL is the command that rewrites existing data to match the current keys.** Run it when you first enable clustering on a table that already holds data, or after you change keys. On a large table that was never clustered on those keys, it can take hours. When the keys haven't changed since the last FULL run, FULL behaves exactly like plain OPTIMIZE. OPTIMIZE ... FULL WHERE <predicate> reclusters only the files whose ranges overlap the predicate. VACUUM has nothing to do with layout: it deletes data files the table no longer references, which saves storage and changes no clustering.

    What each command does to a clustered table's existing files
    CommandEffect on existing files
    ALTER TABLE ... CLUSTER BY (cols)None. Later writes and OPTIMIZE runs use the new keys
    OPTIMIZE table_nameIncremental. Rewrites only files not yet clustered
    OPTIMIZE table_name FULLReclusters all existing data under the current keys
    ALTER TABLE ... CLUSTER BY NONENone. Future OPTIMIZE runs stop using clustering keys
    VACUUMDeletes data files no longer referenced by the table; no layout change

    Partitioned tables can be migrated in place. On Databricks Runtime 18.1 and above, ALTER TABLE ... REPLACE PARTITIONED BY WITH CLUSTER BY converts a partitioned Delta table, managed or external, with minimal reader and writer downtime. With no columns listed, the partition columns become the clustering keys. With AUTO, they become the starting keys and predictive optimization adjusts them over time. Listing very different columns triggers a large recluster on the first OPTIMIZE, so Databricks recommends staying close to the old partition columns. If a table previously used ZORDER BY, use those columns as keys. If it used a generated column such as a date derived from a timestamp, cluster on the original column instead.

    Converting a table partitioned on (year, month, day) to cluster on different columnssql
    ALTER TABLE t1 REPLACE PARTITIONED BY WITH CLUSTER BY (day, id);
    OPTIMIZE t1;

    To confirm a conversion worked, DESCRIBE EXTENDED should show the new clustering columns. DESCRIBE HISTORY should show REORG operations, an UPGRADE PROTOCOL operation and the REPLACE PARTITIONED BY WITH CLUSTER BY operation.

    Checkpoint 4 of 9· Check yourself

    After the clustering keys of a large Delta table were switched from store_id to region last week, scheduled OPTIMIZE jobs have run normally. Queries filtering on region still read many older files. Which command brings the existing data in line with the new keys?

    Checkpoint 5 of 9· Exam question

    A 20 TB liquid-clustered sales table was originally clustered on store_id. A data engineer runs ALTER TABLE sales CLUSTER BY (region, product_category) and wants every existing file in the table to reflect the new keys before the next quarterly report runs tonight. Which command accomplishes this?

    Sources12

    4.Automatic liquid clustering with CLUSTER BY AUTO

    **CLUSTER BY AUTO lets Databricks choose the clustering keys and change them later.** It works on Unity Catalog managed Delta tables (Databricks Runtime 15.4 LTS and above), managed Iceberg v3 tables (Runtime 18.0 and above), and materialized views and streaming tables, including those defined in Lakeflow pipelines. It doesn't work on managed Iceberg v2 tables. The feature needs predictive optimization, which handles both picking the keys and running the clustering asynchronously.

    Giving initial key hints, then handing key selection to Databrickssql
    ALTER TABLE table1 CLUSTER BY (c1, c2);
    ALTER TABLE table1 CLUSTER BY AUTO;

    Key selection follows the workload. Databricks looks at the table's query history and picks the best candidate columns. When query patterns or data distributions shift, for example when analysts move from filtering on customer_id to filtering on region and order_date, it selects new keys without anyone running ALTER TABLE or OPTIMIZE FULL. The change has a cost condition: keys change only when the predicted savings from better data skipping outweigh the cost of reclustering. As a result, a table on AUTO can keep its current keys for a long time without anything being wrong.

    Sometimes no keys are chosen at all, for one of several reasons:

    • the table is too small to benefit
    • its current layout, from earlier manual keys or from the natural insertion order, already matches the queries
    • the table isn't queried often
    • the workload isn't running on Databricks Runtime 15.4 LTS or above, which writes the metadata that key selection depends on

    For a specific table, the reason appears on the Catalog Explorer History tab: click the AUTO LIQUID row labelled Not applied.

    AUTO is easy to lose by accident. Running CREATE OR REPLACE on the table without repeating CLUSTER BY AUTO turns automatic clustering off and drops the columns it had chosen. A nightly job that rebuilds the table with a plain CREATE OR REPLACE resets the layout on every run. To check the current state, run DESCRIBE TABLE or SHOW TBLPROPERTIES: clusterByAuto is true when AUTO is on, and clusteringColumns lists the current keys. ALTER TABLE ... CLUSTER BY NONE turns AUTO off. ALTER TABLE ... CLUSTER BY (cols) turns it off and fixes the keys manually.

    Checkpoint 6 of 9· Fill the gap

    A team wants Databricks to choose table1's clustering keys and change them over time, using c1 and c2 as starting hints. Which keyword completes the second statement?

    ALTER TABLE table1 CLUSTER BY (c1, c2);
    ALTER TABLE table1 CLUSTER BY  ? ;

    Checkpoint 7 of 9· Exam question

    A team creates a new Delta table with CLUSTER BY AUTO to support a Lakeflow Spark Declarative Pipeline that ingests continuously via Auto Loader. Over several months, downstream analysts' filters shift from customer_id to region and order_date. What should the team expect regarding the table's clustering keys?

    Sources1

    5.What predictive optimization runs, skips and requires

    Predictive optimization is Databricks running table maintenance for you. It finds Unity Catalog managed tables that would benefit from maintenance, queues the operations, and runs them on serverless compute for jobs, billed under a serverless jobs SKU. It is on by default for accounts created on or after November 11, 2024. Older accounts are being enabled gradually.

    The three maintenance operations predictive optimization runs
    OperationWhat it does when run by predictive optimization
    OPTIMIZETriggers incremental clustering for clustered tables and compacts files to better sizes. Never runs ZORDER
    VACUUMDeletes data files no longer referenced by the table, using delta.deletedFileRetentionDuration (default 7 days, never less than 7)
    ANALYZEScans the table and collects statistics to improve query performance

    Predictive optimization never Z-orders. Its OPTIMIZE runs don't include ZORDER, and it ignores Z-ordered files entirely, so a legacy Z-ordered table gets no layout maintenance from it. Migrating such a table to liquid clustering is what brings it under automatic maintenance. VACUUM has a safety floor: setting delta.deletedFileRetentionDuration below 7 days does not stop predictive optimization from keeping files for at least 7 days. If you need longer time travel, say 30 days, set the property before enabling predictive optimization.

    The requirements are short, and the exclusions matter as much as the requirements:

    • the workspace is on the Premium plan or above, in a supported region
    • queries use SQL warehouses or Databricks Runtime 12.2 LTS or above
    • the table is a Unity Catalog managed table; predictive optimization never runs on external tables or on tables loaded into a workspace as OpenSharing recipients

    The external-table exclusion catches people out, because an external table looks like any other table in Catalog Explorer. The distinction is covered in managed versus external tables.

    Checkpoint 8 of 9· Match them up

    Predictive optimization is enabled at the account level. Match each table to what predictive optimization does with it.

    Tap a term, then the definition that fits it.

    Sources2

    6.Inheritance from account to table, and where to see the history

    The setting is inherited from account to catalog to schema to table. Every managed table takes the account value unless a catalog, schema or table overrides it. An account admin sets the account value in the accounts console under Settings, then Feature enablement. Below that, the catalog, schema or table owner, or a user with MANAGE on the object, can override it. INHERIT removes an override so the object follows its parent again.

    Enabling, disabling, or resetting predictive optimization at each levelsql
    ALTER CATALOG [catalog_name] { ENABLE | DISABLE | INHERIT } PREDICTIVE OPTIMIZATION;
    ALTER { SCHEMA | DATABASE } schema_name { ENABLE | DISABLE | INHERIT } PREDICTIVE OPTIMIZATION;
    ALTER TABLE table_name { ENABLE | DISABLE | INHERIT } PREDICTIVE OPTIMIZATION;

    An explicit setting wins over an inherited one in both directions. If the account is disabled, catalogs and schemas that were explicitly enabled stay enabled. If an object was explicitly disabled before the account was enabled, it stays blocked. A finance schema disabled last year therefore won't start getting maintenance when the account admin turns the feature on. DESCRIBE (CATALOG | SCHEMA | TABLE) EXTENDED name shows the Predictive Optimization field and indicates when the value is inherited.

    Every operation is recorded in the system table system.storage.predictive_optimization_operations_history (Public Preview). Each row carries the catalog, schema and table, an operation_type such as COMPACTION, CLUSTERING, AUTO_CLUSTERING_COLUMN_SELECTION, VACUUM or ANALYZE, an operation_status, operation_metrics, and a cost in usage_quantity measured in ESTIMATED_DBU. The unit is an estimate because several operations can share a cluster and the DBUs have to be split between them, though the cluster's total is exact. Rows appear within two hours. Billing data can take up to 24 hours.

    Estimated DBUs spent by predictive optimization in the last 30 dayssql
    SELECT SUM(usage_quantity)
      FROM system.storage.predictive_optimization_operations_history
      WHERE
        usage_unit = "ESTIMATED_DBU"
        AND timestampdiff(day, start_time, Now()) < 30;

    The system table records what ran. To see why something didn't run, look per table. On Databricks Runtime 18 LTS and above, DESCRIBE TABLE EXTENDED ... AS JSON returns a predictive_optimization_evaluations field with the latest result for each operation type. ANALYZE skip reasons are not included. Catalog Explorer's History tab shows the same information: filter to Automatic runs, where Auto marks an operation that ran and Not applied marks one that was skipped. Click a Not applied row to see the reason.

    How the evaluation operation types map to Catalog Explorer history labels
    DESCRIBE TABLE EXTENDED operation typeCatalog Explorer operationMeaning
    COMPACTIONOPTIMIZEFile compaction to improve query performance
    CLUSTERINGOPTIMIZEIncremental liquid clustering
    AUTO_CLUSTERING_COLUMN_SELECTIONAUTO LIQUIDEvaluation or evolution of liquid clustering keys
    VACUUMVACUUMRemoval of data files no longer referenced by the table

    Checkpoint 9 of 9· Check yourself

    In a Unity Catalog metastore, the sales schema was explicitly set with ALTER SCHEMA sales ENABLE PREDICTIVE OPTIMIZATION. The hr schema has no setting of its own. The account admin now disables predictive optimization at the account level. What happens to maintenance for the managed tables in these two schemas?

    Sources23

    Sources

    (3)

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

    1. 1.
      “Liquid clustering is a data layout optimization technique that replaces table partitioning and ZORDER.”
      ↩︎ Why liquid clustering replaces partitioning and ZORDER
      “Clustering is not compatible with partitioning or ZORDER.”
      ↩︎ Why liquid clustering replaces partitioning and ZORDER
      “Databricks recommends liquid clustering for all new tables, including streaming tables and materialized views.”
      ↩︎ Why liquid clustering replaces partitioning and ZORDER
      “Unlike traditional partitioning, you can redefine clustering keys without rewriting existing data.”
      ↩︎ Why liquid clustering replaces partitioning and ZORDER
      “You can specify up to four clustering keys.”
      ↩︎ Enabling CLUSTER BY and choosing keys
      “For smaller tables (less than 10 TB), using more clustering keys can degrade performance when filtering on a single column.”
      ↩︎ Enabling CLUSTER BY and choosing keys
      “Clustering keys must be columns that have statistics collected. By default, Delta Lake tables collect statistics for the first 32 columns.”
      ↩︎ Enabling CLUSTER BY and choosing keys
      “You cannot change clustering keys when using append mode.”
      ↩︎ Enabling CLUSTER BY and choosing keys
      “Delta Lake tables with liquid clustering enabled use Delta writer version 7 and reader version 3.”
      ↩︎ Enabling CLUSTER BY and choosing keys
      “After enabling liquid clustering, run OPTIMIZE jobs to incrementally cluster data.”
      ↩︎ OPTIMIZE does the clustering, and changing keys does not recluster
      “When you change clustering keys, subsequent OPTIMIZE and write operations use the new clustering approach, but existing data is not rewritten.”
      ↩︎ OPTIMIZE does the clustering, and changing keys does not recluster
      “Setting cluster keys to NONE does not rewrite clustered data, but prevents future OPTIMIZE operations from using clustering keys.”
      ↩︎ OPTIMIZE does the clustering, and changing keys does not recluster
      “Run OPTIMIZE <table_name> FULL when you enable clustering for the first time or change clustering keys.”
      ↩︎ OPTIMIZE does the clustering, and changing keys does not recluster
      “For large tables that have not previously been clustered on the specified keys, this operation might take hours.”
      ↩︎ OPTIMIZE does the clustering, and changing keys does not recluster
      “In this scenario, OPTIMIZE uses an incremental approach and only rewrites files that haven't previously been compacted.”
      ↩︎ OPTIMIZE does the clustering, and changing keys does not recluster
      “For tables experiencing many updates or inserts, Databricks recommends scheduling an OPTIMIZE job every one or two hours.”
      ↩︎ OPTIMIZE does the clustering, and changing keys does not recluster
      “Using very different columns triggers a large reclustering operation on the first OPTIMIZE run.”
      ↩︎ OPTIMIZE does the clustering, and changing keys does not recluster
      “Conversion minimizes reader and writer downtime and supports both external and managed tables.”
      ↩︎ OPTIMIZE does the clustering, and changing keys does not recluster
      “Automatic liquid clustering requires predictive optimization for automatic key selection and clustering operations, and runs asynchronously.”
      ↩︎ Automatic liquid clustering with CLUSTER BY AUTO
      “If your query patterns or data distributions change over time, automatic liquid clustering selects new keys to optimize performance.”
      ↩︎ Automatic liquid clustering with CLUSTER BY AUTO
      “Databricks changes clustering keys only when the predicted cost savings from data skipping improvements outweigh the data clustering cost.”
      ↩︎ Automatic liquid clustering with CLUSTER BY AUTO
      “The table is too small to benefit from liquid clustering.”
      ↩︎ Automatic liquid clustering with CLUSTER BY AUTO
      “If automatic liquid clustering is enabled, the clusterByAuto property is set to true.”
      ↩︎ Automatic liquid clustering with CLUSTER BY AUTO
      “Automatic liquid clustering isn't available for managed Apache Iceberg v2 tables.”
      ↩︎ Automatic liquid clustering with CLUSTER BY AUTO
      “Liquid clustering is a data layout optimization technique that replaces table partitioning and ZORDER.”
      ↩︎ Key concept
      “When you change clustering keys, subsequent OPTIMIZE and write operations use the new clustering approach, but existing data is not rewritten.”
      ↩︎ Exam trap 1
      “running CREATE OR REPLACE table_name without CLUSTER BY AUTO turns off automatic clustering and does not preserve clustering columns.”
      ↩︎ Exam trap 4
      “The default behavior does not apply clustering to previously written data. To force reclustering, use OPTIMIZE <table_name> FULL”
      ↩︎ Checkpoint
    2. 2.
      “Reduces storage costs by deleting data files no longer referenced by the table.”
      ↩︎ OPTIMIZE does the clustering, and changing keys does not recluster
      “Predictive optimization automatically runs OPTIMIZE, VACUUM, and ANALYZE on Unity Catalog managed tables (Delta Lake and Iceberg) on Databricks”
      ↩︎ What predictive optimization runs, skips and requires
      “OPTIMIZE does not run ZORDER when executed by predictive optimization. On tables that use Z-order, predictive optimization ignores Z-ordered files.”
      ↩︎ What predictive optimization runs, skips and requires
      “predictive optimization still retains data files for a minimum of 7 days when it runs VACUUM FULL.”
      ↩︎ What predictive optimization runs, skips and requires
      “Predictive optimization runs ANALYZE, OPTIMIZE, and VACUUM operations using serverless compute for jobs.”
      ↩︎ What predictive optimization runs, skips and requires
      “Your Databricks workspace must be on the Premium plan or above in a supported region.”
      ↩︎ What predictive optimization runs, skips and requires
      “Tables loaded to a workspace as OpenSharing recipients”
      ↩︎ What predictive optimization runs, skips and requires
      “All Unity Catalog managed tables inherit the account value by default.”
      ↩︎ Inheritance from account to table, and where to see the history
      “If predictive optimization is later enabled at the account level, it remains blocked for objects that have specifically disabled it.”
      ↩︎ Inheritance from account to table, and where to see the history
      “Databricks provides the system table system.storage.predictive_optimization_operations_history for observability into predictive optimization operations, costs, and impact.”
      ↩︎ Inheritance from account to table, and where to see the history
      “the Not applied label indicates the operation was skipped”
      ↩︎ Inheritance from account to table, and where to see the history
      “OPTIMIZE does not run ZORDER when executed by predictive optimization. On tables that use Z-order, predictive optimization ignores Z-ordered files.”
      ↩︎ Exam trap 2
      “Disabling predictive optimization at the account level does not disable it for catalogs or schemas that have specifically enabled it.”
      ↩︎ Exam trap 3
      “Disabling predictive optimization at the account level does not disable it for catalogs or schemas that have specifically enabled it.”
      ↩︎ Checkpoint
    3. 3.
      “The predictive optimization system table updates within two hours. However, billing information can take up to 24 hours to populate the data.”
      ↩︎ Inheritance from account to table, and where to see the history

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