1 · INTERNALS · MERGER
Mergers: From Smaller Units to Larger Ones
-- партиция 202609, уровень 0
202609_1_1_0 546 794 строки
202609_3_3_0 546 579
202609_6_6_0 547 282
202609_7_7_0 547 425
202609_9_9_0 271 393
│
▼ слияние: фоном или OPTIMIZE
202609_1_9_1 2 459 473 строки, уровень 1
-- старые: active = 0, удалятся через 8 мин
Merging combines the segments of a single partition.
1. Unpack the columns of the parts.
2. Merge the already sorted streams.
3. Build an index, compress, and write the new segment.
4. Replace atomically: a query sees either the old segments or the new one.
Only within the partition
The server decides when
These engines are in use here
The parts grow to about 150 GB; each merge represents a +1 level.
Background threads (background_pool_size). There is never a "one-of" guarantee.
Replacing, Summing, Aggregating, and TTL are applied during the merge. Before that—FINAL or GROUP BY.
That’s where the name “MergeTree” comes from: the parts are merged into a tree with levels 0 → 1 → 2 … We’ll write the code quickly and clean it up later. lab, Section 4: 10 parts → 1.