Typorithm · medium

Parts & Merges

parts-and-mergesclickhousepartsmergeswrite-path
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Parts & Merges

0%

Columns & Engines

Each INSERT writes a new immutable part; ClickHouse merges parts in the background, and OPTIMIZE ... FINAL forces a merge.

MergeTree never updates rows in place — every INSERT creates a new sorted, immutable part.

A background process continuously merges small parts into larger ones, reclaiming space and keeping reads fast.

OPTIMIZE TABLE ... FINAL forces an immediate full merge, but it is expensive and meant for occasional maintenance.

01

INSERT = one new immutable part.

02

Background merges combine parts.

03

OPTIMIZE FINAL forces a merge (costly).

INSERT INTO events VALUES
    ('2026-06-01', 42, 'click', 1.5),
    ('2026-06-01', 42, 'view', 0.0);

OPTIMIZE TABLE events FINAL;

Read the implementation

Connect each part of the code to the concept before you type.

1. Insert writes a part

Each INSERT writes one new immutable part on disk.

INSERT INTO events VALUES

2. Batch the rows

Send many rows per INSERT to avoid creating too many tiny parts.

('2026-06-01', 42, 'click', 1.5),
    ('2026-06-01', 42, 'view', 0.0)

3. Force a merge

FINAL forces parts to merge now — costly, use rarely.

OPTIMIZE TABLE events FINAL

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

Parts & Merges: Lesson & Practice · Typorithm | ApplyDjinn