Skip to content

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

ClickHouse 8 min read Deep dive mediumAdept

Clone massive tables instantly and experiment safely in ClickHouse

ClickHouse's `CREATE TABLE ... CLONE AS` creates a full, independent copy of a table almost instantly, without copying any data. It can do this because MergeTree data parts are immutable. Each part directory in the clone hard-links to the source's files, using POSIX hard links locally or metadata indirection on S3. Any later insert, update, delete or merge writes new parts, which gives part-level copy-on-write. Cloning time grows with part count rather than data size, the clone uses almost no extra storage until either table diverges, and shared files stay on disk until nothing references them. That makes clones safe for destructive tests, schema experiments, backfills and migrations.

Related posts

  • ClickHouse Release 24.10

    ClickHouse mediumAdept

    ClickHouse 24.10 adds a `--copy` mode and an `--implicit-select` calculator mode to clickhouse-local, a CLONE AS clause, real-time query metrics in the client, and a filesystem cache for S3 and Azure files. CLONE AS makes near-instant table copies by hard-linking immutable data parts, so the copy uses no extra storage and the two tables can then diverge independently. The remote file cache keys entries by path plus ETag, caches only the columns a query touches and evicts with LRU. In the example query it cut S3 GetObject calls from 186 to 0 and S3 read time from 16s to 122ms. Refreshable Materialized Views are now production-ready with Replicated database support, and the rewritten MongoDB integration supports all MongoDB data types and pushes down WHERE and ORDER BY.

  • 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.

  • ClickHouse and dbt - A Gift from the Community

    ClickHouse mediumAdept

    The dbt-clickhouse adapter, started by community contributor Dmitriy Sokolov and later taken over as a vendor-supported plugin, maps dbt's view, table, incremental and ephemeral materializations onto ClickHouse features. The default incremental strategy builds a temporary table of changed rows, copies all unchanged rows into a new table and atomically swaps it in, which duplicates the whole dataset on every run. A newer delete+insert strategy uses ClickHouse 22.8's experimental lightweight deletes (tombstones removed during merges) to write only the changed rows and performs significantly better. Its caveats: it needs the experimental setting enabled, and because it modifies the target table directly with no transaction, a failure can leave the model in an invalid state.

  • 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: Fast, Updatable Lookups with the Join Table Engine

    ClickHouse mediumAdept

    ClickHouse's Join table engine keeps a precomputed in-memory hash map for a fixed join strictness, type and key. With ANY LEFT strictness, inserts behave as upserts, which suits Type 1 slowly changing dimensions as an updatable alternative to Dictionaries, queried via Direct Join or joinGet. In open source the engine isn't distributed and persists each insert as an uncompacted .bin file, which degrades over time. ClickHouse Cloud transparently backs Join tables with a SharedJoin over a MergeTree (ALL) or ReplacingMergeTree (ANY) table, refreshing memory with a FINAL query on insert and startup, so deduplication, compaction and clustering are handled automatically.

The quest for software engineering knowledge.

Look:
Layout: