
Unlock this content
Enter your email to unlock this content for free
Optimizing a Project with Materialized Views
TL;DR
To optimize a project with materialized views, identify slow aggregation queries and create materialized views using AggregatingMergeTree. Use *State() functions in the materialized view and *Merge() functions at query time. The performance improvement can be dramatic: reading thousands of pre-aggregated rows instead of billions of rows from the source table.
Example: calculate the count of events per action type from the analytics events table.
The Problem: Slow Aggregation Queries
Original query:
SELECT count()
FROM analytics_events
GROUP BY action