← Back to Glossary

Data compression

Data compression encodes data using fewer bits than its original representation, reducing storage footprint and the amount of I/O needed to read it.

Overview

Compression matters for databases for two reasons: it reduces how much disk (or cloud storage) a dataset consumes, and — often more importantly for analytical workloads — it reduces how many bytes have to be read from disk or over the network to answer a query. A well-compressed column can turn a multi-gigabyte scan into a fraction of that size.

General-Purpose vs. Lightweight Compression

General-purpose compressors like gzip or zstd work on arbitrary byte streams and can achieve high compression ratios, but decompressing them is relatively expensive per query. Analytical databases instead favor lightweight compression schemes that are cheap enough to decode on the fly, sometimes without fully materializing the decompressed value at all, so queries stay fast even against compressed data.

Common Techniques

  • Dictionary encoding — replace repeated values with small integer codes and a separate lookup table.
  • Run-length encoding (RLE) — store repeated runs as a (value, count) pair instead of repeating the value.
  • Bit packing — store integers using only as many bits as their actual range requires, rather than a fixed 4 or 8 bytes.
  • FSST — a string compression scheme that replaces frequent substrings with short codes, well suited to text columns.

DuckDB's Compression

DuckDB automatically chooses a lightweight compression scheme per column chunk — dictionary encoding, RLE, bit packing, constant encoding, or FSST for strings — based on which one fits that chunk's data best, with no configuration required. Because DuckDB can also read compressed Parquet files directly (typically Snappy or Zstd compressed) and push filters down into the reader, much of a query's I/O savings come before any DuckDB-specific compression is even applied.

Related terms

FAQS

No. DuckDB automatically selects the best lightweight compression scheme per column chunk (dictionary, RLE, bit packing, FSST, or constant encoding) based on the data, with no manual tuning needed.