clickhouse-materialized-views_skill

This skill helps you design and manage ClickHouse materialized views for real-time aggregation and data transformation, optimizing queries and avoiding common

9

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill obsessiondb/clickhouse-skills --skill clickhouse-materialized-views

  • SKILL.md13.3 KB

Overview

This skill provides 10+ proven patterns for ClickHouse Materialized Views (MVs) to build real-time aggregation, transformation, and query-optimization pipelines. It highlights which MergeTree engines to use—SummingMergeTree, AggregatingMergeTree, ReplacingMergeTree—and warns about common pitfalls like missing backfills and wrong ORDER BY choices. Practical examples and troubleshooting guidance help you design safe, performant MVs.

How this skill works

Materialized Views run the MV SELECT on each INSERT batch into the source table and write results into a target table; they do not read historical data. Use -State functions in MVs to store intermediate aggregate states and -Merge functions at query time to complete aggregation for AggregatingMergeTree. Choose SummingMergeTree for additive counters and AggregatingMergeTree for non-additive aggregates like uniq or quantiles.

When to use it

  • Create real-time counters and pre-aggregations to speed heavy queries
  • Parse or enrich incoming raw data for downstream consumers
  • Maintain latest-per-key state (last seen, last action) with ReplacingMergeTree
  • Build multi-level aggregation (hourly → daily) to reduce query cost
  • When queries are slow and data can be incrementally aggregated at insert time

Best practices

  • Treat MVs as INSERT-triggered processing, not caches of query results
  • Pick the correct engine: SummingMergeTree for sums/counts, AggregatingMergeTree for uniq/quantiles, ReplacingMergeTree for last-value
  • Match target ORDER BY to the MV GROUP BY for proper merges and space efficiency
  • Backfill historical data manually when adding an MV; MVs do not process existing rows
  • Avoid many MVs on a single source table to prevent insert latency; consider async or consolidated pipelines

Example use cases

  • Daily event counters using SummingMergeTree for fast dashboard metrics
  • Accurate unique user and p95 latency using AggregatingMergeTree with -State/-Merge
  • Parse JSON logs into structured tables on insert for simpler downstream queries
  • Track latest user state with ReplacingMergeTree and argMax patterns
  • Multi-level aggregation: hourly AggregatingMergeTree feeding daily AggregatingMergeTree for rollups

FAQ

No. Materialized Views only run on new INSERT batches. Backfill historical data by inserting aggregated results into the target table manually.

When should I use AggregatingMergeTree vs SummingMergeTree?

Use SummingMergeTree for pure additive metrics (sums, counters). Use AggregatingMergeTree when you need non-additive aggregates like uniq(), quantile(), or when accurate merging of state is required.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational