Skip to main content
BRILLIQS

ClickHouse

A column oriented database management system that answers analytical SQL queries over very large tables.

ClickHouse is an open source database management system built for analytical queries. It stores data by column rather than by row, compresses each column and processes values in batches rather than one at a time. It uses SQL, and is available both as software you run yourself and as a managed cloud service.

What ClickHouse is

ClickHouse is a database management system built for one job: answering analytical questions over large amounts of data. It uses SQL, so the interface is familiar, but almost everything behind that interface is arranged differently from a transactional database.

Rows against columns

A transactional database stores a row together. That is the right choice when an application asks for one customer record and wants every field of it.

Analytical queries behave differently. They read millions of rows but usually only a handful of columns. Storing a table by column means those queries read only what they need, and the columns they ignore are never touched.

There is a second effect. Values within a column are similar to each other, and similar values compress well. Stored data ends up considerably smaller than the raw input, which reduces both storage cost and the amount that has to be read.

The ordering key does the heavy lifting

When you create a table with the MergeTree engine you specify an ordering key. This is the single most consequential decision in ClickHouse table design.

Rows are physically stored in that order, and the engine keeps a sparse index over it. When a query filters on the leading columns of the ordering key, whole ranges of data can be skipped without being read.

Choose it to match how the table will be queried and large scans become small ones. Choose it badly and the same query reads everything.

How writes work

An insert does not modify existing files. It creates a new part: a self contained piece of the table on disk.

Parts accumulate, so the engine merges them in the background, combining smaller parts into larger ones in the correct order. This is where the MergeTree name comes from, and it is why ClickHouse handles continuous inserts well while updates to existing rows are a different matter.

Updates and deletes

Changing rows that already exist is possible but is not the normal path. The documentation describes these operations as mutations, which rewrite the affected data rather than editing rows in place.

The practical consequence is that ClickHouse tables are usually designed so data is appended. Where a current value is needed from a stream of changes, engines within the MergeTree family exist that collapse or replace rows during merges.

Keeping aggregates current

Materialised views in ClickHouse are maintained as data is inserted. A view defined over a table receives new rows as they arrive and updates its own stored result.

This gives a way to keep summary tables current without scheduling a rebuild, which matters when the underlying table is large enough that recomputing it regularly would be impractical.

Who ClickHouse suits

ClickHouse suits teams querying very large event, log or metric tables, and product teams building analytics features that their own users query directly. It is used by engineers and analysts writing SQL, and operated by whoever owns the deployment.

What to be aware of

It is not a transactional database and does not try to be. Applications needing frequent small updates and strict transactional behaviour should use something built for that.

Table design also carries more weight here than in a general purpose database. The engine choice and the ordering key determine query performance to a degree that indexes on a conventional database do not, so those decisions are worth making carefully before loading data.

Getting started

The documentation includes a quick start that installs ClickHouse locally, creates a table and loads a sample data set. Separate sections cover table engines, the MergeTree family, materialised views, integrations and deployment.

Key features of ClickHouse

Capabilities described in the official documentation.

Column oriented storage

Each column is stored separately, so a query touching three columns of a wide table reads only those three.

The MergeTree engine family

Data is written as parts that are merged in the background, ordered by the key you choose when creating the table.

Vectorised execution

Values are processed in batches rather than row by row, which is how the engine gets through large scans.

Materialised views

A view can be maintained as new data is inserted, so aggregates are kept current without a scheduled rebuild.

Advantages of ClickHouse

Factual advantages that follow from the features above.

Storage costs less than raw size suggests

Similar values sit together in a column, which compresses well, so stored data is considerably smaller than the input.

Familiar query language

Queries are written in SQL, so existing knowledge applies and many client tools can connect directly.

Runs where you choose

The same engine can be deployed on your own machines or used as a managed service, so the choice is not fixed at the start.

Inserts do not interrupt reads

A write creates a new part rather than modifying existing files, so continuous loading does not block queries.

Common use cases for ClickHouse

Situations the official documentation describes this tool as being used for.

Digital analytics

Analytics on large event tables

Queries filter and aggregate billions of event rows by time and attribute for reporting and investigation.

Software products

Serving analytics inside a product

An application queries ClickHouse to show usage statistics to its own users without a separate reporting system.

Operations

Storing and querying logs

Log records are inserted continuously and queried by time range and field values when something needs investigating.

Business intelligence

Replacing a slow reporting query

A report that scanned a transactional database moves onto a table designed for the scan it performs.

Official website

Everything on this page is based on the official documentation for ClickHouse. You can read the source here.

ClickHouse official documentation

Frequently asked questions about ClickHouse

Answers taken from the official documentation for this tool.

No. It is designed for analytical queries that read many rows, not for the frequent small reads and writes an application makes. The documentation covers this distinction and lists the operations that behave differently from a transactional system.

They are not routine operations here. The documentation describes them as mutations, which rewrite affected data rather than changing rows in place. Tables are usually designed so that appending is the normal case.

It sets the order in which rows are stored on disk, which is what allows the engine to skip large ranges of data when a query filters on those columns. It is one of the most consequential choices when designing a ClickHouse table.

An insert creates a part, which is a self contained piece of the table on disk. The engine merges parts together in the background so that reads do not have to open an ever growing number of small files.