Optimizing lakehouse tables

By Hatnest · Reviewed by Saurav Raj Joshi · Updated Nov 30, 2026

Lakehouse tables are Delta tables: Parquet files plus a transaction log. Every write adds files, and every update or delete adds more. Left alone, a table collects many small files, and every engine that reads it (Spark, the SQL analytics endpoint, Direct Lake) pays for opening them. Optimizing a table is mostly about keeping files well sized and well organized.

The small-file problem

Small files mean more metadata, more tasks and less parallel efficiency. Streaming and frequent small inserts are the usual cause, as are heavily partitioned tables and many MERGE, UPDATE or DELETE operations. Even append-only tables can drift into this state, so a lakehouse needs a maintenance plan. Warehouse tables, in contrast, are maintained by the service.

Note who writes the table. Spark offers the broadest controls. Data written by a pipeline Copy activity or by Dataflow Gen2 does not automatically get Spark's defaults, so inspect the file layout and schedule maintenance separately.

Prevent small files

  • Optimize write shuffles data into well-sized bins before writing, so fewer, larger files are produced. It helps partitioned tables, frequent small inserts and operations that touch many files. It adds a shuffle, so use it where it pays off. You can enable it for one table with a table property:
ALTER TABLE dbo.sales
SET TBLPROPERTIES ('delta.autoOptimize.optimizeWrite' = 'true')
  • Auto compaction checks each partition after a write and, if too many small files exist, runs an OPTIMIZE straight after the commit. Enable it with the session setting spark.databricks.delta.autoCompact.enabled. It is the recommended default for Spark-written tables, and for streaming or micro-batch writes pair it with optimize write. Because it runs synchronously, a workload with strict write latency may prefer a scheduled OPTIMIZE instead, ideally on a separate pool.

Compact existing files with OPTIMIZE

OPTIMIZE rewrites small files into larger ones. Use it once on a table with a backlog of small files, then rely on auto compaction.

OPTIMIZE dbo.sales
OPTIMIZE dbo.sales ZORDER BY (order_date, customer_id)
OPTIMIZE dbo.sales VORDER
  • ZORDER BY colocates rows with similar values so selective filters on those columns skip more files. It pays off when queries filter on several columns together.
  • VORDER applies V-order to the rewritten files.
  • Combined order of work: compaction, then Z-order, then V-order.
  • Fast optimize (spark.microsoft.delta.optimize.fast.enabled) skips groups of files unlikely to benefit, which cuts rewriting.

You can run maintenance by hand from the lakehouse (right-click the table, Maintenance), from a notebook, or on a schedule with the Lakehouse maintenance activity in a pipeline (preview), which can run OPTIMIZE and VACUUM after your load. Maintenance applies to Delta tables only, not to plain Parquet or CSV folders. Dataflow Gen2 destinations that use incremental refresh do not support OPTIMIZE.

V-order

V-order is a write-time Parquet layout that speeds up reads, mainly for dashboards and Direct Lake, at a cost of about 15% on write time on average. In new workspaces it is off by default (spark.sql.parquet.vorder.default is false), because many workspaces are write-heavy. Turn it on at the session, table (delta.parquet.vorder.enabled) or write level for read-heavy tables, or use a read-heavy resource profile. Do not enable it only to help the SQL analytics endpoint.

Layout: liquid clustering, partitioning, Z-order

  • Liquid clustering is the recommended layout for read performance from Runtime 2.0. Declare CLUSTER BY columns when creating the table, or change them later, and OPTIMIZE applies them. Ordinary writes do not cluster data, so you still need compaction.
  • Partitioning is best reserved for cases that need concurrent writers that touch different partitions without conflict. Choose a low-cardinality column and aim for at least 1 GB per partition. Over-partitioning creates small files.
  • Z-order still suits older runtimes, tables that already have a Z-order routine, and skipping on several columns.
CREATE TABLE dbo.sales_txn (order_id BIGINT, order_date DATE, region STRING)
CLUSTER BY (order_date, region)

VACUUM

VACUUM deletes files no longer referenced by the log and older than the retention threshold, 7 days by default. It frees storage but does not speed up queries. Portal and API requests under 7 days are refused unless you change a Spark property. Shortening retention removes time travel history and can break concurrent readers.

Common mistakes

  • Running OPTIMIZE constantly instead of enabling auto compaction.
  • Partitioning by a high-cardinality column such as a customer id.
  • Expecting VACUUM to improve read speed.
  • Forgetting maintenance on tables written by pipelines or dataflows.

For the exam

  • Many small files hurt reads; fix with optimize write, auto compaction and OPTIMIZE.
  • OPTIMIZE ... ZORDER BY helps multi-column filters; liquid clustering is the modern layout choice.
  • V-order trades slower writes for faster reads and is off by default in new workspaces.
  • VACUUM has a 7-day default retention and reclaims storage only.
  • The Lakehouse maintenance activity runs OPTIMIZE and VACUUM from a pipeline.

Sources