Skip to content
IT glossary
DatabasesUpdated December 3, 2026

ClickHouse

An analytical SQL database that stores values by column. It is designed to summarize large datasets such as application logs, usage events, and metrics without reading fields the query does not need.

What ClickHouse is for

ClickHouse is a column-oriented database built for online analytical processing (OLAP). Think of the difference between updating one order and calculating an hourly sales breakdown across millions of orders. The first task is a transaction on a small set of records; the second is an analytical query that scans and summarizes many records. A team might keep orders in PostgreSQL and send a copy of order events to ClickHouse for reporting.

What makes a scan efficient?

Storing each column together lets the database read just the fields a query needs. For a dashboard that counts requests by status code, ClickHouse can leave request bodies unread. Values of the same type tend to compress well, and processing batches of values reduces the overhead of handling one row at a time.

With the common MergeTree table engine, inserts create data parts that are merged in the background. Each part is sorted by the table's ORDER BY key. A sparse primary index stores key values at intervals rather than indexing every row. When a filter lines up with the leading columns of the key, ClickHouse can often rule out whole ranges before reading them. That is different from using a unique index to locate an individual record.

Example: count recent HTTP responses

CREATE TABLE requests (
    service String,
    ts DateTime,
    status UInt16,
    path String
) ENGINE = MergeTree
ORDER BY (service, ts);

SELECT status, count() AS total
FROM requests
WHERE service = 'checkout'
  AND ts >= now() - INTERVAL 1 HOUR
GROUP BY status
ORDER BY total DESC;

The table is laid out to make a time-range scan within one service efficient. The query reads the service, timestamp, and status fields, but not the path. The two ORDER BY clauses have different jobs: one sets the storage order within each part; the other sorts the report.

Where it fits and what can go wrong

ClickHouse works well for log exploration, product analytics, and dashboards over fresh event data. Batch inserts are generally preferable to a stream of single-row inserts, which can leave the database managing many small parts. Updates and deletes are possible, but frequent edits to individual records are not the usual reason to choose MergeTree. Its primary key does not reject duplicates.

How it comes up in interviews

Expect to justify a sort key using actual query patterns. In the example, (service, ts) is a good fit when queries typically name a service. If the busiest dashboard instead reads a short time window across every service, putting ts first may be a better fit. Be ready to distinguish sorting from partitioning: partitioning by month can make old data easy to drop in bulk, but it does not replace the sort key for narrowing a scan within a month.