What you will be able to do
- Decide from table size and data grain whether a large table should be partitioned at all, and on which column
- Choose liquid clustering keys from the filter and join columns that queries use between facts and dimensions
- Convert a partitioned table to liquid clustering in place and know when OPTIMIZE must follow
- Keep file sizes balanced with OPTIMIZE, auto compaction, optimized writes and target file sizes, on both Delta and Iceberg tables
Key concept
Partition only where the grain yields large partitions — A partition column is justified only when the table is very large and every value of the column still holds at least about 1 GB of data. Below that, use liquid clustering on the columns queries filter by, and let compaction keep the files balanced.
1.Start from the grain, the predicates and the size
A table layout covers three decisions that depend on each other: whether to partition, which columns to cluster on, and how large the data files should be. Make them in this order. First identify the grain, meaning what one row represents and how it arrives (one event per row, landing by ingest date). Next list the dominant predicates, the columns that dashboards and jobs filter and join on. Last, estimate the table's size at maturity. Get them wrong and the cost is high. An ineffective partitioning strategy might negatively affect query performance and require a full rewrite of data to fix, and on a large table that rewrite is slow and expensive.
Size sets the default, and that default is not to partition. Most tables on Databricks with less than 100 TB of data don't need partitioning. Delta automatically clusters unpartitioned tables by ingestion time, which gives the same benefit a date partition would for event data that arrives in date order. If such a table later receives heavy UPDATE or MERGE traffic, keep that ordering with liquid clustering on a column that follows ingestion order, such as an event timestamp or a creation date.
| Table size | Guidance |
|---|---|
| Under 1 TB | Don't partition |
| 1 TB to 100 TB | Use liquid clustering instead of partitioning. Partitioning hurts performance more often than it helps |
| 100 TB or more | Partitioning might help, but try liquid clustering first and verify the improvement |
For a table large enough to partition, the partition column comes from the grain, never from a high-cardinality key. An ingest date or a physical location qualifies, because these columns have low or known cardinality. Timestamps and customer IDs do not, because they produce millions of tiny directories. Then check the arithmetic: divide the table size by the number of distinct partition values. If any partition falls below roughly 1 GB, the scheme costs more than it saves, because tables with fewer, larger partitions tend to perform better. Daily partitions on a table that adds 200 MB a day fail this test, even though the date column matches the grain exactly. The mechanics of Hive-style partitioning and ZORDER are covered in Hive-style partitioning and ZORDER. For layout design, the rule that matters is the 1 GB floor.
Checkpoint 1 of 8· Match them up
Match each table size to the Databricks partitioning guidance for it
Tap a term, then the definition that fits it.
Size sets the default, and the default is not to partition. Only at 100 TB or more might partitioning help, and even then liquid clustering should be tried and measured first.
“With less than 1 TB of data, don't partition. With more than 1 TB to 100 TB of data, use liquid clustering instead of partitioning.”Source: docs.databricks.com
Checkpoint 2 of 8· Check yourself
A 400 TB clickstream table holds about three years of events, one row per event, landing by ingest date. Queries filter on customer_id and on date. The team has verified that partitioning beats liquid clustering for this table. Which partition column fits?
The partition column should come from the grain and have low or known cardinality. With about 1,100 days, each daily partition is far above the 1 GB floor. customer_id and timestamps have high cardinality and would create millions of tiny partitions.
“Partitioning works well only for low or known cardinality fields (for example, date fields or physical locations), but not for fields with high cardinality”Source: docs.databricks.com
Sources1
2.Cluster on the columns that relate facts to dimensions
Liquid clustering replaces partitioning and ZORDER as the main layout tool. It organises files around clustering keys and has no fixed directory boundaries (Liquid Clustering covers how it works). In a design, the main question is which keys to choose. Take them from the relationships queries traverse. On a fact table, that usually means the date column dashboards slice by plus the foreign key that joins to the most-filtered dimension, such as event_date and customer_id on fact_events. File skipping depends on per-file min/max statistics, so clustering rows with similar key values into the same files lets a filter on those keys skip most of the table.
CREATE TABLE table1 (
col0 STRING,
col1 DATE,
col2 BIGINT
)
CLUSTER BY (col0, col1);Several situations favour clustering over partitioning:
- Queries that filter on high-cardinality columns, such as a customer key
- Heavily skewed data, where some partitions would be huge and most would be tiny
- Fast-growing tables whose maintenance would otherwise need constant tuning
- Access patterns that vary or change as new reports are built
- Cases where any plausible partition key would return results from too many or too few partitions
Changing access patterns are what most clearly separate clustering from partitioning. When next quarter's dashboards filter on different columns, you can redefine the clustering keys without rewriting existing data. A partitioned table would need a full rewrite to change its partition column. Clustering also handles a case partitioning cannot: liquid clustering is the only way to data-skip on a struct field without first extracting it into a top-level column.
When there are too many tables to tune by hand, let the platform pick the keys. In Databricks Runtime 15.4 LTS and above, CLUSTER BY AUTO on a Unity Catalog managed Delta table lets Databricks choose clustering keys to optimise query performance. This requires predictive optimization, which selects the keys and runs clustering asynchronously. Because predictive optimization bases these choices on how the data is actually used, keys can change as dashboards change. The table history records this as an AUTO_CLUSTERING_COLUMN_SELECTION operation.
Checkpoint 3 of 8· Check yourself
Your team is designing the layout for fact_events, a 30 TB table. Dashboards slice it by event_date and filter on customer_id, and next quarter's reports are expected to filter on different columns. Which layout fits these requirements?
Liquid clustering on the date and the foreign key matches the access pattern, and you can redefine its keys later without rewriting existing data. Clustering cannot be combined with partitioning or ZORDER, a partitioned table needs a full rewrite to change its partition column, and customer_id has too many distinct values to be a partition column.
“Unlike traditional partitioning, you can redefine clustering keys without rewriting existing data.”Source: docs.databricks.com
Checkpoint 4 of 8· Exam question
A team is designing a fact_events table that will grow to several billion rows. Query patterns filter heavily on event_date and customer_id, but the exact date ranges and customer segments used in dashboards change frequently as new reports are built each month. The team wants a layout that avoids costly directory-listing overhead from thousands of narrow partitions while still letting the physical data layout adapt as query patterns shift. Which approach best meets these requirements?
Correct answer: A — Create the table with CLUSTER BY (event_date, customer_id) so Delta Lake incrementally reorganizes files around these columns without a fixed directory layout that must be rewritten as patterns change.
- A. Liquid clustering lets Delta Lake incrementally rewrite only the files that need reorganizing, and clustering keys can be changed later without a full rewrite, which matches both the scale requirement and the shifting query pattern requirement.
- B. Daily partitioning over several billion rows accumulated across years still produces a very large number of partition directories, so directory-listing overhead persists even though Z-order adds secondary skipping within each partition.
- C. Partitioning by a very high-cardinality column like customer id creates an enormous number of small partition directories, which is the exact small-partition overhead the team is trying to avoid.
- D. Auto Loader handles incremental file discovery and ingestion, not the physical layout or compaction of data already stored in the table, so it does not address directory or file-size overhead.
Checkpoint 5 of 8· Exam question
A platform team manages hundreds of Unity Catalog managed Delta tables and does not have the capacity to manually choose and periodically revisit clustering keys as BI dashboards evolve. They want Databricks to observe query history and select clustering keys automatically, changing them only when the switch is expected to pay for itself in reduced maintenance cost. Which configuration satisfies this requirement?
Correct answer: A — Create or alter the tables with CLUSTER BY AUTO so Databricks Runtime 15.4 LTS or later analyzes each table's query history and updates clustering keys only when the savings outweigh the reclustering cost.
- A. This is exactly the automatic clustering-key selection feature: Databricks analyzes the workload against the table and only changes keys when doing so is expected to be cost-effective, requiring no manual key management.
- B. Auto compaction controls small-file bin-packing behavior on write, but it does not select or change clustering keys, so it does not meet the requirement to automate key selection.
- C. This describes a manually built and maintained job that inspects statistics and swaps keys by hand, which is the opposite of the hands-off, workload-aware automation the team wants.
- D. Predictive optimization schedules maintenance jobs like
OPTIMIZEandVACUUM, andZORDER BYis a separate, non-adaptive indexing technique used with partitioned tables, not an automatic clustering-key selector.
3.Moving a partitioned table to clustering, on Delta and Iceberg
A partitioned table that has outgrown its scheme can be converted in place. In Databricks Runtime 18.1 and above, ALTER TABLE ... REPLACE PARTITIONED BY WITH CLUSTER BY turns a partitioned Delta table into a liquid-clustered one without exporting and reloading the data, for both managed and external tables. A plain ALTER TABLE ... CLUSTER BY only works on a table that is not partitioned. A CTAS into a new table works too, but it rewrites everything and does not preserve all table metadata.
| Clause | Resulting clustering keys |
|---|---|
| CLUSTER BY (cols) | The listed columns. Keep them close to the old partition columns to avoid a large first recluster |
| CLUSTER BY AUTO | Starts from the current partition columns, then predictive optimization adapts them. Unity Catalog managed tables only |
| CLUSTER BY (no options) | The current partition columns |
No. The ALTER changes metadata, not data. The physical reorganisation happens when OPTIMIZE runs. If the new keys differ from the old partitions, the first OPTIMIZE is a large reclustering job, so schedule it accordingly. After conversion, DESCRIBE EXTENDED shows the new clustering columns, and DESCRIBE HISTORY shows the REORG and protocol-upgrade steps.
ALTER TABLE t1 REPLACE PARTITIONED BY WITH CLUSTER BY (day, id);
OPTIMIZE t1;Iceberg tables follow the same layout rules with a few differences in mechanics (Iceberg as a target format (managed Iceberg tables / UniForm) covers the format itself). For managed Iceberg tables, Unity Catalog supports only liquid clustering, and a PARTITION BY clause is read as clustering keys. Running the conversion command on these tables therefore raises an error, because there is nothing to convert. OPTIMIZE rewrites Iceberg files as it does Delta files, but Iceberg uses clustering and sorting strategies in place of ZORDER. Liquid clustering on Iceberg is in Public Preview from Databricks Runtime 16.4 LTS.
Checkpoint 6 of 8· Fill the gap
Table t1 is partitioned on (year, month, day) and is converted to cluster on different columns. Which command in the second line actually reorganises the existing files by the new keys?
ALTER TABLE t1 REPLACE PARTITIONED BY WITH CLUSTER BY (day, id);
? t1;The ALTER only changes metadata. Existing files are reclustered on the new keys when OPTIMIZE runs, and because (day, id) differs from the old partition columns, that first OPTIMIZE is a large reclustering job. DESCRIBE only checks the result, ANALYZE collects statistics and VACUUM deletes files the table no longer references.
Source: docs.databricks.comCheckpoint 7 of 8· Exam question
An existing Delta table orders is partitioned by order_month and has accumulated hundreds of small partitions after a shift in order volume, degrading query performance. The team wants to move the table to liquid clustering on order_date and region without exporting and reloading the underlying data. Which statement should they run?
Correct answer: A — ALTER TABLE orders
REPLACE PARTITIONED BY
WITH CLUSTER BY (order_date, region);
This removes the existing Hive-style partition scheme and registers the new clustering keys on the same table in place.
- A. The
REPLACE PARTITIONED BY ... WITH CLUSTER BYclause is the documented in-place conversion path: it drops the partition scheme and applies the new clustering keys to the existing table without exporting and reloading data. - B. Liquid clustering is not compatible with an existing partition scheme, so applying
CLUSTER BYdirectly to a still-partitioned table is not a valid conversion path, and manually dropping partitions afterward does not register clustering keys. - C. A full CTAS rewrite can produce a clustered table, but it is unnecessary here and the claim that clustered tables must originate from a full rewrite is false, since the in-place
REPLACE PARTITIONED BY WITH CLUSTER BYpath exists precisely to avoid that cost. - D.
ZORDER BYis a distinct, non-adaptive indexing technique used with partitioned tables; running it does not register liquid clustering keys or convert the table's clustering metadata.
4.Keeping file sizes balanced with compaction
Even a good partition and clustering design degrades if the files are the wrong size. Streaming appends and small batches leave thousands of small files. Each one adds per-file overhead and its own statistics to check, which is why Databricks sizes files so that the number of files in a table doesn't grow too large. Files can also be too big. On very narrow tables, a single file can hold more rows than the Parquet format supports, and the write fails. maxRecordsPerFile is the remedy, but only when that error actually occurs.
OPTIMIZE is the main tool for compaction. It rewrites data files into fewer, evenly sized ones using bin-packing, which balances files by bytes in storage rather than by row count. On a clustered table it also groups rows by the clustering keys. On a partitioned table it compacts within each partition, never across partitions. The operation is safe to run alongside other work. It changes no data, readers keep their snapshot, a second run on the same data does nothing, and streams that read from the table are unaffected. On a large table you can limit it to recent data with a predicate.
OPTIMIZE table_name WHERE date >= '2022-11-18'Two write-time features reduce small files before OPTIMIZE ever runs, but neither replaces it. Optimized writes shuffle data before writing so each write produces fewer, larger files. This matters most on partitioned tables and adds some write latency. Auto compaction runs synchronously on the writing cluster after a successful write and combines small files that have not yet been compacted. It is a file-merging step and has nothing to do with clustering keys. Both are always on for MERGE, UPDATE and DELETE. Do not combine optimized writes with a manual repartition(n) or coalesce(n). For tables over 1 TB, run OPTIMIZE on a schedule as well. A sensible starting point is daily, at night, then adjust the frequency to balance cost against query speed.
| Table size | Target file size | Approximate files |
|---|---|---|
| 10 GB | 256 MB | 40 |
| 1 TB | 256 MB | 4096 |
| 5 TB | 512 MB | 17339 |
| 10 TB | 1 GB | 24437 |
| 100 TB | 1 GB | 114437 |
Target size depends on table size, and autotuning sets it for you. A table under 2.56 TB targets 256 MB files. Between 2.56 TB and 10 TB the target grows linearly, and above 10 TB it is 1 GB. As a table grows, files written at the old, smaller target are not rewritten when the target rises. If those leftovers matter, set a fixed delta.targetFileSize (or iceberg.targetFileSize). A table you tune this way is no longer autotuned, and on managed tables only OPTIMIZE honours the setting. For Unity Catalog managed tables, the simplest path is predictive optimization. It runs OPTIMIZE, VACUUM and ANALYZE when they are cost-effective, on serverless compute, and records them in system.storage.predictive_optimization_operations_history. It does not run on external tables, and it never performs ZORDER.
Checkpoint 8 of 8· Match them up
A 3 TB external Delta table gets streaming appends. Pair each file-sizing feature with what it actually does for this table
Tap a term, then the definition that fits it.
Auto compaction and optimized writes cut down small files when data is written, but neither replaces OPTIMIZE, which should still run on a schedule for tables over 1 TB. Predictive optimization would handle OPTIMIZE automatically, but it doesn't run on external tables.
“Auto compaction and optimized writes each reduce small file problems, but are not a full replacement for OPTIMIZE.”Source: docs.databricks.com
Sources
(6)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.https://docs.databricks.com/aws/en/tables/partitionsOfficial docs
“An ineffective partitioning strategy might negatively affect query performance and require a full rewrite of data to fix.”
↩︎ Start from the grain, the predicates and the size“Most tables on Databricks with less than 100 TB of data don't need partitioning.”
↩︎ Start from the grain, the predicates and the size“automatically clusters data in unpartitioned tables by ingestion time, so you get partitioning-like performance without manual tuning”
↩︎ Start from the grain, the predicates and the size“For partitions, verify that each partition contains at least 1 GB of data.”
↩︎ Start from the grain, the predicates and the size“Liquid clustering is the only way to data-skip on a struct field without first extracting it into a top-level column.”
↩︎ Cluster on the columns that relate facts to dimensions“For managed tables using Apache Iceberg, Unity Catalog supports only liquid clustering and interprets PARTITION BY columns as clustering keys.”
↩︎ Moving a partitioned table to clustering, on Delta and Iceberg“For partitions, verify that each partition contains at least 1 GB of data.”
↩︎ Key concept“Partitioning works well only for low or known cardinality fields (for example, date fields or physical locations)”
↩︎ Exam trap 1“With less than 1 TB of data, don't partition.”
↩︎ Prediction“With less than 1 TB of data, don't partition. With more than 1 TB to 100 TB of data, use liquid clustering instead of partitioning.”
↩︎ Checkpoint“Partitioning works well only for low or known cardinality fields (for example, date fields or physical locations), but not for fields with high cardinality”
↩︎ Checkpoint - 2.https://docs.databricks.com/aws/en/tables/clusteringOfficial docs
“Unlike traditional partitioning, you can redefine clustering keys without rewriting existing data.”
↩︎ Cluster on the columns that relate facts to dimensions“Tables where a typical partition key might return results from too many or too few partitions.”
↩︎ Cluster on the columns that relate facts to dimensions“Clustering is not compatible with partitioning or ZORDER.”
↩︎ Cluster on the columns that relate facts to dimensions“In Databricks Runtime 15.4 LTS and above, you can enable automatic liquid clustering for Unity Catalog managed Delta Lake tables.”
↩︎ Cluster on the columns that relate facts to dimensions“Automatic liquid clustering requires predictive optimization for automatic key selection and clustering operations, and runs asynchronously.”
↩︎ Cluster on the columns that relate facts to dimensions“to convert an existing partitioned Delta Lake table to liquid clustering, use REPLACE PARTITIONED BY WITH CLUSTER BY in an ALTER TABLE statement.”
↩︎ Moving a partitioned table to clustering, on Delta and Iceberg“To benefit from altering clustering columns, you must run OPTIMIZE.”
↩︎ Moving a partitioned table to clustering, on Delta and Iceberg“Using very different columns triggers a large reclustering operation on the first OPTIMIZE run.”
↩︎ Moving a partitioned table to clustering, on Delta and Iceberg“For managed Iceberg tables, conversion is not necessary because these tables use partition definitions as liquid clustering keys.”
↩︎ Moving a partitioned table to clustering, on Delta and Iceberg“to convert an existing partitioned Delta Lake table to liquid clustering, use REPLACE PARTITIONED BY WITH CLUSTER BY in an ALTER TABLE statement.”
↩︎ Exam trap 2 - 3.
“at query time to skip irrelevant files and speed up queries”
↩︎ Cluster on the columns that relate facts to dimensions - 4.
“If automatic liquid clustering is enabled, predictive optimization might select new clustering keys before clustering data.”
↩︎ Cluster on the columns that relate facts to dimensions“OPTIMIZE does not run ZORDER when executed by predictive optimization.”
↩︎ Keeping file sizes balanced with compaction“OPTIMIZE does not run ZORDER when executed by predictive optimization.”
↩︎ Exam trap 4 - 5.
“Apache Iceberg tables use clustering and sorting strategies instead of ZORDER.”
↩︎ Moving a partitioned table to clustering, on Delta and Iceberg“Bin-packing aims to produce evenly-balanced data files with respect to their size in storage”
↩︎ Keeping file sizes balanced with compaction“For tables with partitions defined, file compaction and data layout are performed within partitions.”
↩︎ Keeping file sizes balanced with compaction“Because OPTIMIZE makes no data changes to the table, a read before and after an OPTIMIZE has the same results.”
↩︎ Keeping file sizes balanced with compaction“Databricks recommends that you start by running OPTIMIZE on a daily basis, preferably at night when spot prices are low”
↩︎ Keeping file sizes balanced with compaction - 6.
“so that the number of files in the table doesn't grow too large”
↩︎ Keeping file sizes balanced with compaction“the number of rows in a given data file exceeds the support limits of the Parquet format”
↩︎ Keeping file sizes balanced with compaction“For tables larger than 1 TB, Databricks recommends running OPTIMIZE on a schedule to further consolidate files.”
↩︎ Keeping file sizes balanced with compaction“Optimized writes are most effective for partitioned tables, as they reduce the number of small files written to each partition.”
↩︎ Keeping file sizes balanced with compaction“It runs synchronously on the cluster that performs the write, after the write succeeds”
↩︎ Keeping file sizes balanced with compaction“When the target file size for a table grows, existing files are not re-optimized into larger files by the OPTIMIZE command.”
↩︎ Keeping file sizes balanced with compaction“When using Unity Catalog managed tables and SQL warehouses or Databricks Runtime 11.3 LTS and above, only OPTIMIZE commands respect the targetFileSize setting.”
↩︎ Keeping file sizes balanced with compaction“Auto compaction and optimized writes each reduce small file problems, but are not a full replacement for OPTIMIZE.”
↩︎ Exam trap 3“Auto compaction and optimized writes each reduce small file problems, but are not a full replacement for OPTIMIZE.”
↩︎ Checkpoint