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

How to speed up ClickHouse queries using materialized columns

Blog post from PostHog

Post Details
Company
Date Published
Author
Karl-Aksel Puulmann
Word Count
945
Company Posts That Month
5
Language
-
Hacker News Points
-
Post removed?
No
Summary

ClickHouse's materialized columns offer a significant optimization opportunity for query performance by creating new columns derived from existing data, which can expedite queries that involve parsing JSON objects. In an example from PostHog, a schema was optimized by adding a materialized column for URLs, which reduced the need for JSON parsing and decreased the data read from disk. This approach demonstrated a remarkable speed improvement in querying pageviews by reducing execution time and disk read significantly. Although this method increases storage requirements, ClickHouse's compression capabilities make it an efficient trade-off, with substantial performance gains evident, especially when multiple property filters are applied. To efficiently backfill existing data without rewriting entire tables, the article suggests using default type columns before finalizing them as materialized, thus optimizing performance without disrupting existing processes. PostHog utilizes this technique selectively, focusing on properties that most frequently slow down queries, leading to an average query time improvement of 55 percent. This strategic use of materialized columns highlights the potential of ClickHouse in enhancing analytics capabilities across extensive datasets.

Trends Found in this Post

No tracked trend matches for this post yet.

Use This Data

Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.