Unlock this content

Enter your email to unlock this content for free

By continuing, you agree to our Terms of Service and Privacy Notice, and to receive occasional marketing emails.

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

Tinybird is not affiliated with, associated with, or sponsored by ClickHouse, Inc. ClickHouse® is a registered trademark of ClickHouse, Inc.

Optimizing a Project with Materialized Views | ClickHouse for Developers