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:lz4– Default option; fast compression and decompression, ideal for general workloads.zstd– Higher compression ratios at the cost of increased CPU usage; useful for large datasets.
Disabling compression with
NONE is not supported. Firebolt always compresses data using one of the supported algorithms.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 |