
Unlock this content
Enter your email to unlock this content for free
ReplacingMergeTree
TL;DR
ReplacingMergeTree deduplicates rows by keeping the latest version based on a version column. Deduplication happens during background merges. Use FINAL at query time to force deduplication, but it has a performance cost.
How It Works
ReplacingMergeTree deduplicates rows based on the sorting key. When multiple rows have the same sorting key values, it keeps the one with the highest version column value.
CREATE TABLE users (
id UInt64,
name String,
updated_at DateTime
) ENGINE = ReplacingMergeTree(updated_at)
ORDER BY id;