File formats & storage · Performance & Layout

What is Z-ordering?

HardZ-orderclusteringDeltadata skippingOPTIMIZE

Interview question

What is Z-ordering (multi-dimensional clustering), and why does it help?

How to answer

The short answer

Z-ordering (Z-order clustering) co-locates related values across multiple columns inside data files so that filters on those columns skip more file chunks. It is a multi-dimensional clustering technique popularized in Delta Lake (OPTIMIZE ... ZORDER BY).

Problem first. Partitioning helps when you filter on keys (often dt). Many queries also filter on user_id or product_id *inside* a day partition. Without clustering, matching rows are scattered across every file, so min/max stats rarely skip anything.

When to use it

  • High-cardinality filter columns that are not good partition keys
  • Multiple filter columns (Z-order interleaves several dimensions)
  • After large merges / before heavy read workloads

Caveats

  • Rewrites data (compute + write cost)
  • Helps skipping via stats; it is not a B-tree index
  • Pick a few important columns, not 20

Interview tip: "Z-order improves data skipping for non-partition filters by clustering values so file-level min/max become selective."