What we wanted
Our event table has 56 columns: strings (paths, titles, referrers), UUIDs, timestamps, a handful of doubles, and some maps. We wanted to squeeze it, and DuckDB 2.0 has a per-column syntax that looks like exactly the right tool.
What the engine will actually write
The syntax is there. The list of what the engine accepts is much shorter:
| type | the methods the engine will write |
|---|---|
VARCHAR / BLOB | uncompressed · zstd — only these two |
TIMESTAMP / UUID / BIGINT / INTEGER | uncompressed · constant · rle · bitpacking |
DOUBLE / FLOAT | uncompressed · constant · rle · alp · alprd |
dictionary / fsst / chimp / patas are refused: "deprecated and only has decompress support" — they can be read, not written.
DICT_FSST — the automatic choice you see in the docs — cannot be written by hand. The engine picks it; you cannot ask for it.
51 columns, 51 losses
We wrote every column into its own file, once per method, and measured.
| column | the engine's own choice | the best a knob can give | the gap |
|---|---|---|---|
browser (VARCHAR) | 0.85 B/row | zstd 6.82 | 8.0× |
country (VARCHAR) | 0.85 B/row | zstd 6.82 | 8.0× |
url_path (VARCHAR) | 0.95 B/row | zstd 6.82 | 7.2× |
session_id (BLOB) | 4.93 B/row | zstd 9.00 | 1.8× |
created_at (TIMESTAMP) | 3.98 B/row | bitpacking 3.98 | even |
session_start (TIMESTAMP) | 4.74 B/row | bitpacking 4.74 | even |
visit_id (UUID) | 1.85 B/row | bitpacking 1.85 | even |
event_id (UUID) | 1.16 B/row | bitpacking 1.16 | even |
The explicit method never won once. (And zstd_min_string_length = 0 changes not one byte — when you force zstd, that threshold is not even looked at.)
The per-column compression knob is not a knob. It can only make things worse, or do nothing. The choice is the engine's, and it is a good one: its automatic pick on a string column is 8× smaller than the only alternative you may write.
The knob that does work: the unit
DuckDB's timestamp columns are bit-packed, and the width of a segment is the range inside it — so the unit is the lever, not the codec, and not the precision of the values.
2,767,665 rows:
| column | shape | B/row | the bits |
|---|---|---|---|
created_at | TIMESTAMP (microseconds) | 3.98 | 31.8 |
created_at | TIMESTAMP_MS | 2.65 | 21.2 |
created_at | TIMESTAMP_S | 1.14 | 9.1 |
created_at | TIMESTAMP, values truncated to ms | 3.98 | 31.8 |
created_at | TIMESTAMP, values truncated to s | 3.98 | 31.8 |
session_start | TIMESTAMP (microseconds) | 4.74 | 37.9 |
session_start | TIMESTAMP_MS | 3.13 | 25.0 |
session_start | TIMESTAMP_S | 2.37 | 18.9 |
Truncating the values saves nothing. Not to milliseconds, not to seconds — the width follows the range, not the jitter. only changing the unit saves anything. and it saves ten whole bits (microseconds to milliseconds). because that is a thousand-fold smaller interval.
TIMESTAMP_S is smaller still (9.1 bits) — but it throws the milliseconds away. We keep milliseconds, so TIMESTAMP_MS is the shape that fits that decision.
On the whole instance
The same traffic, the same write path:
| on the disk | really used | dead blocks | |
|---|---|---|---|
TIMESTAMP (microseconds) | 119.8 MB | 93.6 MB | 26.3 MB |
TIMESTAMP_MS (milliseconds) | 108.8 MB | 84.9 MB | 23.9 MB |
11.0 MB less on the disk (−9.2%), and the queries did not get slower (summary 67/70 ms against 66/62 ms, pages 7/7 against 7/6, sessions 25/24 against 24/22 — inside this machine's noise).
One correction
We had written down: "DuckDB's timestamp columns are fixed-width 8 bytes, so truncating to seconds does not change the width."
That is not true for DuckDB — they are bit-packed, the width is the range, and the unit is the lever. It is true for PostgreSQL and SQLite, which are fixed-width. The decision to keep milliseconds is unaffected: TIMESTAMP_MS is milliseconds. What changes is how it is stored — and it happens to line up with ClickHouse's DateTime64(3).
What we take away
- Do not fight the engine's compression choice. On 51 of 51 columns it was
the best available, and on a string column it was 8× better than the only alternative you are allowed to write.
- If your timestamps are big, change the unit, not the values. Truncating
the values buys exactly nothing; TIMESTAMP_MS against TIMESTAMP buys about a third of the column.
- **Check what the engine will actually write before you design around the
syntax.** dictionary, fsst, chimp and patas are read-only in 2.0.
Caveats
Our data (2,767,665 rows, 56 columns), DuckDB 2.0.1 on macOS/arm64, one machine. The methods we could write are the ones in the table above; we did not measure the read-only ones, because we cannot write them.
The numbers and the raw output are in the benchmarks folder of the public repository; the tools are private.