跳转到主内容
跳转到主内容

estimateCompressionRatio

estimateCompressionRatio

引入于:v25.4.0

在不压缩给定列的情况下估算其压缩比。

注意

对于下面的示例,结果会因服务器的默认压缩编解码器而有所不同。 参见 列压缩编解码器

语法

estimateCompressionRatio([codec, block_size_bytes])(column)

参数

  • codec — 包含一个压缩编解码器名称,或由逗号分隔的多个编解码器名称的字符串。String
  • block_size_bytes — 压缩数据的块大小。类似于同时设置 max_compress_block_sizemin_compress_block_size。默认值为 1 MiB (1048576 字节) 。允许的最大值为 256 MiB (268435456 字节) 。UInt64

参数说明

  • column — 任意类型的列。Any

返回值

返回指定列的压缩比估算值。Float64

示例

使用默认编解码器的基本用法

CREATE TABLE compression_estimate_example
(
    `number` UInt64
)
ENGINE = MergeTree()
ORDER BY number
SETTINGS min_bytes_for_wide_part = 0;

INSERT INTO compression_estimate_example
SELECT number FROM system.numbers LIMIT 100_000;

SELECT estimateCompressionRatio(number) AS estimate FROM compression_estimate_example
┌───────────estimate─┐
│ 1.9988506608699999 │
└────────────────────┘

使用指定编解码器

SELECT estimateCompressionRatio('T64')(number) AS estimate FROM compression_estimate_example
┌──────────estimate─┐
│ 3.762758101688538 │
└───────────────────┘

使用多个编解码器

SELECT estimateCompressionRatio('T64, ZSTD')(number) AS estimate FROM compression_estimate_example
┌───────────estimate─┐
│ 143.60078980434392 │
└────────────────────┘