Sobes.tech
Middle

Mis on partitsioon ClickHouse'is?

sobes.tech AI

Vastus AI-lt

In ClickHouse, a partition is a logical part of a table used for organizing and optimizing data storage. Partitioning allows splitting the table into separate segments based on a specific key (e.g., by date), which speeds up queries filtering data by this key and facilitates data management (e.g., deleting old partitions).

Partitions in ClickHouse are created based on an expression defined at table creation and typically correspond to ranges of values (e.g., month, day). This helps efficiently read and compress data, as well as perform TTL and cleanup operations.

Example of creating a table with monthly partitioning:

CREATE TABLE example (
    event_date Date,
    user_id UInt32,
    value Float32
) ENGINE = MergeTree()
PARTITION BY toYYYYMM(event_date)
ORDER BY (user_id);

Here, a partition is created for each month, allowing quick selection of data for a specific period.