Sub topic 16
Automating maintenance with predictive optimization
This chapter assumes you know Delta Lake basics, have used OPTIMIZE and ANALYZE TABLE (covered in earlier chapters), and work with Unity Catalog managed tables.
What predictive optimization does
Earlier chapters had you run maintenance by hand: OPTIMIZE to compact small files, clustering to improve data skipping, and ANALYZE TABLE to refresh statistics. Predictive optimization moves that work to Databricks. It watches how your Unity Catalog managed tables are used and runs maintenance when it is likely to pay off.
It can run these operations:
OPTIMIZE, which compacts small files and applies clustering (including liquid clustering).VACUUM, which deletes data files that are no longer referenced and are past the retention period.- Statistics collection, which keeps column statistics current for the optimizer.
The operations run on serverless compute managed by Databricks. You don't schedule jobs or size a cluster for them.
Turning it on
You enable it at the account, catalog, or schema level. Settings are inherited, so a schema follows its catalog unless you override it. You need the right privileges, and the feature is available only for managed tables in Unity Catalog. External tables are not covered. Check the current documentation for region and plan availability, because rollout has changed over time.
ALTER CATALOG main ENABLE PREDICTIVE OPTIMIZATION;
ALTER SCHEMA main.sales INHERIT PREDICTIVE OPTIMIZATION;To see what is in effect for a table, describe it:
DESCRIBE EXTENDED main.sales.orders;The output includes whether predictive optimization is enabled for the table.
Checking what it ran
Maintenance is not hidden. Databricks records each run in a system table, so you can audit the work and its cost.
SELECT *
FROM system.storage.predictive_optimization_operations_history
ORDER BY start_time DESC
LIMIT 20;Each row shows the table, the operation type, its status, and the usage it consumed. Use this to confirm that your hot tables are being maintained and to see the cost.
Limits and common mistakes
- It is not a replacement for good design. It compacts and maintains. It will not fix a poor clustering choice or replace a Python UDF with built-in functions.
- Timing is not under your control. A table may wait before it is maintained. If a pipeline needs a compacted table right after a large load, run
OPTIMIZEyourself. - Managed tables only. If a table seems untouched, check whether it is external.
- It has a cost. The serverless usage is billed. Review the history table, particularly for large tables that change often.
- Do not assume statistics are fresh. After a big change, confirm the plan's row estimates before you trust join choices.
Exercise
A team enabled predictive optimization on a catalog, but one table in it never appears in the operations history. Name two likely causes and how you would check each.
Show answer
The table may be external rather than managed, which predictive optimization does not cover. Check the table type with DESCRIBE EXTENDED. Or the feature may be disabled at the schema or table level, overriding the catalog setting, or the table may not have needed maintenance yet. Check the setting inherited by the schema and table, and query the operations history system table filtered by the table name.