Model
Dictionary encoding: when it pays
When the dictionary grows, it becomes the main cost.
- Values
- values in the column
- Distinct values
- distinct values
- Value size
- average value size (bytes)
How it behaves
One input on the horizontal axis, the others held fixed.
Data table
| Distinct values k | Compression ratio |
|---|---|
| 2 | 160× |
| 2.36 | 80× |
| 2.78 | 80× |
| 3.27 | 80× |
| 3.85 | 80× |
| 4.54 | 53.3× |
| 5.35 | 53.3× |
| 6.31 | 53.3× |
| 7.43 | 53.3× |
| 8.75 | 40× |
| 10.3 | 40× |
| 12.2 | 40× |
| 14.3 | 40× |
| 16.9 | 32× |
| 19.9 | 32× |
| 23.4 | 32× |
| 27.6 | 32× |
| 32.5 | 26.6× |
| 38.3 | 26.6× |
| 45.1 | 26.6× |
| 53.2 | 26.6× |
| 62.7 | 26.6× |
| 73.8 | 22.8× |
| 87 | 22.8× |
| 102 | 22.8× |
| 121 | 22.8× |
| 142 | 19.9× |
| 168 | 19.9× |
| 198 | 19.9× |
| 233 | 19.9× |
| 274 | 17.7× |
| 323 | 17.7× |
| 381 | 17.7× |
| 449 | 17.6× |
| 529 | 15.9× |
| 623 | 15.8× |
| 734 | 15.8× |
| 865 | 15.8× |
| 1.02K | 15.7× |
| 1.2K | 14.3× |
| 1.41K | 14.3× |
| 1.67K | 14.2× |
| 1.96K | 14.1× |
| 2.31K | 12.9× |
| 2.73K | 12.9× |
| 3.21K | 12.8× |
| 3.78K | 12.7× |
| 4.46K | 11.7× |
| 5.25K | 11.6× |
| 6.19K | 11.4× |
| 7.29K | 11.3× |
| 8.59K | 10.4× |
| 10.1K | 10.2× |
| 11.9K | 10.1× |
| 14.1K | 9.85× |
| 16.6K | 9.07× |
| 19.5K | 8.83× |
| 23K | 8.57× |
| 27.1K | 8.28× |
| 31.9K | 7.96× |
| 37.6K | 7.27× |
| 44.3K | 6.93× |
| 52.2K | 6.57× |
| 61.5K | 6.19× |
| 72.5K | 5.6× |
| 85.4K | 5.22× |
| 101K | 4.83× |
| 119K | 4.45× |
| 140K | 3.97× |
| 165K | 3.61× |
| 194K | 3.26× |
| 228K | 2.93× |
| 269K | 2.58× |
| 317K | 2.29× |
| 374K | 2.03× |
| 440K | 1.79× |
| 519K | 1.57× |
| 611K | 1.36× |
| 720K | 1.18× |
| 849K | 1.03× |
| 1M | 0.889× |
Worked examples, recomputed
Every number the mechanisms quote for this relationship is recomputed from it, so none of them disagrees with it.
- k = 1,000 → about 1.27 MB against 20 MB (≈ 15×)
- k = 500,000 → about 12.4 MB (1.6×)
- 10 million 20-byte strings, 1,000 distinct → ≈ 16×
Where it appears
Each mechanism states it in its own names. The general symbol each name stands for is shown with it.
- Encoding, Serialization & Compression
What do we turn our values into when we turn them into bytes, and what does that choice cost?