CertSafari
    Databricks Certified Data Engineer Professional· Lessons

    Domain 5 · Lesson 32/46

    Liquid Clustering vs ZORDER and Partitioning by Query Pattern

    Compare Liquid Clustering vs partitioning/ZORDER for a given table size and query pattern.

    10 min read
    2.5% of exam
    5 sources
    Published 3 Oct 2026
    Docs as of 30 Sep 2026

    What you will be able to do

    • Match partitioning, ZORDER, and liquid clustering to the column cardinality and filter patterns each one handles
    • Explain the limits of ZORDER: it works only within partitions, cannot use partition columns, and becomes less effective with each added column
    • Choose liquid clustering for skewed, concurrently written, or changing workloads, and know what happens to existing data when clustering keys change

    1.Column cardinality decides which technique fits

    After table size, the next question is which columns your queries filter on and how many distinct values those columns have. Partitioning creates one partition per value, so it only works well for low- or known-cardinality fields, such as a date or a physical location. It is a poor fit for high-cardinality fields like timestamps, because they would produce a huge number of tiny partitions.

    ZORDER works the other way round. It is meant for columns that appear often in query predicates and have many distinct values, and it handles fields that keep gaining new values, like a customer ID in an orders table. Liquid clustering covers both ends. It works for low- and high-cardinality columns, without the fixed partition boundaries and small-file problems of static partitioning. Filtering on high-cardinality columns is one of the scenarios where Databricks says clustering particularly helps.

    How each layout technique handles column cardinality and its key constraints
    TechniqueColumn cardinality it suitsKey constraint
    PartitioningLow or known cardinality (e.g. date fields, physical locations)Not for high-cardinality fields such as timestamps; partition columns must be top-level
    ZORDER (via OPTIMIZE)High cardinality, including fields that grow infinitelyOnly within a partition; cannot Z-order on partition columns
    Liquid clusteringBoth low and high cardinalityNot compatible with partitioning or ZORDER

    Checkpoint 1 of 6· Match them up

    Match each layout technique to the column it is designed to handle

    Tap a term, then the definition that fits it.

    Sources123

    2.Where ZORDER runs out

    ZORDER is not a table property. It is a clause you add to the OPTIMIZE command, which rewrites files so that related values end up in the same set of files. Databricks data skipping then uses the per-file statistics to avoid reading files that cannot match a filter. The example below Z-orders only the last day of an events table on eventType.

    ZORDER is applied through OPTIMIZE, here restricted to recent datasql
    OPTIMIZE events
    WHERE date >= current_timestamp() - INTERVAL 1 day
    ZORDER BY (eventType)

    Checkpoint 2 of 6· Fill the gap

    Which keyword completes this command so that it colocates eventType values while rewriting files?

    OPTIMIZE events
    WHERE date >= current_timestamp() - INTERVAL 1 day
     ?  BY (eventType)

    ZORDER has several limits that make it a weaker tool than liquid clustering for many query patterns. On a partitioned table, files cannot be combined across partition boundaries, so Z-ordering only happens inside each partition. You also cannot Z-order on the partition columns themselves.

    You can list multiple ZORDER columns, but the docs warn that effectiveness drops with each extra column. A ZORDER column is only useful if statistics are collected for it. Without statistics, Z-ordering is ineffective and wastes compute. Z-ordering is also not idempotent: running it again on data that has changed rewrites that data, and the run time is not guaranteed to shrink over repeated runs. Finally, ZORDER cannot be used at all on a table with liquid clustering. Databricks recommends liquid clustering over Z-ordering for new tables.

    Checkpoint 3 of 6· Check yourself

    A table is partitioned by date and Z-ordered by user_id. Which statement about this layout is correct?

    Checkpoint 4 of 6· Exam question

    A 50 TB Delta table `sales_history` was originally partitioned by `ingest_date` (roughly 1,800 daily partitions) and Z-Ordered by `customer_id` within each partition to speed up point lookups by customer. The rigid daily directories now cause small-file problems on low-volume days, and query planning must prune 1,800 partition directories before the Z-Order ordering helps. The team wants a supported approach that keeps fast `customer_id` lookups while removing the small-file overhead from the daily directories. Which approach should they take?

    Sources2

    3.Skew, concurrent writes, and access patterns that change

    Cardinality is not the only factor. The Databricks docs list workload traits where liquid clustering is the better choice:

    - Data with heavy skew. Static partitioning makes you pick partition columns up front, and uneven values then produce uneven partitions. Liquid clustering is described as skew-resistant. - Fast-growing tables that would otherwise need ongoing maintenance and tuning. - Tables with concurrent writes. Liquid clustering supports row-level concurrency, which reduces write conflicts. - Tables where a typical partition key would produce too many or too few partitions. - Tables whose access patterns vary or change over time.

    The last point is where liquid clustering differs most from partitioning. To change a partition scheme, you have to rewrite the table. To change clustering keys, you run ALTER TABLE ... CLUSTER BY, and the key order does not matter. The catch is that changing the keys does not reorganize anything on its own. Only rows clustered by the next OPTIMIZE run follow the new keys, and rows already clustered by the old keys stay as they were.

    If you would rather not choose keys at all, CLUSTER BY AUTO on Unity Catalog managed tables lets Databricks pick the clustering columns and adjust them as the workload changes.

    Checkpoint 5 of 6· Put it in order

    Put these steps in order to add a second clustering dimension to a table and have new layout work use it

    1. 1.ALTER TABLE t CLUSTER BY (a, b);
    2. 2.CREATE TABLE t(a int, b string) CLUSTER BY (a);
    3. 3.OPTIMIZE t;

    Sources435

    4.Moving a partitioned table to liquid clustering

    If a table's size or query patterns show its partitioning is wrong, Databricks Runtime 18.1 and above can convert it in place with ALTER TABLE ... REPLACE PARTITIONED BY WITH CLUSTER BY. The listed benefits are the same points covered above: better performance for tables with poor data skipping or over-partitioning, keys that are easy to change instead of a rigid scheme, and fewer write conflicts thanks to row-level concurrency.

    The example below converts a table partitioned on (year, month, day) to clustering on different columns. Databricks recommends keeping the new clustering columns close to the old partition columns. Very different columns trigger a large reclustering job on the first OPTIMIZE run.

    Converting a partitioned table to liquid clustering on different columns, then running OPTIMIZE so the new keys take effectsql
    ALTER TABLE t1 REPLACE PARTITIONED BY WITH CLUSTER BY (day, id);
    OPTIMIZE t1;

    Checkpoint 6 of 6· Exam question

    A streaming table ingests high-volume clickstream events and is queried concurrently by many downstream jobs filtering on `user_id` (extremely high cardinality) and `event_type` (low cardinality, about 20 values). Query patterns shift week to week as new dashboards are added. Which characteristics make liquid clustering, configured with `CLUSTER BY AUTO`, a better fit than a legacy layout that partitions by `event_type` and Z-Orders by `user_id`? (Select all that apply.)(Select 3)

    Sources3

    Exam traps

    Each one states something that sounds right. Open it to see what is actually true.

    1. 1.On a partitioned table, ZORDER colocates data across the whole table, and you can add the partition column to ZORDER BY for extra skipping.Why is that wrong?

      Z-ordering only happens within each partition, and partition columns cannot be Z-order columns.

      Covered in Where ZORDER runs out

    2. 2.Running ALTER TABLE ... CLUSTER BY with new columns immediately reorganizes all existing data by the new keys.Why is that wrong?

      Changing the keys rewrites nothing by itself. OPTIMIZE has to run afterwards, and rows already clustered by the old columns stay as they were.

      Covered in Skew, concurrent writes, and access patterns that change

    3. 3.Partitioning by a high-cardinality column such as a timestamp is a good way to speed up filters on that column.Why is that wrong?

      Partitioning only works well for low- or known-cardinality fields. High-cardinality filter columns are a reason to choose liquid clustering.

      Covered in Column cardinality decides which technique fits

    Sources

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

    1. 1.
      “Liquid clustering works for both low and high cardinality columns and avoids the fixed partition boundaries and small-file issues common with static partitioning.”
      ↩︎ Column cardinality decides which technique fits
      “You cannot Z-order on fields used for partitioning.”
      ↩︎ Exam trap 1
      “but not for fields with high cardinality such as timestamps”
      ↩︎ Exam trap 3
      “Z-order works for all fields, including high cardinality fields and fields that may grow infinitely”
      ↩︎ Prediction
      “Partitioning works well only for low or known cardinality fields”
      ↩︎ Checkpoint
      “You cannot combine files across partition boundaries, and so Z-order clustering can only occur within a partition.”
      ↩︎ Checkpoint
    2. 2.
      “if that column has high cardinality (that is, a large number of distinct values), then use ZORDER BY.”
      ↩︎ Column cardinality decides which technique fits
      “However, the effectiveness drops with each extra column.”
      ↩︎ Where ZORDER runs out
      “Databricks recommends that you don't use ZORDER BY on columns that don't have statistics collected because it is ineffective and uses unnecessary compute resources.”
      ↩︎ Where ZORDER runs out
      “Z-ordering is not idempotent but aims to be an incremental operation.”
      ↩︎ Where ZORDER runs out
      “You can't use ZORDER in combination with liquid clustering.”
      ↩︎ Where ZORDER runs out
    3. 3.
      “Queries that filter on high cardinality columns.”
      ↩︎ Column cardinality decides which technique fits
      “Tables with varied or changing access patterns.”
      ↩︎ Skew, concurrent writes, and access patterns that change
      “Performance improvements for tables that suffer from poor data-skipping or over-partitioning.”
      ↩︎ Moving a partitioned table to liquid clustering
      “Clustering columns are flexible and simple to alter, whereas partitioning is rigid and difficult to alter.”
      ↩︎ Moving a partitioned table to liquid clustering
      “Using very different columns triggers a large reclustering operation on the first OPTIMIZE run.”
      ↩︎ Moving a partitioned table to liquid clustering
    4. 4.
      “Static partitioning requires you to select partition columns and reorganize data up front, which can cause data skew for unevenly distributed values.”
      ↩︎ Skew, concurrent writes, and access patterns that change
      “Liquid clustering is self-tuning, skew-resistant, and incremental, rewriting only the data that needs reorganization on each run.”
      ↩︎ Skew, concurrent writes, and access patterns that change
    5. 5.
      “Directs Delta Lake to automatically determine and over time adapt to the best columns to cluster by.”
      ↩︎ Skew, concurrent writes, and access patterns that change
      “Note that rows clustered by previous clustering columns are not affected.”
      ↩︎ Exam trap 2
      “To cluster rows with altered clustering columns, you must run OPTIMIZE.”
      ↩︎ Checkpoint

    Ready to test yourself?

    Practise Databricks Certified Data Engineer Professional in quiz mode.

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