
Unlock this content
Enter your email to unlock this content for free
AggregatingMergeTree
TL;DR
AggregatingMergeTree stores aggregate function states (not final values) that merge incrementally. Use *State() functions when inserting and *Merge() functions when querying. Usually combined with materialized views.
How It Works
AggregatingMergeTree stores intermediate aggregate states (not final values) that merge incrementally during background merges and at query time. Use AggregateFunction types to define which aggregations to store.
-- Source table: raw session data
CREATE TABLE hits (
user_id UInt64,
duration UInt64
) ENGINE = MergeTree()
ORDER BY user_id;