Overview
Firebolt allows users to specify a custom compression algorithm at both the table level and the column level when creating a table. Compression helps you reduce storage costs and improve query performance by decreasing disk usage and I/O.Supported compression algorithms
Firebolt supports the following compression algorithms:Disabling compression with
NONE is not supported. Firebolt always compresses data using one of the supported algorithms.LZ4
Fast lossless compression algorithm optimized for speed over compression ratio. This is the default compression codec in Firebolt. Performance characteristics:- Compression speed: Very fast
- Decompression speed: Very fast
- Typical compression ratio: Good
- CPU usage: Very low
- High-throughput data ingestion
- Frequently accessed data requiring fast queries
- Real-time analytics workloads
- When CPU resources are limited
ZSTD (Zstandard)
Modern compression algorithm providing excellent balance between compression ratio and speed with configurable compression levels. Parameters:COMPRESSION_LEVEL: Compression level (1-22, default: 1)- Levels 1-3: Fast compression, good for online workloads
- Levels 4-10: Balanced performance
- Levels 11-22: High compression, slower writes
| Level | Compression Speed | Compression Ratio | Use Case |
|---|---|---|---|
| 1 | Fast | Good | Real-time data |
| 3 | Fast | Better | General workloads |
| 7 | Moderate | Better | Balanced storage/speed |
| 15 | Slow | Excellent | Archival data |
ZSTD compression levels higher than 3 typically reach the point of diminishing returns for most workloads.
- General analytics workloads (levels 1-3)
- Archival data storage (levels 10+)
- Data with good compressibility (JSON, text, logs)
Specify compression settings
You can specify compression settings for a table, columns, or a combination of both when creating tables:- Table-level compression sets a default compression method for all columns.
- Column-level compression overrides the table-level default for individual columns.
Table-level compression
You specify table-level compression using theWITH clause in the CREATE TABLE statement. This compression applies to all columns unless explicitly overridden at the column level.
Syntax:
Use the following syntax to set table-level and/or column-level compression.Compression level
- The optional
COMPRESSION_LEVELparameter lets you fine-tune the balance between compression ratio and CPU usage. - Higher compression levels provide greater compression but increase CPU overhead.
- Firebolt applies algorithm-specific default levels if no level is specified.
Default behavior
- If you don’t specify column-level compression, Firebolt applies the table-level setting.
- If no table-level setting is provided, Firebolt defaults to
lz4.
Example
The following code creates a table with ZTSD compression:Column-level compression
Column-level compression allows you to override table-level compression settings for specific columns. This approach is useful for columns that have different compression requirements, such as large text fields or numerical columns.Syntax:
Compression level
- The
compression_levelparameter fine-tunes compression efficiency versus CPU usage. - Higher compresson levels reduce storage but consume more CPU resources during compression and decompression.
- If not specified, Firebolt applies a default compression level appropriate for the selected algorithm.
Default behavior
- If you do not specify compression explicitly, Firebolt applies the default
lz4compression algorithm. - When you define table-level compression, all columns inherit this setting unless overridden with column-level compression.
Step-by-step example
The following example shows how to use table-level and column-level compression in Firebolt. Step 1: Create and populate table with default compression Create a base table without custom compression and insert 10000 identical rows into it.This example uses ZSTD with compression level 1. You can use a higher compression level to achieve better compression at the cost of increased CPU usage.
However, ZSTD compression levels higher than 3 typically reach the point of diminishing returns.
table_default_compression table:
| table_name | compression_ratio | compressed_bytes |
|---|---|---|
| table_c_column_zstd1 | 449.4 | 2559 |
| table_c_d_column_zstd1 | 1505.2 | 764 |
| table_default_compression | 241 | 4772 |
| table_zstd1 | 2948.7 | 780 |