Skip to main content

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.

This feature is only available starting from version 3.0.

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​

Press Play or step through. The Keeper and the second replica come into play for replicated tables. Underlined names lead to the Glossary.

ClientWho writes
ApplicationSends the INSERT
Replica 1Receives the INSERT
ReplicatedMergeTree tableReceives the rows
New partImmutable directory
MergeMerges parts in the background
ClickHouse KeeperWho coordinates
KeeperReplica metadata
Replica 2Fetches the copy
Same tableAnother replica of the shard
Part copyFetched in the background
Step 1 of 8

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.

  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.
  2. 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.
  3. A part is born. The data is split by column, each column is compressed, and everything is written to a new directory: a part.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. The merge applies to all replicas. On a replicated table, merges are coordinated and performed the same way on all replicas.
Figure 1 - An INSERT into a ReplicatedMergeTree table. Each insert becomes a part; the Keeper coordinates the replicas; merges combine the parts in the background.

Architecture​

A ClickHouse cluster has one or more shards, and each shard can have replicas.

ClickHouse architecture: clients, distributed table, shards with replicas and ClickHouse KeeperClients talk to the cluster through the HTTP interface or the native protocol. A distributed table, which does not store data of its own, sends the query to the shards and merges the results. Each shard has two replicas, each on a ClickHouse server with the same ReplicatedMergeTree table, whose data lives in parts combined by merges; the replicas exchange copies of the parts. ClickHouse Keeper, or a ZooKeeper, stores the replicas' metadata and coordinates the distributed DDL.HTTP interfacePlay UI, Dashboard and applicationsNative protocolclickhouse-clientClickHouse clusterDistributed tableStores no data: sends the query to the shards, which read in parallel, and merges the resultsShard 1Replica 1ClickHouse serverReplicatedMergeTreepartpartpartParts combinedby mergeReplica 2ClickHouse serverReplicatedMergeTreepartpartpartParts combinedby mergeReplicas exchange copies of partsShard 2Replica 1ClickHouse serverReplicatedMergeTreepartpartpartParts combinedby mergeReplica 2ClickHouse serverReplicatedMergeTreepartpartpartParts combinedby mergeReplicas exchange copies of partsClickHouse KeeperStores replica metadataand coordinatesthe distributed DDLKeeper nodeKeeper nodeKeeper nodeorZooKeeper
Figure 2 - ClickHouse architecture: clients, distributed table, shards with replicas, and ClickHouse Keeper. Underlined terms lead to the Glossary.

What the figure shows:

  1. 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.
  2. The distributed table holds no data: it sends the query to the shards, which read in parallel, and combines the results.
  3. A shard holds a part of the data and splits the cluster load.
  4. 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.
  5. 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.
  1. 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.
  2. 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.
  3. 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.
  4. 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.
Figure 3 - Organization of a MergeTree table: each level contains the next. The engine, the TTL, the merge, the columns, and the marks accompany each level.

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.

Where it comes from

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​

Available in the TDP editions
EditionVersionDocumentation
TDP Kubernetes25.8.11.66 · chart tdp-clickhouse 3.0.3Configuration 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.

Operator

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.

Topology

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.

Persistence

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.

Uninstallation

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.

S3 storage

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.

Access

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.

Authentication

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.

User for integrations

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.

What connects

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.

License

A valid TDP license is required. See License configuration.

Next steps​

Sources​

ClickHouse - What is ClickHouse?

ClickHouse - Why is ClickHouse so fast?

ClickHouse - Table parts

ClickHouse - Part merges

ClickHouse - Table partitions

ClickHouse - A practical introduction to primary indexes

ClickHouse - Data replication

ClickHouse - Distributed table engine

ClickHouse - Glossary

ClickHouse - ClickHouse Keeper

ClickHouse - History

Altinity ClickHouse Operator