
Unlock this content
Enter your email to unlock this content for free
MergeTree
TL;DR
MergeTree stores data in immutable parts with partitions and sorting keys. Background merges optimize reads. Choosing the right partition key (1-300 GB per partition) and sorting key (filtering columns first) is critical for performance.
How MergeTree Works
MergeTree stores data in parts on disk. Each insert creates new parts, and a background process periodically merges smaller parts into bigger parts for more efficient reads.
CREATE TABLE events (
event_date Date,
user_id UInt64,
event_type String
) ENGINE = MergeTree()