Real-time analytics
over large volumes of data.
ClickHouse is a columnar SQL database built for analytical processing. See, step by step, what happens when data arrives and how a query discards what it does not need before reading.
A database with columnar storage keeps the values of each column together, and a query reads only the columns it needs.
In TDP Kubernetes, ClickHouse is the columnar database for OLAP: complex calculations over large volumes of data, often in real time.
Columnar
Reads only the requested columns
The values of each column are stored together on disk. An analytical query reads only the columns it uses, not entire rows.
Lightweight inserts
Each INSERT becomes a part
Each insert writes a new, immutable part, with no synchronization with the others. The parts are merged later, in the background.
Less reading
Skip what does not matter
Indexes, partitions, and per-column compression let the query discard whole blocks of data before reading them.
On this page
- Watch an INSERT happen
- Architecture
- The path of a replicated table
- From table to granule
- By row or by column
- Why ClickHouse
- In the TDP editions
Watch an INSERT happen
Press Play or step through. The Keeper and the second replica come into play for replicated tables. Underlined names lead to the Glossary.
1 The INSERT reaches a replica
The application sends an INSERT to the table. On a replicated table, the insert can reach any replica: all of them accept writes.
In the Glossary: ReplicatedMergeTree table
- The INSERT reaches a replica. The application sends an INSERT to the table. On a replicated table, the insert can reach any replica: all of them accept writes.
- The rows are sorted. Before writing, ClickHouse sorts the rows by the sorting key and generates the sparse index, with one entry per granule, a group of rows.
- A part is born. The data is split by column, each column is compressed, and everything is written to a new directory: a part.
- The part is immutable. The part is immutable and self-contained, with no central catalog. A query sees the parts that exist at the moment it starts, and inserts are isolated from queries.
- The Keeper records the block. On a replicated table, the replica records the information about the inserted block in ClickHouse Keeper. The Keeper is what holds the replicas' metadata.
- The other replica fetches the copy. Coordinated by the Keeper, the other replicas fetch the copy of the part in the background. Only the compressed inserted data travels over the network, and the other replicas see the data with some latency.
- The parts are merged. In the background, merges combine parts of the same partition into a larger part. The original parts become inactive and are deleted later, and the level of the new part rises with each merge.
- The merge applies to all replicas. On a replicated table, merges are coordinated and performed the same way on all replicas.
Architecture
A ClickHouse cluster has one or more shards, and each shard can have replicas.
What the figure shows:
- The clients talk to the cluster through the HTTP interface, used by the Play UI, the Dashboard, and applications, or through the native protocol, used by clickhouse-client.
- The distributed table holds no data: it sends the query to the shards, which read in parallel, and combines the results.
- A shard holds a part of the data and splits the cluster load.
- Each replica of a shard is a ClickHouse server with a copy of the same data, and replication is defined per table, independent of sharding. Each replica has the same ReplicatedMergeTree table, whose data lives in parts combined by merges, and the replicas exchange copies of the parts.
- ClickHouse Keeper stores the metadata of the replicas and coordinates replication and distributed DDL. A ZooKeeper can also fill this role.
The path of a replicated table
Each replicated table has a path in ClickHouse Keeper, built with substitutions.
Click each part of the path.
Common prefix
The common beginning of the paths of replicated tables in ClickHouse Keeper.
See in the Glossary/clickhouse/tables— Common prefix- The common beginning of the paths of replicated tables in ClickHouse Keeper.
{shard}— Shard- Replaced by the shard identifier. Tables on different shards have different paths.
{database}— Database- Replaced by the name of the table's database.
{table}— Table- Replaced by the table name: it is the table's node in ClickHouse Keeper. The path in the Keeper does not change once created.
The path is the first argument of the engine, as in ReplicatedMergeTree('/clickhouse/tables/{shard}/{database}/{table}', '{replica}'), and it is unique for each replicated table.
The second argument is the name of the replica, which distinguishes the replicas of the same table and only needs to be unique within each shard.
The values between braces come from the macros section of the server configuration.
From table to granule
How a MergeTree table is organized on disk: four levels, each inside the other.
Level 1 of 4
MergeTree table
Engines of the MergeTree family accept fast inserts and process the data in the background. Only tables of this family can be replicated.
- Table engineDefines how data is written, stored, and read: which queries are supported, which indexes exist, and whether there is parallel execution and replication.
- MergeTree table. Engines of the MergeTree family accept fast inserts and process the data in the background. Only tables of this family can be replicated.
- Table engine. Defines how data is written, stored, and read: which queries are supported, which indexes exist, and whether there is parallel execution and replication.
- Partition. Groups the data by an expression declared in PARTITION BY, such as the month of a date. A query that filters by partition discards the others before reading.
- TTL. A rule that removes or moves data when it expires. With partitions, the TTL can drop entire partitions at once.
- Part. An immutable directory with a slice of the partition's data, sorted by the sorting key and with its own sparse index.
- Merge. Combines parts of the same partition into a larger part, in the background.
- Compressed columns. Inside the part, each column is stored and compressed separately.
- Granule. The smallest group of rows that ClickHouse reads. The sparse index has one entry per granule and therefore fits in memory.
- Mark. Each sparse index entry points, through a mark, to the start of a granule in the column files.
When reading, ClickHouse discards what it does not need before reading it.
The MinMax indexes of the partitions discard entire partitions, and the sparse index, by binary search, discards granules within each part.
Only the requested columns are read, and vectorized execution processes the data in batches, in parallel, usually one thread per processor core.
By row or by column
The same table, stored in two ways.
Row-oriented
For reading and writing a few rows
The values of a row are stored together. This is the model of transactional databases (OLTP), where each operation reads or writes a few rows.
Column-oriented
For analyzing many rows
The values of a column are stored together. An analytical query (OLAP) reads only the columns it uses, over large volumes of rows.
Why ClickHouse
Speed
Real-time analytics
Built for complex calculations over large volumes of data, often with real-time responses.
Inserts
Writes without waiting
Inserts do not need to synchronize with each other and are isolated from queries, at close to the disk's write speed.
Less reading
Indexes and partitions
Primary indexes, projections, and data skipping indexes discard data before reading.
Compression
Per-column codecs
Each column can use the codec suited to its data, such as ZSTD, Delta, or Gorilla.
Scale
More cores, more servers
Vectorized processing uses the cores of a server, and sharding distributes the data across multiple nodes. Replication is asynchronous and multi-master, with automatic or semi-automatic recovery.
SQL
SQL and access control
In many cases the SQL is identical to ANSI, with GROUP BY, JOIN, subqueries, and window functions. Role-based access control (RBAC) is also done in SQL.
ClickHouse began in 2009 as an experimental project by Alexey Milovidov and his team, to generate real-time analytical reports from non-aggregated data that also grows in real time. In 2012 it went into production on a web analytics platform and, in 2016, it became open source under the Apache 2 license.
In the TDP editions
| Edition | Version | Documentation |
|---|---|---|
| TDP Kubernetes | 25.8.11.66 · chart tdp-clickhouse 3.0.3 | Configuration in TDP Kubernetes |
In TDP Kubernetes
In TDP Kubernetes, ClickHouse is installed by the tdp-clickhouse chart, with the Altinity ClickHouse Operator, which creates and manages the cluster from a ClickHouseInstallation resource.
The Altinity ClickHouse Operator, an Operator, is installed once per cluster by the tdp-operator chart, a prerequisite of ClickHouse, and the CRDs come from tdp-crds. The operator embedded in the chart itself, at tdp-clickhouse.operator.enabled, is disabled by default.
Shards and replicas are defined in tdp-clickhouse.clickhouse.shardsCount and tdp-clickhouse.clickhouse.replicasCount. Replication requires ClickHouse Keeper, which can be enabled in tdp-clickhouse.keeper.enabled, and applies to tables of the Replicated* engines.
Enabled by default in tdp-clickhouse.clickhouse.persistence.enabled, with the size in tdp-clickhouse.clickhouse.persistence.size and the cluster's default StorageClass or the one defined in tdp-clickhouse.clickhouse.persistence.storageClass.
The cleanup Job, enabled by default in tdp-clickhouse.cleanup.enabled, removes the ClickHouseInstallation and the orphaned StatefulSets, Pods, and Services, and preserves the PersistentVolumeClaims.
With TDP-Settings.s3Connection.enabled, disabled by default, a Job creates the bucket and the access Secret. The S3 storage policy is declared in tdp-clickhouse.clickhouse.extraConfig.
The HTTP interface, with the Play UI and the Dashboard, and the native protocol are served by internal Services of the cluster. Ingress or Gateway API, one or the other, expose the HTTP interface, in TDP-Settings.gateway. The default user accepts only local connections, and tdp-clickhouse.clickhouse.extraUsers defines the users that access from outside.
The default user's password is set in tdp-clickhouse.clickhouse.defaultUser.password. The chart ships a temporary password (previously, the default user had no password), which is for testing only. LDAP and Active Directory can be configured in tdp-clickhouse.clickhouse.extraConfig, and LDAP login requires a role with permissions, defined by whoever administers ClickHouse. See ClickHouse security.
With tdp-clickhouse.clickhouse.tdpUser.enabled, disabled by default, the chart creates the tdpuser user, accepted from any host and with full privileges, through a post-install Job, for use by the platform's integrations. Applications and other Pods (Trino, Superset, CloudBeaver, OpenMetadata) must use this or another user, not default, which only accepts local connections.
Trino, through the clickhouse catalog in tdp-trino.catalogs; Superset, in tdp-superset.datasources.clickhouse; CloudBeaver, in tdp-cloudbeaver.dataSources; and OpenMetadata, in datasourcesIntegration.clickhouse of the tdp-openmetadata chart. Each integration is enabled in the chart of the component that connects. The Airflow image includes the clickhouse-connect and clickhouse-driver libraries.
A valid TDP license is required. See License configuration.
Next steps
Prerequisite
Operators Configuration
The chart that installs the Altinity ClickHouse Operator and Strimzi.
Architecture
TDP Kubernetes Architecture
Where ClickHouse sits among the components that process and query data.
Sources
ClickHouse - What is ClickHouse?
ClickHouse - Why is ClickHouse so fast?
ClickHouse - A practical introduction to primary indexes
ClickHouse - Distributed table engine