
Unlock this content
Enter your email to unlock this content for free
When to Use Matviews
Materialized views solve three main use cases: data transformation (ELT pattern), aggregation for faster queries, and handling historical data. The main use case is aggregation. Use AggregatingMergeTree with AggregateFunction types for complex aggregations (averages, unique counts) or SummingMergeTree with SimpleAggregateFunction for simple sums. Materialized views only process new data; historical data requires backfilling.
Materialized views are insert triggers that transform and aggregate data as it arrives. They solve three main use cases: data transformation, aggregation, and historical data handling.
Use Case 1: Data Transformation (ELT)
Materialized views help transform data following the Extract, Load, Transform (ELT) pattern. Common tasks include parsing logs, processing JSON strings, filtering data, and routing data to different tables.
Example: Filter and Extract from JSON
-- Source datasource: analytics_events.datasource