Home / Companies / Tinybird / Blog / Post Details
Content Deep Dive

ClickHouse ® Tips #4: Materializing UNION ALL queries

Blog post from Tinybird

Post Details
Company
Date Published
Author
Elena Torro
Word Count
839
Language
English
Hacker News Points
-
Summary

The text discusses a method for materializing UNION ALL queries in ClickHouse® and Tinybird by creating two materialized views that write to the same table, utilizing the SimpleAggregateFunction data type. This approach, exemplified with Unsplash open data, circumvents the inability to directly materialize UNION ALL results by employing the AggregatingMergeTree engine. The process involves creating a destination table and two materialized views to store photo IDs, keywords, and collection details in a more efficient manner. The use of SimpleAggregateFunction allows for performance improvements and simpler queries compared to AggregateFunction, as it only stores the aggregate value rather than the full state, eliminating the need for -State and -Merge suffixes in queries. By structuring projects properly in Tinybird and using commands like tb push, the data can be joined and accessed rapidly, enhancing the speed of data retrieval by approximately six times compared to traditional methods.