Prompts Forms Resume Reports ★ Saved ★ Saved★ + Submit a tool
Tools and frameworks

ClickHouse Analytics

About 3934 characters Updated Nov 30, 2026 24 views AI wiki

ClickHouse is an open-source columnar analytical database, originally developed by Yandex for internal web analytics use cases. Its positioning is very clear: real-time aggregation queries over massive data, excelling at returning statistical results in sub-second to second time on detail data ranging from hundreds of millions to tens of billions of rows; it is not a general-purpose transactional database, nor a store designed for high-frequency point updates.

Core Principles

ClickHouse's fundamental advantage comes from columnar storage. Data is organized by column rather than by row, values in the same column are stored contiguously with a consistent type, compression ratios are high (commonly several times to more than ten times), and a query reads only the columns it involves, avoiding the waste of row storage where reading one row means moving the whole row. Combined with compression algorithms such as LZ4 and ZSTD, disk IO drops sharply.

Storage also uses LSM-style append-only writes: data is only appended and never rewritten, and background threads continuously merge parts, so write throughput is extremely high and a single machine can ingest millions of rows per second. This model of "append only, merge in the background" combined with columnar compression is the fundamental reason it can handle both real-time writes and complex analytics.

The second key is vectorized execution. Queries no longer process row by row but treat a column of data as an array, running loop operations on the CPU in batches, fully exploiting SIMD instructions and CPU caches and reducing the overhead of function calls and branch checks. Together with multi-threaded parallel scanning and multi-core parallel aggregation, single-machine throughput is very high.

As for storage engines, MergeTree is the core family. On write, data generates small immutable parts, which are merged into larger parts sorted by primary key in the background; the primary key index uses a sparse index plus data skipping indexes (such as min-max and bloom filters), greatly reducing the scan range. MergeTree has also spawned variants such as ReplacingMergeTree (deduplication), SummingMergeTree (pre-aggregation) and AggregatingMergeTree, as well as the Distributed table for distributed clusters.

Key Points

The sort key is the index: the ORDER BY at table creation determines the physical order of data and the primary key index, and the columns most often used for filtering should come first, which is the first task of performance tuning.

Not suitable for point updates: ClickHouse has no efficient row-level update or delete, and UPDATE and DELETE are heavyweight asynchronous mutations; frequent small-batch updates create heavy background merge pressure. The correct approach is to use ReplacingMergeTree with a version column for eventual consistency deduplication, or to append new versions.

Not suitable for transactions and high-concurrency point lookups: it has no complete multi-row transactions, single primary key lookups are far worse than an OLTP database, and it is also unsuitable for point lookup scenarios at thousands of QPS.

Selection judgment: it is the first choice for log analysis, event tracking statistics, metric dashboards and large-scale aggregation reports; do not use it for business databases that need transactions, state tables that need frequent updates, or low-frequency small-data scenarios.

Common Misconceptions

Using ClickHouse as an OLTP database for single-row queries and frequent updates, with dismal performance as a result. Setting ORDER BY carelessly or not sharding at table creation, which invalidates indexes and causes full table scans. Some people also assume it supports complex multi-table joins, when in fact large-table joins are very expensive and should be replaced as far as possible with wide tables and pre-aggregation.

In operations, replicas and shards also need attention: production environments usually configure two replicas plus multiple shards, using multiple replicas per shard for availability and then sharding by time or business dimension to expand capacity, so that single-machine disk and memory do not become bottlenecks. Materialized views can pre-aggregate on write, turning high-frequency report queries into reads of small tables.

Application Scenarios

Log analysis of websites and applications, user behavior event tracking statistics, real-time monitoring dashboards, advertising delivery reports, IoT time series aggregation, multi-dimensional analysis of business metrics, and storage of detail and summary layers in data warehouses.