In DuckDB, an UPDATE on an Iceberg table is a delete plus an insert. A CDC MERGE has both
WHEN MATCHED THEN UPDATEandWHEN NOT MATCHED THEN INSERT, so it has two actions that append to the table, and DuckDB runs them one after the other on one thread. The scan and the join still run in parallel, but the writes run on one thread. New rows are buffered, spilling to disk, before they are written. Size a CDC MERGE into Iceberg for one writing core and a fast temp disk, not for threads, and load CDC snapshots using INSERT.
We replicate Postgres tables into Iceberg with an in-process DuckDB:
flowchart LR PG[Postgres] -->|CDC| AV[Avro files in object storage] AV -->|one batch| DD[Keep the newest change per key] DD -->|MERGE| IC[Iceberg table]
Staging the changes in object storage decouples capture from loading, and is simpler to run than Kafka.
Each batch mixes new, updated and deleted rows. After deduplication the loader runs one MERGE:
MERGE INTO lake.shop.orders AS T
USING stage_latest AS S
ON T.id = S.id
WHEN MATCHED THEN UPDATE SET status = S.status, ..., is_deleted = S.is_deleted
WHEN NOT MATCHED THEN INSERT (id, status, ..., is_deleted) VALUES (S.id, S.status, ..., S.is_deleted);
We could not explain why the MERGE did not speed up with more threads, or understand its use of memory and disk
space. So we measured MERGE performance with different mixes of INSERTs, UPDATEs and DELETEs. Since we support soft
deletes, DELETEs are converted to an UPDATE with is_deleted = true.
Measurements
The test table is shaped like an orders table in Postgres: 37 columns of ids, decimals, integers, booleans, timestamps and short and medium strings, about 400 bytes a row. The Iceberg table starts with 10 million rows. Each batch has 4 million rows, one per key:
- 5% of the batch are deletes of existing rows.
- Measurements were taken for datasets with different ratios of new and updated rows.
- A special case is 100% of the dataset as new rows, to represent a CDC snapshot (below).
- Updated and deleted keys are spread over the whole table.
Each mix ran twice: with a 16 GiB memory_limit, where the MERGE has room, and with a 2 GiB one, where it spills.
With a 16 GiB Limit: The Buffer Stays in Memory

- With a 16 GiB memory limit, DuckDB processes the dataset in memory without any spills to disk.
- Time taken is proportional to the number of UPDATEs.
- Memory used is proportional to the number of INSERTs.
- 4 threads are faster, as the SCAN and JOIN can run in parallel. Beyond that, more threads are not useful.
With a 2 GiB Limit: The Buffer Spills to Disk

- The amount spilled to disk is proportional to the number of INSERTs, as expected.
- Writing updated rows is more expensive than spilling to disk for this dataset, due to full-row rewrites.
- Threads do not help, due to single-threaded writes.
- A single thread could not handle 100% UPDATEs: it failed with DuckDB’s own
Out of Memory Error.
An Edge Case: Loading a CDC Snapshot
A CDC snapshot is all new rows into an empty table. The same 4 million rows were written three ways: the CDC MERGE, a MERGE with only the INSERT clause, and an INSERT.

With a 16 GiB limit, the CDC MERGE holds every row in memory before it writes them: 4.9 GiB. The MERGE with only the INSERT clause and the INSERT stream the rows to Parquet and use about 1 GiB.

With a 2 GiB limit, the CDC MERGE spills 1.8 GiB to disk and takes 20.5 s instead of 7.2 s. The other two do not spill and take 2–3 s at either limit. Spilling has a major effect on runtime, so avoid a MERGE for a CDC snapshot: load it with an INSERT.
MERGE into a DuckDB Table Behaves Differently
The same CDC MERGE into a DuckDB table:

- DuckDB updates its own tables in place, so the MERGE has one appending action: it does not buffer the new rows. A CDC snapshot takes 3.7 s without spilling, close to an INSERT (2.8 s), and uses 1.4 GiB.
- It runs in parallel, keeping 3.4–3.8 of 4 cores busy at every mix.
- The batch was sorted by key for the mixes with updates: in random key order, updating string columns in a DuckDB table was hundreds of times slower, for reasons that deserve a post of their own.
How DuckDB Runs a MERGE into Iceberg
flowchart LR B[Batch] --> J[Hash join with the table] J --> M[Merge Into] M -->|matched rows, streamed| U[UPDATE: write new row versions and position deletes] M -->|new rows, buffered in memory or on disk| I[INSERT: write new rows] U -.->|runs first, then| I
The scan and the join run in parallel. After the join, the MERGE has two branches: one writes the UPDATEs and one writes the INSERTs. For a DuckDB table, the two branches run in parallel. For an Iceberg table, DuckDB runs them one after the other, each on one thread. It starts with how the Iceberg extension handles an UPDATE.
An Iceberg UPDATE Is a Delete Plus an Insert
Iceberg data files are immutable, so the extension turns every UPDATE into a delete of the old row and an insert of
the new one
(iceberg_update.cpp):
// all updates in DuckDB-Iceberg are deletes + inserts
update.update_is_del_and_insert = true;
A CDC MERGE therefore has two actions that write new rows to the table: the UPDATE and the INSERT.
Two Writing Actions Run One After the Other, on One Thread
When more than one action writes new rows, the planner runs them one after the other and turns off their parallelism
(plan_merge_into.cpp,
physical_merge_into.cpp):
bool serialize_actions = append_count > 1;
...
max_threads = op.parallel ? exchange->MaxThreads() : 1; // parallel = !serialize_actions
Each action reads its rows and writes its Parquet files on one thread.
Only the First Action Streams; the INSERT’s Rows Are Buffered
The second action must hold all its rows until the first finishes
(physical_merge_into.cpp):
// if the actions must run one after the other only the first action can stream: the rows of the other actions
// are buffered (spilling to disk if required)
WHEN MATCHED sorts first, so the UPDATE streams and every new row waits in the INSERT’s buffer, in memory or, past
memory_limit, on disk.
What This Explains
| Observation | Cause |
|---|---|
| More threads do not make the MERGE faster; it keeps one or two cores busy | Both actions write on one thread. Only the scan and the join run in parallel. |
| Memory at 16 GiB and spill at 2 GiB grow with the number of INSERTs | Every new row is buffered until the UPDATE finishes. |
| Time grows with the number of UPDATEs | Each updated row is written in full as a new row, on one thread. With no new rows, that write was 44 s of a 54 s MERGE; the position deletes took under half a second. |
| A CDC snapshot is slow as a MERGE and fast as an INSERT | The MERGE buffers every row. An INSERT, or a MERGE with only the INSERT clause, has one writing action, so it streams in parallel. |
| A MERGE into a DuckDB table runs in parallel without buffering | DuckDB updates its own tables in place, so only the INSERT writes new rows. |
How We Measured
- DuckDB v2.0.0 with its iceberg extension, against a local Iceberg REST catalog (
apache/iceberg-rest-fixture) with its warehouse on local NVMe. No object storage or network is involved. - An 8 vCPU, 64 GiB machine (61 GiB usable). In the 2 GiB runs, DuckDB spilled to local NVMe; the 16 GiB runs did not spill.
- Every run rebuilt the target table, then timed only the MERGE. The batch was read from a DuckDB table: the deduplicated batch, not the Avro files.
- Memory is
duckdb_memory(), spill is the size of DuckDB’s temp directory, both sampled every 200 ms. Cores busy is process CPU time divided by wall time. - Each configuration ran once; the CDC snapshot runs ran twice.