Typorithm · medium

Compression Codecs

compression-codecsclickhousecodecsdeltacompression
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Compression Codecs

0%

Scale & Ops

Per-column CODEC choices: Delta/DoubleDelta for sequences, T64/Gorilla for floats, then ZSTD or LZ4 as the final compressor.

Each column can declare its own CODEC, a chain where an encoding transform precedes a general-purpose compressor.

Delta and DoubleDelta shrink monotonic sequences like timestamps and counters by storing differences instead of raw values.

Gorilla and T64 target floating-point series, and the chain ends with a general compressor — ZSTD for ratio, LZ4 for speed.

01

Delta/DoubleDelta for monotonic sequences.

02

Gorilla/T64 for floating-point series.

03

End the chain with ZSTD or LZ4.

CREATE TABLE metrics
(
    ts        DateTime CODEC(Delta, ZSTD),
    seq       UInt64   CODEC(DoubleDelta, ZSTD),
    latency   Float64  CODEC(Gorilla, ZSTD),
    payload   String   CODEC(ZSTD(3))
)
ENGINE = MergeTree
ORDER BY (ts);

Read the implementation

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

1. Delta then ZSTD

Delta stores differences between consecutive values, then ZSTD compresses the small deltas.

CODEC(Delta, ZSTD)

2. Sequence codec

DoubleDelta suits monotonic sequences whose gaps are near-constant, like counters.

CODEC(DoubleDelta, ZSTD)

3. Float codec

Gorilla (and T64) target floating-point series that drift slowly over time.

CODEC(Gorilla, ZSTD)

4. Final compressor

ZSTD(3) sets a higher compression level for the general-purpose final stage.

CODEC(ZSTD(3))

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.

Compression Codecs: Lesson & Practice · Typorithm | ApplyDjinn