Typorithm · medium

Column Types & Codecs

clickhouse-column-typesclickhouselow-cardinalitycodecsnullable
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Column Types & Codecs

0%

Columns & Engines

Pick types and codecs that fit the data: LowCardinality for few-distinct strings, DoubleDelta for timestamps, ZSTD for general compression.

ClickHouse compresses each column independently, so the type and codec dramatically affect size and speed.

LowCardinality dictionary-encodes columns with a small set of distinct values, like host or region.

Per-column CODECs such as DoubleDelta for monotonic timestamps and ZSTD for general data squeeze storage further.

01

LowCardinality for few-distinct strings.

02

DoubleDelta for timestamps, ZSTD general.

03

Nullable adds overhead — use sparingly.

CREATE TABLE metrics
(
    ts        DateTime CODEC(DoubleDelta, ZSTD),
    host      LowCardinality(String),
    region    LowCardinality(String),
    latency   Float64 CODEC(ZSTD),
    error     Nullable(String)
)
ENGINE = MergeTree
ORDER BY (host, ts);

Read the implementation

Connect each part of the code to the concept before you type.

1. Dictionary encoding

LowCardinality stores few-distinct strings as small integer codes.

host      LowCardinality(String)

2. Timestamp codec

DoubleDelta compresses near-monotonic timestamps before ZSTD.

DateTime CODEC(DoubleDelta, ZSTD)

3. Compressed metric

Per-column codecs tune compression to each column's data shape.

Float64 CODEC(ZSTD)

4. Nullable column

Nullable adds a null bitmap and some overhead; avoid on hot columns.

Nullable(String)

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

Column Types & Codecs: Lesson & Practice · Typorithm | ApplyDjinn