Copy-on-write: what changes after a clone is edited?
When either source or clone changes, Snowflake writes new data for the changed state while other references can continue using old immutable data.
Your learning goal
Predict both tables’ values after independent edits and distinguish logical row changes from physical storage accounting.
Understand the idea
A concrete example
QA raises order 101 from 100 to 110. Production-like data raises 104 from 50 to 60. Each table should show only its own change, despite originally sharing storage.
| Concept | What it means |
|---|---|
| Shared start | Both objects refer to existing source data. |
| Clone write | Changes the clone’s state, not the source’s state. |
| Source write | Changes the source’s state, not the clone’s state. |
| Retained blocks | History or another clone may still reference previous data. |
Remember: Validate isolation by key and value, and budget for divergence, historical versions and clone lifetimes.
Explain it step by step · full theory
Learning objectives and prerequisites
Predict both tables’ values after independent edits and distinguish logical row changes from physical storage accounting.
Build on Modules 02–04: storage, table types, SELECT, DML and transactions. Module 13 explains why recovery must preserve valid business history. Use the first lesson’s isolated setup; examples name separate demonstration tables so the baseline ORDERS stays unchanged.
Follow references instead of imagining two full copies
Imagine source and QA both referencing blocks A and B. Updating QA’s order in A gives QA new data A_QA while the source still uses A. Updating the source’s order in B gives it B_PROD while QA still uses B.
These names are a teaching model. A four-row SQL fixture does not guarantee two physical micro-partitions, and a ten-unit amount change does not mean ten bytes of additional storage. Rewrites happen at managed storage granularity.
Prove isolation at the data level
Inspect values by key in both tables. The two example totals each become 510, even though different rows changed. This is an important trap: equal totals do not prove that two tables have the same contents.
Use row-level comparison when proving source isolation. If a QA update appears in the source, check your fully qualified SQL target and any procedures or views that still reference the source. Clone independence does not prevent you from accidentally writing to the wrong name.
Why dropping a source may not remove its data
An active clone still needs the shared data it references. A source drop therefore cannot simply remove every block if the clone depends on it. Time Travel and other references may also retain older data.
Do not add logical table sizes to estimate physical billing across a clone group. Observe storage categories over time and keep an inventory of long-lived test environments. Storage attribution is a separate problem from the logical correctness of SELECT results.
When copy-on-write becomes expensive
Frequent large rewrites on many QA branches can create considerable divergent data and history. Cloning is useful for short-lived experiments, but a permanently running clone farm needs cost and lifecycle governance.
Choose a named owner and expiry date for each clone. Keep an untouched evidence snapshot separate from writable experiments if incident reproducibility matters. Do not shorten production retention solely to make a QA experiment cheaper.
Production decisions and common mistakes
Validate isolation by key and value, and budget for divergence, historical versions and clone lifetimes.
Do not infer identical data from identical SUM results or infer storage bytes from the number of updated rows.
Key takeaways
Other objects or historical recovery windows may still require its data. Remove unneeded references deliberately and inspect delayed physical storage metrics instead of expecting immediate reclamation.
Words used in this lesson
- Copy-on-write
- Create changed storage rather than modifying shared immutable data in place.
- Divergence
- Source and clone develop different data states.
- Clone group
- Related objects sharing a cloning ancestry.
- Physical storage
- Actual managed data bytes, unlike logical row counts.
See how it works
Choose a step to explore the idea at your own pace.
Open the interactive explanation
Copy-on-write: what changes after a clone is edited?
- A
- B
- A
- B
Shared starting point
Both objects reference A and B. Zero-copy describes this starting relationship, not a promise that running the QA environment costs nothing.
Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.
Read the complete diagram explanation
- Shared starting point
Both objects reference A and B. Zero-copy describes this starting relationship, not a promise that running the QA environment costs nothing.
- Source: A; B
- QA: A; B
- QA changes order 101
The affected data is written in new immutable storage, illustrated as A_QA. Source queries still reference A. The drawing does not predict rewrite size.
- Source: A · 101 amount 100; B
- QA: A_QA · 101 amount 110; B
- Source changes order 104
The source now references B_PROD, while QA still references B. Changes do not automatically propagate in either direction.
- Source: A; B_PROD · 104 amount 60
- QA: A_QA; B · 104 amount 50
- Old references can remain billable
History and clones can retain old blocks after a source change or drop. Count unique retained physical data conceptually, not logical table sizes added together.
- Referenced blocks: A; B; A_QA; B_PROD
- Cost decision: Expire unused environments; Review retention
Try the SQL or command
Read → predict → run in your learning environment → compare. You can also learn by reading without an account.
New to SQL? Where to run it and how to read it
A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.
- No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
- For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
- Read the entire example, including comments beginning with
--. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor. - Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
- SELECT / FROM
- Choose the values to return / identify their input.
- VALUES / COLUMN1
- VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
- AS / WITH
- AS gives a result a readable name. WITH names a temporary query step within one statement.
- NULL / ::
- NULL means missing or unknown. The :: notation converts a value to a named data type.
- Session
- One connection and its settings. Keep related transaction steps in the same session.
- Database.schema.table
- A full address for stored data. It is separate from the warehouse that processes queries.
Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →
Help with common practice errors
- No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
- Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
- Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
- Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.
Before running this lesson
Manual Snowflake practice only; SQL has not been executed for this course. Use an authorized warehouse and role with access to L2_OBJECTS_LAB and CREATE SCHEMA/CREATE TABLE as needed. Run in M14_LAB, in one session with one writer, using autocommit unless a transaction is shown. Run CREATE once, never replace an existing production object. Standard Edition with one-day retention is sufficient for the main lab; longer retention and administrative monitoring have separate requirements.
Change both sides independently
Definition: Separate DML targets demonstrate independent data states.
When to use: Fresh COW_SOURCE and COW_QA objects, so no earlier exercise state is required.
USE SCHEMA L2_OBJECTS_LAB.M14_LAB;
CREATE TABLE COW_SOURCE CLONE ORDERS;
CREATE TABLE COW_QA CLONE COW_SOURCE;
UPDATE COW_QA SET AMOUNT=110 WHERE ORDER_ID=101;
UPDATE COW_SOURCE SET AMOUNT=60 WHERE ORDER_ID=104;
SELECT s.ORDER_ID,s.AMOUNT AS SOURCE_AMOUNT,q.AMOUNT AS QA_AMOUNT
FROM COW_SOURCE s JOIN COW_QA q ON s.ORDER_ID=q.ORDER_ID
ORDER BY s.ORDER_ID;What to expect and why
101 differs only on QA; 104 differs only on source. Both totals happen to be 510, so the row-level check is necessary.
| ORDER_ID | SOURCE_AMOUNT | QA_AMOUNT |
|---|---|---|
| 101 | 100.00 | 110.00 |
| 102 | 200.00 | 200.00 |
| 103 | 150.00 | 150.00 |
| 104 | 60.00 | 50.00 |
Keep an independent clone after a source drop
Definition: Remaining objects retain their required data references.
When to use: Optional disposable demonstration, not a cleanup method for production.
CREATE TABLE COW_DROP_SOURCE CLONE ORDERS;
CREATE TABLE COW_SURVIVOR CLONE COW_DROP_SOURCE;
DROP TABLE COW_DROP_SOURCE;
SELECT COUNT(*) AS N,SUM(AMOUNT) AS TOTAL FROM COW_SURVIVOR;What to expect and why
COW_SURVIVOR remains readable with four rows totaling 500. This does not promise that billed storage immediately falls after the source drop.
| N | TOTAL |
|---|---|
| 4 | 500.00 |
Check your understanding
Choose an answer, then check your reasoning. This is practice, not a scored test.
Try it yourself
Why can a dropped source still be associated with retained storage?
Compare your reasoning
Other objects or historical recovery windows may still require its data. Remove unneeded references deliberately and inspect delayed physical storage metrics instead of expecting immediate reclamation.
Key takeaway
Validate isolation by key and value, and budget for divergence, historical versions and clone lifetimes.
Connect this lesson to the learning path
Official sources and curriculum
Module 14 · See module scope
By Rohit Ray · Independent educational lesson · Explore this visual lab