Skip to the page
Tecyfy

Databricks Performance Tuning: A Checklist That Starts with What Is Automatic

How to make Databricks workloads faster and cheaper: predictive optimization, liquid clustering, Photon, right-sized compute, adaptive query execution, joins and skew, the disk cache and VACUUM, in the order that saves the most.

Tecyfy · Published · Updated · 7 min read

Most slow or expensive Databricks workloads come down to a few causes: tables laid out so that queries read far more files than they need, compute that is the wrong size or never shuts down, and joins that move or pile up too much data. Much of the tuning that used to be manual is now automatic, so the first job is to make sure the automatic features are on, and only then tune by hand.

This checklist goes in that order: what Databricks does for you, the table layout, the compute, the queries, and the cleanup. Each step links to a fuller guide where Tecyfy has one.

1. Use Unity Catalog managed tables with predictive optimization

Predictive optimization runs OPTIMIZE, VACUUM and ANALYZE on Unity Catalog managed tables by itself, choosing which tables need them, and collects statistics as data is written. On the Premium plan or above, in supported regions, it is on by default for accounts created on or after 11 November 2024, and Databricks is turning it on for older accounts. It runs on serverless jobs compute, billed separately.

On a managed table, Databricks also tunes file sizes automatically, so the old manual settings for target file size, optimized writes and auto compaction mostly do not apply. Predictive optimization does not run on external tables, so schedule maintenance for those yourself. If your account predates the rollout, check whether it is on before you schedule maintenance jobs of your own.

2. Cluster tables by the columns you filter on

Reading fewer files is one of the most direct savings: the right clustering keys significantly improve data skipping and query performance. Databricks recommends liquid clustering for new tables in place of partitioning and ZORDER:

CREATE TABLE sales.orders (...) CLUSTER BY (customer_id, order_date);
-- or, on a Unity Catalog managed table with predictive optimization, let Databricks choose the keys from your query history
ALTER TABLE sales.orders CLUSTER BY AUTO;

Pick up to four keys from the columns your queries filter on. Our liquid clustering guide covers choosing keys, converting partitioned tables and the protocol versions readers need.

If you still have tables with ZORDER, they keep working, but but predictive optimization does not run ZORDER and ignores Z-ordered files, while liquid clustering is incremental: OPTIMIZE only rewrites data as necessary.

3. Use Photon where the work is SQL and DataFrames

Photon is Databricks' native vectorized engine. It is always on in SQL warehouses and serverless compute, and on by default for classic compute created in the UI; through the Clusters or Jobs API you must set runtime_engine to PHOTON yourself. It needs no code change, and where a query uses something Photon does not support, such as a Python UDF, that part falls back to the Spark engine.

Photon helps most with joins, aggregations and scans of large tables. It consumes DBUs at a different rate than the same instance without it, and queries that normally finish in under two seconds see no meaningful improvement, so for simple jobs that finish in seconds it can cost more than it saves. On classic compute, check which operators run in Photon in the Spark UI's SQL/DataFrame tab before deciding; on SQL warehouses and serverless, the query profile shows the share of task time spent in Photon.

4. Size compute to the job, and let it stop

  • Shut down idle compute. Set auto termination on every all-purpose cluster.
  • Use jobs compute or serverless for scheduled work, not an all-purpose cluster. On AWS at the Premium tier, jobs compute costs $0.15 per DBU and all-purpose compute $0.55, before the cloud's own machine price.
  • Autoscale long jobs whose load changes from stage to stage.
  • Use instance pools when start-up time matters.

To find the right size and what it costs, use the Spark cluster sizing calculator and the Databricks cost calculator, which prices each worker type, serverless and SQL warehouses on each cloud.

5. Let adaptive query execution fix plans at run time

Adaptive query execution (AQE) re-plans a query while it runs, using the real size of the data after each shuffle. It turns a sort-merge join into a broadcast join when one side turns out to be small, combines small partitions after a shuffle, and splits skewed partitions in joins. It is on by default, so you do not need the SET spark.sql.adaptive.* lines found in older guides. Tune its settings only when the defaults do not fit.

Statistics help the optimizer choose before AQE has to correct it. With predictive optimization on, they are collected for you; otherwise run ANALYZE TABLE ... COMPUTE STATISTICS FOR ALL COLUMNS after large loads.

6. Fix joins and skew

Most slow stages are joins. Broadcast the small side when it fits in memory, filter both sides before joining, and look for the one task that runs far longer than the rest, the sign of a skewed key. Two guides cover this in depth:

Dynamic file pruning also helps joins without any change: when a large Delta table is joined to a small filtered one, Databricks skips files of the large table that cannot match. It is on by default, and in MERGE, UPDATE and DELETE it needs Photon.

7. Prefer the disk cache to df.cache()

Databricks keeps a copy of each Parquet or Delta file a worker reads on its local disk, so repeated reads of the same data are faster. This disk cache, once called the Delta cache, is automatic on worker types with local SSDs. Databricks recommends it over the Spark cache for repeated reads of tables. Keep df.cache() for a DataFrame you compute once and then use several times in the same job, and call unpersist() when you are done with it.

8. Clean up old files with VACUUM

Every update and delete leaves old data files behind for time travel. VACUUM removes those older than the retention threshold, 7 days by default, which cuts storage cost. Predictive optimization runs it on managed tables. For large tables vacuumed often, VACUUM ... LITE uses the transaction log instead of listing every file; our VACUUM LITE guide explains when it applies.

Tecyfy Takeaway

Start by making sure the automatic features are on: Unity Catalog managed tables, predictive optimization, Photon where the work is SQL, AQE and the disk cache. Then spend your effort on the two things nothing can do for you: clustering tables by the columns you actually filter on, and sizing and stopping compute. Measure with the query profile before and after each change, because the right setting depends on your data.

Questions

How do I make Databricks queries faster?
First make sure the automatic features are on: Unity Catalog managed tables with predictive optimization, Photon, adaptive query execution and the disk cache. Then cluster tables by the columns you filter on, size compute to the job and fix slow joins and skew.
What is predictive optimization in Databricks?
Predictive optimization runs OPTIMIZE, VACUUM and ANALYZE on Unity Catalog managed tables by itself, choosing which tables need them. On the Premium plan or above, in supported regions, it is on by default for accounts created on or after 11 November 2024, and runs on serverless compute billed separately.
Should I use liquid clustering or ZORDER?
Databricks recommends liquid clustering for new tables in place of partitioning and ZORDER. Pick up to 4 keys from the columns your queries filter on, or, on Unity Catalog managed tables with predictive optimization, use CLUSTER BY AUTO to let Databricks choose them from your query history.
Is Photon worth the extra cost?
For joins, aggregations and scans of large tables, usually. Photon consumes DBUs at a different rate, so for simple jobs that finish in seconds it can cost more than it saves; check which operators run in Photon in the Spark UI on classic compute, or the share of time in Photon in the query profile on SQL warehouses and serverless.
How do I cut Databricks compute costs?
Set auto termination on every all-purpose cluster, run scheduled work on jobs compute or serverless instead of all-purpose clusters, autoscale jobs whose load varies, and size clusters to the job. On AWS Premium, jobs compute is $0.15 a DBU against $0.55 for all-purpose.