Wednesday, 12 August 2026

Core features of Clickhouse

  

1. True Column-Oriented Database Management System

A true columnar database like ClickHouse stores only the actual data values nothing else. It does not store additional information like the size of each value, or tags, or formatting per value.

 

For example, assume your orders table has a column called is_cancelled where values are just 0 (no) or 1 (yes). In a true columnar database like ClickHouse:

 

It stores these like a tight chain of 0s and 1s: 0, 1, 1, 1, 0, 1

 

For 1 billion orders, this takes exactly 1GB (since each 0/1 is 1 byte). No extra space is wasted storing metadata like "this is a number" or "the next value is 3 bytes long"

 

Other systems (like Cassandra) store each 0/1 with labels and metadata: {type:number, value:0, length:1}, {type:number, value:1, length:1}...

 

Making the same data 5-10x bigger.

 

2. Built in Data Compression

Imagine you have an orders table with millions of rows, storing all that data can take a lot of space. To solve this, ClickHouse compresses data, so it takes less space and runs faster.

 

ClickHouse doesn’t just use general compression (like ZIP or gzip). It uses special smart techniques (called codecs) depending on what kind of data is in each column. These codecs prepare data to be easily and more efficiently compressed.

 

2.1 Delta Codec

In this Algorithm, raw values are replaced by the difference of two neighboring values, except for the first value that stays unchanged.

 

For example,

order_id

Value

1000

 

1001

+1

1003

+2

1006

+3

 

Instead of storing 1000, 1001, 1003, 1006, it stores:

·      First value: 1000

·      Then: +1, +2, +3

 

Storing these small differences take less space.

2.2 DoubleDelta Codec

Calculates delta of deltas and writes it in compact binary form. Great for timestamps that increase evenly (like 10s, 20s, 30s, 40s). Instead of,

·      Differences: 10, 10, 10

·      Store that the difference between differences.

 

Imagine you have a sequence of numbers [2, 5, 7, 11, 13], let’s encode them using DoubleDelta.

 

Step 1: Store first value as it is.

first_vlaue = 2

 

Step 2: Calculate first level delta

Now, compute how much each number changes from the previous one.

 

Number

Previous

Delta

2

-

-

5

2

5 – 2 = 3

7

5

7 – 5 = 2

11

7

11 – 7 = 4

13

11

13 – 11 = 2

 

So, the deltas are: [3, 2, 4, 2]

 

Step 3: Calculate DoubleDeltas (Differences Between Deltas!)

Now, find how much the deltas themselves change:

 

Delta

Previous Delta

DoubleDelta (Current - Previous Delta)

3

-

- (No Previous Delta)

2

3

2 – 3 = -1

4

2

4 – 2 = 2

2

4

2 – 4 = -2

 

So, the DoubleDeltas are: [-1, +2, -2]

 

Step 4: Construct final values to store.

Combine everything:

 

·      First value (raw): 2

·      First delta (raw): 3

·      All DoubleDeltas: -1, +2, -2

 

Final encoded form: [2, 3, -1, 2, -2]. This is what gets stored instead of [2, 5, 7, 11, 13]

 

How to Decode Back to Original?

Let’s reverse the process.

 

·      Encoded data: [2, 3, -1, 2, -2]

·      First value = 2

 

First delta = 3, Next number = 2 + 3 = 5

Next DoubleDelta = -1, New delta = 3 + (-1) = 2, Next number = 5 + 2 = 7

Next DoubleDelta = 2, New delta = 2 + 2 = 4, Next number = 7 + 4 = 11

Next DoubleDelta = -2, New delta = 4 + (-2) = 2, Next number = 11 + 2 = 13

 

Final decoded result: [2, 5, 7, 11, 13]

 

Using Double Delta, instead of storing big numbers, we store smaller differences (easier to compress).

 

2.3 GCD Codec (Greatest Common Denominator)

Finds the biggest number that divides all values, and stores divided values instead.

 

For example, take the values [24, 28, 16, 8] instead of storing these values as it is, we calculate the GCD = 4, and store the values [6, 7, 4, 2] instead. These smaller numbers take less space while storing.

 

2.4 Gorilla Codec

Calculates XOR between current and previous floating point value and writes it in compact binary form.

 

Refer this link https://clickhouse.com/docs/sql-reference/statements/create/table#specialized-codecs to get more details about all the supported Codecs.

 

3. Disk Storage of Data

ClickHouse stores data on disk in a sorted order (based on the primary key you define). This allows ClickHouse to quickly skip over large chunks of data when scanning by ranges or specific values.

 

Unlike some other systems (e.g., SAP HANA, Google PowerDrill) that require everything to be loaded in RAM for speed. ClickHouse is designed to work efficiently from disk, making it much more cost-effective. You can still benefit from SSD and RAM if available, but it’s not a key requirement.

 

4. Parallel processing on Multiple Cores

ClickHouse automatically breaks down large queries and runs them in parallel across all available CPU cores on the server, making full use of the machine’s processing power.

 

5. Distributed Processing

ClickHouse supports fully distributed query processing across multiple servers. Data is partitioned into shards, each shard is replicated for fault tolerance. When you run a query, ClickHouse automatically processes it in parallel across all shards, making the distribution transparent to the user.

 

6. SQL Language Support

ClickHouse provides strong support for SQL, with syntax largely compatible with the ANSI SQL standard. It supports a wide range of commonly used SQL features, including:

 

·      GROUP BY, ORDER BY, and JOIN operations

·      Subqueries in the FROM clause

·      The IN operator and scalar subqueries

·      Window functions for advanced analytics

 

However, correlated subqueries (where the inner query depends on values from the outer query) are not currently supported, though future support is planned.

 

7. Vector Computation Engine

In ClickHouse, data is stored column by column (not row by row like in traditional databases). But it doesn’t stop there when it processes data, it doesn't look at one value at a time. Instead, it works with vectors, which are chunks of values from a single column (for example, 1,024 values at once).

 

By working on many values at once, ClickHouse can use the CPU more efficiently. This is like solving a whole group of math problems in one go instead of solving them one by one.

 

Many analytics queries scan large parts of columns (like summing sales or calculating averages). Vectorized processing makes these operations blazing fast.

 

8. Real-Time Data Inserts

ClickHouse lets you insert new data continuously and quickly, even while queries are running without locking the table.

 

ClickHouse uses something called a MergeTree engine, which automatically sorts the data by a ordering keys as it’s written. This helps:

 

·      Speed up queries that filter by order key ranges (e.g., dates, user IDs).

·      Avoid any locking, new data can be added without stopping reads or writes.

·      Handle real-time analytics and streaming data smoothly.

 

Physically sorting data by the order keys allows ClickHouse to retrieve specific values or ranges with very low latency, often in just a few milliseconds.

 

9. Secondary Indexes

Secondary Indexes in ClickHouse work differently from traditional databases. Instead of pointing to specific rows, they help the database skip over large chunks of data that don’t match the query. That’s why they’re called data skipping indexes. These indexes summarize information about data blocks and use it during queries to avoid reading unnecessary parts from disk, making queries faster and more efficient.

 

10. Designed for Real-Time, Quick Responses

Most OLAP (Online Analytical Processing) databases are okay with slow reports, taking tens of seconds, minutes, or even needing to prepare results ahead of time to avoid delays.

 

ClickHouse is different.

·      It’s built to handle complex analytical queries instantly, with sub-second query performance

·      No need to precompute or delay

·      Queries run live as users interact

 

So instead of saying “come back later for your report,” ClickHouse gets the answer right now, perfect for dashboards, analytics tools, and real-time user interfaces.

 

11. Approximated Calculations

ClickHouse offers ways to speed up your queries by allowing you to trade some accuracy for better performance. This is useful when you don’t need perfect precision but want to get results much faster.

 

You can use special approximate aggregate functions to quickly calculate things like

·      The number of distinct values (without calculating every single one exactly).

·      Medians and quantiles (without calculating them perfectly).

 

12. Data Replication and Data Integrity in ClickHouse

ClickHouse makes sure your data is safe and available by automatically copying it to multiple servers (called replicas). When data is written to one replica, the others get the same data in the background. All replicas end up with the same data in near future (Eventual Consistency). If something goes wrong like a server crash, ClickHouse can usually fix it on its own or with minimal help needed in complex scenarios.

 

 

References

https://clickhouse.com/docs/sql-reference/statements/create/table#specialized-codecs

https://clickhouse.com/docs/about-us/distinctive-features

Previous                                                    Next                                                    Home

No comments:

Post a Comment