1. Dictionary encoding
LowCardinality stores few-distinct strings as small integer codes.
host LowCardinality(String)Typorithm · medium
Step 1 of 8 · intro card
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.
LowCardinality for few-distinct strings.
DoubleDelta for timestamps, ZSTD general.
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);Connect each part of the code to the concept before you type.
LowCardinality stores few-distinct strings as small integer codes.
host LowCardinality(String)DoubleDelta compresses near-monotonic timestamps before ZSTD.
DateTime CODEC(DoubleDelta, ZSTD)Per-column codecs tune compression to each column's data shape.
Float64 CODEC(ZSTD)Nullable adds a null bitmap and some overhead; avoid on hot columns.
Nullable(String)Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.