Deep clone = independent copy (data + metadata), incremental on re-run. Shallow clone = instant pointer to the source's files. Predictive Optimization auto-runs maintenance for you. This deep dive walks each with the code.
DEEP CLONESHALLOW CLONEincrementalPredictive Optimization
The one-liner
DEEP CLONE copies data + metadata โ independent table (re-runs sync only the delta). SHALLOW CLONE copies only metadata and references the source's files โ instant & cheap but dependent. Predictive Optimization auto-runs OPTIMIZE/VACUUM/ANALYZE on UC managed tables.
๐ Analogy: deep clone = photocopying a whole book (your own copy); shallow clone = sticky-notes referencing the original (instant, but useless if the original is thrown out); PO = a robot librarian that reshelves & declutters automatically.
Clone types โ and the VACUUM trap
โธ pick a clone type, then run VACUUM on the source
DEEP CLONE
SHALLOW CLONE
Source table
data files: present
โ copied โ
Clone
owns its own data
1 ยท The two clone types
Both copy schema, partitioning, invariants, nullability, and TBLPROPERTIES (deep also copies stream/COPY INTO metadata). Neither copies history, description, or UC tags. CLONE defaults to deep.
SQL โ deep, shallow, versioned
CREATE TABLE main.dr.orders_backup DEEP CLONE main.sales.orders; -- independent copyCREATE TABLE main.dev.orders_dev SHALLOW CLONE main.sales.orders; -- instant, points at sourceCREATE TABLE main.dev.orders_v5 SHALLOW CLONE main.sales.orders VERSION AS OF5;
PySpark โ CLONE is SQL DDL, run via spark.sql
spark.sql("CREATE OR REPLACE TABLE main.dr.orders_backup DEEP CLONE main.sales.orders")
2 ยท Deep clone is INCREMENTAL (the backup superpower)
Re-running a deep clone into an existing target commits only the new/changed data since the last clone โ cost scales with the change, not table size. That's why it's the go-to for scheduled backups, DR, and cross-catalog/region migration.
-- Day 1: full copy. Day 2..N: same command re-syncs ONLY the delta since last run.CREATE OR REPLACE TABLE main.dr.orders_backup DEEP CLONE main.sales.orders;
3 ยท Shallow clone & the VACUUM trap
Shallow clone borrows the source's data files, so it's instant โ but two consequences interviewers probe:
VACUUM on the source breaks the shallow clone โ readers hit FileNotFoundException.
Readers need access to both the source's storage and the clone's directory.
๐ก For a durable copy that survives source maintenance, use DEEP CLONE. Also note: streaming tables & materialized views can't be a clone source or target.
4 ยท Predictive Optimization โ click each
What it doesโธ
Automatically runs maintenance โ OPTIMIZE (incl. incremental clustering), VACUUM, and ANALYZE โ on Unity Catalog managed tables based on usage. No manual scheduling.
Why it mattersโธ
Removes the "did you schedule OPTIMIZE/VACUUM?" toil and avoids both under- and over-maintenance. Modern answer to "how do you keep tables fast?"
Scope & defaultโธ
Applies to UC managed tables (external you maintain yourself). Enabled by default for accounts created on/after Nov 11, 2024; older accounts via gradual rollout.
Enable at catalog or schema level (inherits down)
ALTER CATALOG main ENABLE PREDICTIVE OPTIMIZATION;
ALTER SCHEMA main.sales ENABLE PREDICTIVE OPTIMIZATION; -- or DISABLE / INHERIT
Deep vs shallow โ at a glance
Deep clone
Shallow clone
Copies data files
Yes
No (points at source)
Speed / cost
Slower / more storage
Instant / cheap
Independent of source
Yes
No (VACUUM on source breaks it)
Incremental re-sync
Yes
n/a
Good for
Backup, archive, DR, migration
Test/dev, sharing
Why it matters
Shallow clone = instant test/dev copy of a huge prod table without duplicating terabytes โ a favorite trick & interview answer.
Deep clone is incremental โ cheap, repeatable backups/DR.
PO removes maintenance toil โ the modern answer to "how do you keep tables performant?"
๐งช Real-world use case: before a risky migration, SHALLOW CLONE prod.orders to a sandbox in seconds, experiment, then drop it โ zero data copied. For DR, a nightly DEEP CLONE re-syncs only the day's changes.
Uses, edge cases & limitations
Uses: shallow โ cheap test/dev/sharing copies; deep โ backups, archiving versions, ML reproducibility, DR, cross-region migration.
Edge case: shallow clone depends on source files โ VACUUM on the source breaks it (FileNotFoundException); readers need access to both source & clone. Clones have independent history; deep re-runs are incremental.
Limitation: can't clone streaming tables or materialized views; CLONE doesn't copy history/description/UC tags. PO applies to UC managed tables only.
Common gotchas
โ Treating a shallow clone as a real backup โ VACUUM on the source destroys it. Use deep clone for durable copies.
โ Expecting CLONE to copy history/tags/description โ it doesn't.
โ Manually scheduling OPTIMIZE/VACUUM where PO already runs.
โ Trying to clone a streaming table / materialized view โ unsupported.
โ Re-doing a full copy for backups โ a repeat DEEP CLONE only syncs the delta.