Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

ClickHouse 12 min read Deep dive mediumAdept

How we built fast UPDATEs for the ClickHouse column store – Part 1: Purpose-built engines

ClickHouse avoids slow in-place row updates in its column store by expressing updates and deletes as inserts that get resolved during the background merges MergeTree already performs. Sorted, immutable data parts can be merged in a single linear pass, so keeping only the latest version adds almost no overhead. ReplacingMergeTree keeps the latest full row per sorting key, CoalescingMergeTree merges sparse partial updates using Nullable columns, and CollapsingMergeTree cancels rows with a sign column, which also lets it change sorting key values. All three give UPSERT semantics but are only eventually consistent, so queries that need current results use FINAL to apply the merge logic in memory at read time.

Assumes: column-oriented storage basicsSQL DDL and insertsLSM-style background merges

Related posts

  • How we built fast UPDATEs for the ClickHouse column store – Part 2: SQL-style UPDATEs

    ClickHouse hardMaster

    ClickHouse implemented standard SQL UPDATE in its MergeTree column store by evolving from classic mutations (which rewrite whole affected columns and hard-link unchanged ones) through lightweight DELETEs via a _row_exists mask column and on-the-fly in-memory updates, to patch parts. A patch part is a compact delta containing only changed column values plus _part and _part_offset metadata. It is visible to queries immediately and applied during normal background merges in a single linear pass, with no resorting or extra indexing. This avoids full column rewrites and blocking on prior merges, making frequent row-level updates practical (experimental in 25.7, beta expected in 25.8).

  • ClickHouse 25.6 summer bonus: CoalescingMergeTree table engine

    ClickHouse mediumAdept

    CoalescingMergeTree, new in ClickHouse 25.6, consolidates sparse partial-row inserts during background merges by keeping, per sorting key and per column, the latest non-null value as determined by insertion order rather than a timestamp. Using an IoT vehicle-telemetry example, it contrasts the approach with UPDATEs, ReplacingMergeTree full-row overwrites, and plain MergeTree with argMax() aggregation that must scan every row. Because merges usually lag behind ingest, queries should still use GROUP BY with argMax() over a timestamp column, or the FINAL modifier, which applies the coalescing logic in memory at query time and makes the timestamp optional.

  • Handling Updates and Deletes in ClickHouse

    ClickHouse mediumAdept

    ClickHouse offers several ways to modify mostly-immutable analytical data, each with different costs. Lightweight Deletes (DELETE FROM) write a _row_exists mask and rely on background merges to physically remove rows, which makes them cheap but leaves space reclamation non-deterministic. ALTER UPDATE/DELETE mutations rewrite whole parts, so they are heavy but guarantee removal, which matters for compliance. Cheaper alternatives cover specific cases: swapping in a new column with a DEFAULT for whole-table updates, Join engine plus joinGet for join-based updates, dropping partitions or using TTL for bulk and time-based deletion, and CollapsingMergeTree sign rows for frequent row-level updates.

  • ClickHouse Cloud boosts performance with SharedMergeTree and Lightweight Updates

    ClickHouse mediumAdept

    SharedMergeTree is a new ClickHouse Cloud table engine that replaces ReplicatedMergeTree (and its zero-copy replication variant) by moving both data and part metadata off the servers into shared object storage and ClickHouse Keeper. Servers become stateless compute nodes: they cache subsets of metadata locally and learn about new parts through Keeper subscriptions rather than a replication log and exclusive locks. New nodes can join almost instantly, and inserts are durable once the part is in object storage and its metadata is in Keeper. This removes the replication-log contention and local-disk dependencies that limited scaling beyond a few replicas. Lightweight updates are introduced alongside and benefit from the shared-metadata design.

  • How we made ClickHouse UPDATEs 1,000× faster (Part 3: Benchmarks)

    ClickHouse hardMaster

    ClickHouse's new standard SQL UPDATEs, implemented as lightweight patch parts, make changes visible up to ~1,000–1,700× faster than classic mutations on a 600M-row TPC-H lineitem table: one bulk update dropped from about 100 s to 60 ms. The benchmark compares classic mutations, on-the-fly mutations, lightweight updates and ReplacingMergeTree inserts for both bulk and single-row updates, measuring time to visibility and worst-case query slowdown before merges. Lightweight updates add only about 12–15% average query overhead, rising to 39–121% in a rare join-mode fallback. On-the-fly mutations average 149% slowdown, and ReplacingMergeTree with FINAL averages about 280% slowdown with 20–200× the memory. ReplacingMergeTree inserts are the fastest way to write single rows, but lightweight updates give the best balance of write speed and query cost.

The quest for software engineering knowledge.

Look:
Layout: