> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# primary_key_* MergeTree 表设置

> ClickHouse primary_key_* 自动生成分组中的 MergeTree 表设置。

export const SettingsInfoBlock = ({type, default_value, changeable_without_restart}) => {
  return <div className="not-prose" style={{
    display: "flex",
    flexWrap: "wrap",
    alignItems: "baseline",
    columnGap: "0.5rem",
    rowGap: "0.125rem",
    margin: "0.375rem 0",
    fontSize: "0.8125rem",
    lineHeight: "1.125rem"
  }}>
      <div style={{
    fontWeight: 600,
    opacity: 0.72
  }}>类型</div>
      <div style={{
    overflowWrap: "anywhere"
  }}>{type}</div>
      <div style={{
    fontWeight: 600,
    opacity: 0.72,
    marginInlineStart: "0.5rem"
  }}>默认值</div>
      <div style={{
    overflowWrap: "anywhere"
  }}>{default_value}</div>
      {changeable_without_restart && <div style={{
    fontWeight: 600,
    opacity: 0.72,
    marginInlineStart: "0.5rem"
  }}>
          无需重启即可更改
        </div>}
      {changeable_without_restart && <div style={{
    overflowWrap: "anywhere"
  }}>
          {changeable_without_restart}
        </div>}
    </div>;
};

这些设置可在 [system.merge\_tree\_settings](/docs/zh/reference/system-tables/merge_tree_settings) 中查看，且由 ClickHouse 源代码自动生成。

<div id="primary_key_compress_block_size">
  ## primary\_key\_compress\_block\_size
</div>

<SettingsInfoBlock type="NonZeroUInt64" default_value="65536" />

主键压缩块大小，即压缩块的实际大小。

<div id="primary_key_compression_codec">
  ## primary\_key\_compression\_codec
</div>

<SettingsInfoBlock type="String" default_value="ZSTD(3)" />

用于主键的压缩编码。由于主键足够小且已缓存，因此默认压缩方式为 ZSTD(3)。

<div id="primary_key_lazy_load">
  ## primary\_key\_lazy\_load
</div>

<SettingsInfoBlock type="Bool" default_value="1" />

首次使用时才将主键加载到内存中，
而不是在表初始化时加载。如果表的数量很多，
这样可以节省内存。

<div id="primary_key_ratio_of_unique_prefix_values_to_skip_suffix_columns">
  ## primary\_key\_ratio\_of\_unique\_prefix\_values\_to\_skip\_suffix\_columns
</div>

<SettingsInfoBlock type="Float" default_value="0.9" />

如果数据分区片段中主键某一列的值变化比例至少达到该比率，则跳过将后续列加载到内存中。这样可以通过不加载主键中无用的列来节省内存使用量。
