ClickHouse codecs for time series: why Gorilla spends 48 bits on a float and ALP needs 16

On 13 real time-series datasets Gorilla stores a double in 48.1 bits, ALP in 16.4. ClickHouse makes ALP GA in 26.11. Which codec fits which column, and why.

Ask how to compress time series in ClickHouse and you get the same answer from every guide: DoubleDelta for timestamps, Gorilla for float gauges, T64 for small integers, and ZSTD behind them. That advice dates from 2019, when these codecs arrived in ClickHouse 19.11. Since then ClickHouse has added more number codecs, among them FPC, ALP and PCO, and on 2026-11-07 it promoted ALP to generally available for 26.11. The ClickHouse codec reference now says plainly: “In most scenarios, ALP is the best codec ClickHouse offers for Float32 and Float64 columns.”

That raises a question the old guides never answer. Facebook’s Gorilla paper reports 1.37 bytes per data point. The ALP paper measured Gorilla’s float encoding at 48.1 bits per value on 13 real time-series datasets, barely better than storing the raw 64 bits. Both numbers are honest. This post explains why they disagree, what each codec actually writes, and which one to put on which column.

This is day 4 of a daily ClickHouse series. Yesterday’s post measured small inserts and the async_insert default; day 2 covered the default LZ4/ZSTD(3) codec. Today’s numbers all come from published sources: the papers, ClickHouse’s source code and pull requests, and other people’s measurements. Each one is linked, with the version it applies to.

0 bits16 bits32 bits48 bits64 bitsGorillaXORGorilla: 48.1 bits per value48.1ChimpXORChimp: 42.6 bits per value42.6PatasXORPatas: 30.9 bits per value30.9PDEdecimalPDE: 30.0 bits per value30.0Chimp128XORChimp128: 24.5 bits per value24.5ElfXOR + eraseElf: 18.2 bits per value18.2Zstd (level 3)general-purposeZstd (level 3): 17.2 bits per value17.2ALPdecimal → integerALP: 16.4 bits per value16.4
Average bits per value on the ALP paper's 13 time-series datasets (uncompressed: 64). Gorilla saves a quarter; ALP saves three quarters. Source: Afroozeh, Kuffó, Boncz, SIGMOD 2024, Table 4.

The short answer

Column Codec Why
Regular timestamps (DateTime, DateTime64) DoubleDelta, or Delta, ZSTD(1) A constant interval makes the delta of deltas 0, and 0 costs 1 bit
Counters that only go up DoubleDelta or Delta, ZSTD(1) Small, smooth steps
Integers in a small range (status codes, tenths of a degree) T64, ZSTD(1) Drops the high bits that are always zero
Floats that started life as decimals (prices, sensor readings, percentages) ALP, ZSTD(3) on 26.11+ Turns 21.3 back into the integer 213
Floats with full precision (coordinates, model outputs) ALP (it falls back to its RD variant) or plain ZSTD Nothing decimal to exploit
Values that repeat exactly most of the time Gorilla still does well, or ZSTD A repeat costs Gorilla 1 bit

The rest of the post is the reasoning behind each row.

Inside the codecs: what each one writes

All of these codecs run on one compressed block of one column at a time. A block holds 64 KiB to 1 MiB of uncompressed data (min_compress_block_size = 65536, max_compress_block_size = 1048576 by default in 26.10). The values reach the codec in the table’s ORDER BY order. That matters for everything below. A codec that relies on neighbouring values only works if neighbours are similar, and in a table sorted by (metric, ts) the column holds one series after another, with a jump at every series boundary.

DoubleDelta: one bit per regular timestamp

DoubleDelta stores the first value, then the first delta, then for every further value the delta of the delta: a[i] - 2·a[i-1] + a[i-2]. The ClickHouse implementation writes it with variable-length prefixes taken from the Gorilla paper and extended to 64-bit values:

Delta of delta Bits written
0 1 (0)
−62 to 63 9 (10 + sign + 6 bits)
−254 to 255 12 (110 + sign + 8 bits)
−2046 to 2047 16 (1110 + sign + 11 bits)
fits in 32 bits 37 (11110 + sign + 31 bits)
anything else 69 (11111 + sign + 63 bits)

A sensor that reports every 60 seconds produces deltas of 60, 60, 59, 61, so the deltas of deltas are 0, −1, 2: 1, 9 and 9 bits. Facebook found that about 96% of all timestamps in their monitoring system compressed to that single bit (Gorilla, VLDB 2015, section 4.1.1). The catch is the sort order. Each time the column moves to the next series, the delta of deltas is a jump of hours or days and costs 37 or 69 bits. Within one series of thousands of rows that cost hardly shows.

Delta does the first half of this work: it replaces each value with its difference from the previous one and leaves the compressing to whatever codec follows. ClickHouse rejects CODEC(Delta) on its own with “Compression codec Delta does not compress anything” (source). After Delta, a regular timestamp column becomes one number repeated over and over, which ZSTD compresses extremely well. Altinity’s 2019 test of these codecs reported ratios of “1:800+” for constant-step sequences with both Delta, ZSTD and DoubleDelta, ZSTD (Altinity). On real data, ClickHouse’s own NOAA weather schema study (about 1 billion rows) found DoubleDelta, ZSTD(1) the best codec for the date column, at 24.11 MiB.

Gorilla: XOR with the previous value

Gorilla XORs each float’s 64 bits with the previous value’s. If the two values are equal, the XOR is zero and costs 1 bit. If not, it stores the “meaningful” bits between the leading and trailing zeros of the XOR. When those bits fall inside the previous window, that costs 2 bits plus the window. Otherwise it costs 2 + 5 + 6 bits of header plus the bits themselves (ClickHouse source, paper section 4.1.2).

That works when neighbouring values share their high bits and their low bits. In the Gorilla paper, 51% of values were identical to the previous one (1 bit each), 30% fit the previous window at an average of 26.6 bits, and 19% needed a new window at 36.9 bits. The paper adds that “many data sources only store integers” in their system, and integers stored as doubles end in long runs of zero bits.

Decimal readings look completely different. The double closest to 21.3 is 0x1.54ccccccccccdp+4, and the one closest to 21.4 is 0x1.5666666666666p+4. In binary, both mantissas repeat a pattern all the way to the last bit, because 0.3 and 0.4 have no finite binary expansion. XOR them and 46 of the 64 bits are meaningful. I worked this through by hand on the 8-value series 21.3, 21.4, 21.4, 21.5, 21.3, 21.2, 21.4, 21.6 (plain arithmetic on the bit patterns, using Gorilla’s rules). Apart from the first value, the only cheap value is the single repeat. The others cost 50 to 61 bits each, 47.3 bits per value on average: almost exactly the 48.1 the ALP paper measured.

Gorilla: XOR each double with the one before21.321.4XOR46 meaningful bits + 13 header bits = 59 bits for one valueALP: find e so that round(v × 10^e) turns back into exactly v213001214010214010215011213001212000214010216100× 10− 212integers3 bits each
The same readings, two encodings. Decimals like 21.3 have endless binary mantissas, so their XOR is mostly ones; ALP turns them back into small integers. Worked out by hand from the published algorithms.

So the two headline numbers describe different data. 1.37 bytes per point (11 bits, timestamp and value together) is what you get when most values repeat or are integers. 48 bits is what you get with measurements written with one or two decimals, and much real data looks like that.

FPC: a better prediction, the same XOR

FPC (Burtscher and Ratanaworabhan, DCC 2007) predicts each value with two hash-table predictors, keeps the better guess, and XORs the real value with that guess instead of with the previous value. The ClickHouse docs say that for doubles it “is faster than Gorilla, for 32-bit values your mileage may vary”. It still ends in an XOR, though, so it runs into the same wall on decimal data. In the NOAA study, both Gorilla and FPC made the lat and lon columns bigger than plain ZSTD did.

T64: drop the bits nobody uses

T64 works only on integers. It records the minimum and maximum of the whole block, then takes 64 values at a time, transposes their 64×64 bit matrix and keeps only the bit planes the range needs: the high bits that are the same in every value are dropped (source). On data that is truly random below 1 billion, Altinity measured a size “close to 3,750,000 bytes (1,000,000*30/8)”, which means exactly 30 bits per value and nothing more. In the NOAA study, T64, ZSTD(1) was the best codec for most of the integer measurement columns (temperatures, precipitation, wind speed), cutting the largest ones by about 25%.

Note how NOAA stores temperatures: as Int16 tenths of a degree, not as floats. That choice is the idea behind ALP.

ALP: turn the float back into the decimal it came from

ALP (Afroozeh, Kuffó and Boncz, SIGMOD 2024) starts from the observation that most doubles in real datasets were written as decimals. For each vector of 1,024 values it searches for a pair of exponents e and f. With them it computes d = round(n · 10^e · 10^-f) and checks that converting back gives exactly the same bits. If it does, the value is stored as the integer d. 21.3 becomes 213 with e = 1. The integers then go through frame-of-reference encoding and bit-packing: subtract the vector’s minimum and keep only as many bits as the range needs. Values that don’t round-trip are stored raw as exceptions.

My 8 readings become 213, 214, 214, 215, 213, 212, 214, 216: a minimum of 212 and a range of 4, so 3 bits per value. ClickHouse’s implementation also adds a 13-byte header per 1,024-value block (source), about 0.1 bit per value. For doubles that are not decimals, such as coordinates with 15 or more significant digits, ALP switches to a second scheme, ALP_RD. It splits each value into a left part, which goes into a small dictionary (up to 8 entries in ClickHouse), and a right part, which is bit-packed. ALP() (ALP(AUTO)) estimates both on a sample and picks the smaller.

The numbers, from the ALP paper

The ALP paper compares eight schemes on 30 datasets, 13 of them time series, and reports bits per 64-bit value (Table 4; lower is better). I picked out the time-series rows that look like typical ClickHouse metric columns:

Dataset (time series) Gorilla Chimp128 Elf ALP Zstd (level 3)
City-Temp 59.7 23.0 15.1 10.7 16.2
Stocks-USA 37.7 12.2 8.8 7.9 7.8
Basel-Wind 63.2 38.4 34.5 29.8 14.6
Bitcoin price 51.5 45.1 31.9 26.4 49.9
PM10 dust 27.7 13.7 7.1 8.2 6.9
Average of 13 time series 48.1 24.5 18.2 16.4 17.2
Average of all 30 datasets 42.2 28.7 23.1 21.7 20.6

Three things stand out:

  • On decimal-born time series, ALP takes about a third of Gorilla’s space (16.4 vs 48.1 bits), and also beats Zstd on its own, which no other float codec in the paper does.
  • Zstd wins wherever exact repeats or long runs dominate (Basel-Wind, the Gov/* datasets), and it is slightly ahead across all 30 datasets. When the authors put a dictionary or RLE step in front of ALP (the paper’s “LWC+ALP” column), ALP beats Zstd overall too: 18.8 vs 20.6 bits. ClickHouse gets a similar effect by putting ZSTD after ALP; more on that below.
  • ALP is not always the smallest, but its worst case is mild. The paper reports that ALP beats Chimp128 on 27 of the 30 datasets.

Speed is where it pulls far ahead. The paper measures tuples per CPU cycle on a single core with the data in L1 cache (Intel Ice Lake, Table 5):

Scheme Compression (tuples/cycle) Decompression (tuples/cycle) ALP faster at decompression by
ALP 0.487 2.609 –
PDE 0.002 0.387 7×
Patas 0.060 0.157 17×
Zstd 0.035 0.101 26×
Gorilla 0.052 0.047 55×
Chimp128 0.040 0.040 65×
Elf 0.010 0.012 215×
0.010.1110ALPALP: 2.609 values decoded per CPU cycle2.609PDEPDE: 0.387 values decoded per CPU cycle0.387PatasPatas: 0.157 values decoded per CPU cycle0.157ZstdZstd: 0.101 values decoded per CPU cycle0.101GorillaGorilla: 0.047 values decoded per CPU cycle0.047Chimp128Chimp128: 0.04 values decoded per CPU cycle0.040ElfElf: 0.012 values decoded per CPU cycle0.012
Values decompressed per CPU cycle, averaged over 30 datasets, data in L1 cache, Intel Ice Lake (ALP paper, Table 5). Log scale: ALP decodes 55× faster than Gorilla.

Gorilla decodes slowly for a structural reason, as the authors explain: every value depends on the one before it, and the branchy prefix decoding stalls the CPU. ALP decodes 1,024 independent integers with one loop that the compiler vectorizes. These are micro-benchmark numbers on cached data. In a real query, disk, page cache and the rest of the pipeline also take time, so expect a smaller gap.

What ClickHouse measured on its own data

Two ClickHouse pull requests include measurements on real ClickHouse tables, so they are closer to what you would see:

  • The TimeSeries table engine (the storage behind ClickHouse’s Prometheus support) switched its value columns to CODEC(ALP, ZSTD(3)) and its timestamps to CODEC(Delta, T64, ZSTD(3)) in 26.10. On 413,232 series and 71.4 billion samples over 30 days, the main value column shrank from 27.38 GB to 7.80 GB (−71.5%), and all of the engine’s tables together by 9.0%. Queries reading those samples got 3–4% faster (geometric mean). One exception: the small “recent samples” table grew by 81% on the value column. The PR reports it without explaining it.
  • Adaptive codec selection (enable_adaptive_codec_selection, an off-by-default MergeTree setting that tries several codecs per block during merges and keeps the smallest) added ALP to its candidates in 26.9. On TPC-H SF10 that made the lineitem columns 64.5% smaller on open-source ClickHouse, with 3× faster warm reads on one thread.

The same TimeSeries PR answers a practical question: is ZSTD after ALP still worth it? On a 120.3-million-row sample, ZSTD cut the ALP-encoded values from 87.8 MB to 13.8 MB. ALP removes the decimal structure; ZSTD then removes the repeats and patterns ALP does not look for. Hence ALP, ZSTD(3), not ALP on its own.

Which ALP you get depends on your version

ALP has changed a lot in a few months, and the version matters:

Version ALP status
26.3 Added as experimental, STD variant only (#91362)
26.7 RD variant and ALP(AUTO|STD|RD) (#99654)
26.8 Float32 scaling done in Float64: backward incompatible, columns written by earlier versions “may decode values 1 ulp away” (#111627)
26.9 Beta, needs SET enable_alp_codec = 1 (#116337)
26.10 Still beta (enable_alp_codec defaults to 0 in 26.10.2.103); used by the TimeSeries engine
26.11 GA, the setting becomes obsolete and defaults to 1 (#129732)

If you are on 26.9 or 26.10 and want it now:

SET enable_alp_codec = 1;

CREATE TABLE sensor_readings
(
    sensor_id   LowCardinality(String),
    ts          DateTime CODEC(DoubleDelta, ZSTD(1)),
    temperature Float64  CODEC(ALP, ZSTD(3)),
    humidity    Float32  CODEC(ALP, ZSTD(3)),
    error_count UInt32   CODEC(T64, ZSTD(1))
)
ENGINE = MergeTree
ORDER BY (sensor_id, ts);

-- what each column really costs, per row
SELECT name, compression_codec,
       formatReadableSize(data_compressed_bytes) AS on_disk,
       round(data_compressed_bytes * 8 / (SELECT count() FROM sensor_readings), 2) AS bits_per_row
FROM system.columns
WHERE database = currentDatabase() AND table = 'sensor_readings';

Two cautions. First, don’t put ALP on Float32 columns with a version before 26.8 if you plan to upgrade: the format changed. Second, ClickHouse tracks maturity per codec, so check what your build reports with SELECT name, tier FROM system.codecs. The tier column exists since 26.9.

Codec combinations ClickHouse refuses

The sanity checks save you from some of the classic mistakes. Unless you set allow_suspicious_codecs = 1, ClickHouse rejects:

  • Delta or GCD alone (“does not compress anything”).
  • Gorilla, FPC or ALP on a non-float column (“does not make sense to apply a floating-point time series codec to non-floating-point columns”).
  • Delta, Gorilla: “floating point time series codecs do delta compression implicitly by themselves”.
  • Anything after a general-purpose codec, such as ZSTD, Delta: general-purpose compression must come last (only encryption may follow it).

It does not stop DoubleDelta, ZSTD(3), which is often a little better than DoubleDelta alone, or Gorilla, ZSTD, which helps when Gorilla’s output still has patterns. Altinity found ZSTD adds little after DoubleDelta on clean sequences; on real data with series boundaries it usually helps. Check system.columns on a copy of your data rather than trusting any rule.

Next: PCO and FirstApplicable

Two newer pieces are worth knowing, but not yet for production:

  • PCO links the pcodec library (#110613). It is experimental in 26.10 and needs SET enable_pco_codec = 1. Note that the docs still say “beta”, but #127019 moved it to experimental for 26.10. It works on integers and floats alike. The pcodec paper reports a 29–94% higher compression ratio than the best alternative on six real datasets, and decompression above 1 GiB/s per thread. ClickHouse’s docs list the costs: encoding is “several times slower than ZSTD”, and constant or low-cardinality columns compress worse, because it has no run-length path.
  • FirstApplicable(...) (#128473, merged for 26.11) picks the first codec in its list that fits the column type. default_compression_codec = 'FirstApplicable(PCO, ZSTD(3))' gives every numeric column PCO and everything else ZSTD(3), without writing a CODEC clause per column.

I could not find any independent measurement of ClickHouse’s PCO against ALP on the same data yet. The comparisons in the PR and the paper come from the authors. I’ll come back to it when 26.11 is out.

FAQ

What is the best ClickHouse codec for timestamps? For regular intervals, DoubleDelta (optionally followed by ZSTD(1)), or Delta, ZSTD(1). A constant interval costs 1 bit per row with DoubleDelta. ClickHouse’s own TimeSeries engine uses Delta, T64, ZSTD(3).

Is Gorilla still a good codec for floats in ClickHouse? Only when values repeat exactly or are whole numbers. On decimal measurements it averages about 48 of 64 bits per value. On 26.11+ use ALP, ZSTD(3); on 26.9–26.10, enable it with enable_alp_codec = 1.

Should I add ZSTD after a specialized codec? Usually yes for ALP (ClickHouse measured 87.8 → 13.8 MB) and for Delta, which on its own compresses nothing. For DoubleDelta and Gorilla it depends on the data; compare in system.columns.

Why did Gorilla or FPC make my float column bigger? Because XOR-based codecs only win when neighbouring values share their low bits. Coordinates and decimal readings don’t, and generic ZSTD finds more. ClickHouse’s NOAA study saw exactly this on lat/lon.

Is it better to store prices as integers? If you control the schema, Decimal or a scaled integer with T64/Delta + ZSTD is still a clean choice. ALP gets most of that benefit automatically when the column has to stay Float64.

Sources

Tomorrow: LowCardinality vs String vs Enum, and where the break-even cardinality lies.