2 · MERGETREE · INSERT RETRY
run
Insert retry
-- consumer не получил ответ и повторил INSERT;
-- в базе стенда оба INSERT уже выполнены:
-- INSERT INTO kills_raw VALUES (888, 1042, 9), (888, 2001, 4); ×2
SELECT sum(kills) FROM kills_total
WHERE player_id = 1042; -- 18, а не 9
-- *_dedup: SETTINGS non_replicated_deduplication_window = 100
-- на сырой таблице и на целевой таблице MV, те же два INSERT
SELECT sum(kills) FROM kills_total_dedup
WHERE player_id = 1042; -- 9
"At least once" delivery means duplicates.
Queues, HTTP retries, ETL restarts—the same batch will come through again.
Replicated tables store block hashes by default.
Regular MergeTree does not.
TRAP
WINDOW
MORE RELIABLE
Block hash, not a key
In both tables
Batch or Event ID
The same row in a batch of different content is a new block: the 9 is counted again (P6).
The raw table and the target MV table—both during the CREATE operation.
insert_deduplication_token = batch ID; or ReplacingMergeTree by event ID.
MV sums do not forgive retries. Design loading to be idempotent: a stable batch or event ID, like the idempotent purchase in Lesson 3. Lab, section 7.