跳转到主要内容

estimateCompressionRatio

Introduced in:v25.4.0 在不实际压缩给定列的情况下,估算其压缩率。
对于下面的示例,结果会因服务器默认的压缩编解码器不同而有所差异。 请参阅 列压缩编解码器
语法
estimateCompressionRatio([codec, block_size_bytes])(column)
参数
  • codec — 包含一个压缩编解码器,或多个以逗号分隔的编解码器的 String。String
  • block_size_bytes — 压缩数据的块大小。这类似于同时设置 max_compress_block_sizemin_compress_block_size。默认值为 1 MiB (1048576 字节) 。允许的最大值为 256 MiB (268435456 字节) 。UInt64
参数说明
  • column — 任意类型的列。Any
返回值 返回给定列的压缩率估计值。Float64 示例 默认编解码器的基本用法
Query
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
Response
┌───────────estimate─┐
│ 1.9988506608699999 │
└────────────────────┘
使用特定编解码器
Query
SELECT estimateCompressionRatio('T64')(number) AS estimate FROM compression_estimate_example
Response
┌──────────estimate─┐
│ 3.762758101688538 │
└───────────────────┘
使用多种编解码器
Query
SELECT estimateCompressionRatio('T64, ZSTD')(number) AS estimate FROM compression_estimate_example
Response
┌───────────estimate─┐
│ 143.60078980434392 │
└────────────────────┘
最后修改于 2026年6月10日