What a sort key is worth — DuckDB against ClickHouse, on the same rows

The headline number is 8.5%: reordering the rows of our Parquet shards made them that much smaller, and put 99.9% of the visits in one piece. The more interesting number is where it does not work — the same key is worth 1.6% in DuckDB's own storage.

The measurement

One dataset for everything below: three sites, 45 days, 1 000 000 visits, 2 767 665 event rows, 56 columns, written by the product's own write path. Two engines, the same rows, the same machine — which is the only comparison that means anything.

Our storage has two tiers: the hot tier is DuckDB's own files (one per site, the last few days), and the cold tier is the older days, sealed into Parquet shards that DuckDB reads back in place. The same product also has a ClickHouse backend, so the same rows can go into two engines.

Here is the row that started this: on the scoreboard's tier (the one the product ships in — the address and the user agent hashed, the web vitals off), our DuckDB plus the cold tier was 55.7 MB and our ClickHouse was 50.9 MB.

The row we lost

DuckDB is usually the one that wins the "how big is it on disk" argument, so this was not what we expected — and not what we wanted either.

What was different

The sort key. Our Parquet shards were written ORDER BY created_at — the arrival order. ClickHouse's table was ordered by (website_id, day, session_start, visit_id): a key that puts one visit's rows next to each other.

So we were comparing a table with a good key against a table with none. The engine was never the variable.

We reordered the key to (day, visit_id, event_id): the day first (it is a fixed 86 400 seconds, so partitions and filters like it), then visit_id to group a visit together, then event_id to order inside it. Everything else stayed exactly as it was — same rows, same shape.

beforeafter
the Parquet shard19.1 bytes/row17.5 bytes/row (−8.5%)
the visits in one piece24.0% of the time99.9%
our DuckDB + cold tier55.7 MB50.6 MB
our ClickHouse50.9 MB50.9 MB

50.6 MB against 50.9 MB — the row flipped.

The control, which is the point

We wrote ClickHouse's own key with our own Parquet writer, on the same rows:

bytes/rowthe key
19.1created_at (ours, before)
17.5(day, visit_id, event_id)
17.5ClickHouse's own key, our writer
18.4ClickHouse's part

Two different keys, the same 17.5. The difference was never the format and never the engine — it was the key, and a key is the cheapest thing in a database to change.

Where the difference sits, column by column

The same round, per column (bytes a row):

columnour Parquet shardsClickHouse's partwe − CH
session_id2.875.28−2.41
page_title0.301.93−1.64
url_path0.301.52−1.23
lcp · inp · cls · fcp · ttfb0.00 each1.00 each−1.00 each
created_at3.572.28+1.29
event_id2.391.62+0.76
all the columns17.4028.31−10.91

Two different ClickHouse shapes appear in this post, and they are not the same one: the 50.9 MB in the row we lost is the schema shape we had then, and the column above is the product's current shape — the columns are nullable, and ClickHouse charges a byte a row for the null map. With that shape our ClickHouse is 80.0 MB against our 50.6 MB.

Two things to read out of it. ClickHouse's null map costs a byte a row on each of the five web vitals — they are empty in our traffic and it charges for them anyway (DuckDB's validity mask is nearly free). And our two most expensive columns are the timestamp and the event id — the two we already know how to make cheaper, and have not done yet.

The part we did not expect

The same ordering, applied to DuckDB's own storage, is worth 1.6% — not 8.5%.

bytes/rowthe visits in one piece
DuckDB's own file, one bulk write, arrival order30.524.0%
DuckDB's own file, one bulk write, the new key30.099.9%
DuckDB's own file, our production write path43.424.0%

The ordering did exactly what it was asked to do — the visits went from 24.0% contiguous to 99.9% — and the file got 1.6% smaller.

Why? DuckDB compresses each column per row group, with a mix of dictionaries, bit-packing and run-length encodings. Dictionaries and bit-packing do not reward adjacency — the same values compress the same whether they sit next to each other or are scattered across the file. Only the run-length-ish encodings do, and they are a minority of the columns.

What a DuckDB user should take from this

If your history is in Parquet — the usual DuckDB setup, Parquet on S3, Iceberg tables, a cold tier — the sort key is worth about 8%: put one entity's rows next to each other, and measure it. If your history is in DuckDB's own files, reordering buys ~1.6%; moving it to Parquet buys much more.

How to reproduce it

One experiment, four files, the same rows. The tool writes the rows three ways and measures each:

the filehow it is written
todaythe product's write path (the Appender, 5 000 rows at a time)
plainthe same rows, one bulk write, no ordering
orderedthe same rows, one bulk write, ordered by the new key

The cold tier's shards are written with the same key, in service/src/cold.rs — three places: the daily shard, the merged part, and the imported Iceberg table. A test guards it (the_shards_group_the_visits, with deliberately interleaved visits: it fails under the old order).

The raw output of the run is in the public repository's benchmarks/duckdb-vs-clickhouse-sort-key-2026-12-05/ folder — lose-scenario.txt (the two engines, the per-column table) and hot-order.txt (the three files, the block accounting and the batch sweep).

The boundaries of these numbers

  • One round, one machine (macOS/arm64), DuckDB 2.0.1 and ClickHouse 26.12.
  • The scoreboard's tier: the address and the user agent hashed, the web vitals off. That is the tier the product ships in — and the numbers are only comparable within a tier.
  • The files are DuckDB's own format, not Parquet, in the second table — which is the point of that table.
  • We did not establish which internal step frees the blocks (the appender's row-group handling, or the WAL checkpoint). We know that a rewrite gives them back and a bigger batch does not.

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.