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.
| before | after | |
|---|---|---|
| the Parquet shard | 19.1 bytes/row | 17.5 bytes/row (−8.5%) |
| the visits in one piece | 24.0% of the time | 99.9% |
| our DuckDB + cold tier | 55.7 MB | 50.6 MB |
| our ClickHouse | 50.9 MB | 50.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/row | the key |
|---|---|
| 19.1 | created_at (ours, before) |
| 17.5 | (day, visit_id, event_id) |
| 17.5 | ClickHouse's own key, our writer |
| 18.4 | ClickHouse'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):
| column | our Parquet shards | ClickHouse's part | we − CH |
|---|---|---|---|
session_id | 2.87 | 5.28 | −2.41 |
page_title | 0.30 | 1.93 | −1.64 |
url_path | 0.30 | 1.52 | −1.23 |
lcp · inp · cls · fcp · ttfb | 0.00 each | 1.00 each | −1.00 each |
created_at | 3.57 | 2.28 | +1.29 |
event_id | 2.39 | 1.62 | +0.76 |
| all the columns | 17.40 | 28.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/row | the visits in one piece | |
|---|---|---|
| DuckDB's own file, one bulk write, arrival order | 30.5 | 24.0% |
| DuckDB's own file, one bulk write, the new key | 30.0 | 99.9% |
| DuckDB's own file, our production write path | 43.4 | 24.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 file | how it is written |
|---|---|
| today | the product's write path (the Appender, 5 000 rows at a time) |
| plain | the same rows, one bulk write, no ordering |
| ordered | the 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.