Order is the lever on compression

The compression of a column store is decided by what sits next to what. That is why the order of the rows is a design decision, not an accident of the write path.

The principle

A column store compresses a column by looking at the values it holds. A dictionary, a bit-packing and a run-length encoding all reward values that are alike sitting close together.

So the order the rows are written in is part of the data's shape — and the key is the cheapest thing in a database to change. Nothing else in the design gives that much for so little.

The number

Our Parquet shards, same rows, same columns, only the key changed: 19.1 → 17.5 bytes a row (−8.5%), and the visits went from 24.0% to 99.9% sitting in one piece.

The same order, applied to DuckDB's own storage, is worth 1.6% — because its dictionaries and bit-packing do not reward adjacency, and only the run-length encodings do. So the lesson is format-specific: in Parquet the sort key is worth about 8%; in DuckDB's native files it is worth about 1.6%.

Where we use it

The cold tier's shards are written by (day, visit_id, event_id): the day first (it is a fixed number of seconds, so partitions and filters like it), then the visit (it groups one visit's rows), then the event (it orders them inside the visit). A test guards it.

The experiment report has the whole thing: the row we lost, the control, the per-column table and the part we did not expect.

Sumimi / 数咪咪 is an independent open-source project. It is an open-source alternative to Umami and implements the Umami v2 HTTP API; no Umami assets are used. Licensed under the Apache-2.0 licence. Third-party names are referenced nominatively.