Liquid clustering: what it actually replaced, and the caveats worth knowing
I see a lot of questions here that boil down to "should I partition, Z-order, or use liquid clustering." Posting how I reason about it, partly to help and partly because I'd like to hear where others disagree.
All three do the same job
They exist to make the engine read fewer files. Delta stores min, max and null counts per file. When a query filters on a column, those statistics are compared against the predicate and files that cannot match are never opened. Clustering works by making those ranges tight. In a randomly ordered table every file spans the whole range, so nothing can be skipped.
The three approaches differ in granularity and in what they cost you later.
Partitioning
Physical directories per value. Fast pruning when it fits, but three problems. It breaks on high cardinality columns, because you get a directory and at least one file per value. It is a permanent choice, so changing the partition column means rewriting the table. And a skewed partition value is a hotspot you cannot fix without that rewrite.
Z-order
Multi-dimensional clustering within files rather than directories, so cardinality stops being a concern. Two remaining problems. It is a batch operation you have to keep re-running as data lands, and the effect degrades past three or four columns. The keys are also still effectively fixed, since changing them means a full rewrite.
Liquid clustering
Declared on the table, maintained incrementally as data arrives, and the keys are mutable.
CREATE TABLE silver.orders (...) CLUSTER BY (customer_id, order_date);
ALTER TABLE silver.orders CLUSTER BY (region);
CREATE TABLE silver.events (...) CLUSTER BY AUTO;
That second line is the part I think is underrated. Query patterns always change, and repartitioning a large table is a project rather than a config change. Being able to change clustering keys without a rewrite is the feature, more than the layout quality itself.
Caveats that catch people
It is best effort, not a guarantee. Newly written data is not clustered until maintenance runs, so you still need OPTIMIZE scheduled or predictive optimization enabled on Unity Catalog managed tables. People enable clustering, see no improvement, and conclude it does not work.
Changing keys does not reorganise existing data. New writes cluster on the new keys and old data converges over time. If you need existing data reclustered immediately there is a full reclustering variant of OPTIMIZE, and it is not cheap.
It replaces partitioning and Z-order rather than combining with them. You cannot have both on the same table.
There is a cap on the number of clustering keys, so it is not a substitute for thinking about which columns you actually filter and join on.
When I would still partition
A non-performance requirement. Regulatory separation of data by region into distinct paths, or making concurrent writers provably disjoint to avoid commit conflicts. Otherwise I default to liquid clustering on new tables.
Open questions
Has anyone measured CLUSTER BY AUTO against manually chosen keys on a workload with genuinely mixed query patterns? And has anyone migrated a large partitioned table across and found the reclustering cost worse than expected? Interested in numbers rather than impressions.
Liresa Ferizaj