Learn

Dictionary Compression: Store Repeated Values Once

Dictionary encoding stores distinct values once and represents repeated occurrences with identifiers. The dictionary and identifiers together must be counted when evaluating space and correctness.

Separate the value from its occurrences

Imagine a dataset with a million rows but only a handful of status names. Repeating the full string in every row can duplicate information. A dictionary can assign each distinct value an identifier and store the sequence of identifiers alongside the dictionary.

Apache Parquet documents dictionary encoding for column chunks, including the dictionary page and integer identifiers. This is a concrete instance of the idea. Parquet dictionary encoding.

An original small example

Take the sequence pending, complete, pending, failed, complete, pending. Define a dictionary with 0 for pending, 1 for complete, and 2 for failed. The occurrence sequence becomes 0,1,0,2,1,0.

Decoding identifier 0 means looking up pending. The original order remains in the identifier sequence. Exact reconstruction also requires preserving the precise values: capitalization, spaces, and text encoding matter if the contract is byte-for-byte recovery.

To estimate storage, suppose the three UTF-8 strings use 7, 8, and 6 bytes. Their dictionary payload totals 21 bytes. If each identifier uses one byte, the six identifiers use six more. The original repeated strings use 43 bytes. Our simplified payload comparison is therefore 27 versus 43 bytes, before lengths, framing, and other metadata.

The omitted overhead is not free. A complete format must tell the decoder where values end, how the identifiers are represented, and which dictionary applies. For a tiny input, that metadata may erase the apparent saving. For many repeated occurrences, its cost can be spread over more rows.

Distinct-value count changes the result

If every value occurs only once, the dictionary stores essentially all original values plus a separate identifier sequence. That can increase size. If most values repeat frequently, the tradeoff can be favorable. The number of distinct values and their lengths both matter.

The identifier width also matters. Three possible identifiers fit in two bits in an ideal packed representation, but a simple implementation may use a full byte or a wider integer. Crossing an identifier-width boundary changes the accounting. Always measure the real representation instead of assuming the smallest mathematically possible code.

Not every dictionary method uses a fixed table

The term dictionary compression can also describe schemes that refer back to repeated byte sequences in previously seen data. DEFLATE, for example, uses length-and-distance references as part of its format rather than only a fixed table of complete status strings. DEFLATE specification.

These approaches share the goal of avoiding repeated literal information, but their lookup rules, supported patterns, and decoding costs differ. A comparison should name the exact format and configuration rather than treating “dictionary compression” as one uniform implementation.

Query and update implications

For a status filter, an engine might identify the relevant dictionary entry and compare identifiers. But the comparison is meaningful only within the correct dictionary. Identifier 1 in one block need not mean the same value as identifier 1 in another.

Updates can also add new values or require rebuilding a dictionary. These costs belong in the workload if the application changes data frequently. A compact immutable archive and an actively updated table may favor different choices.

Read entropy for probability and coding limits, and compressed-data queries for how representation affects computation. LuMATH’s computable-compression technical overview describes the separate evidence required for a technology-specific evaluation.