> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-detect-table-modification.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# use_* MergeTree 表设置

> ClickHouse 在 use_* 自动生成组中的 MergeTree 表设置。

export const VersionHistory = ({rows = []}) => {
  if (rows.length === 0) {
    return null;
  }
  const headers = ["版本", "默认值", "注释"];
  const border = "1px solid rgba(128, 128, 128, 0.3)";
  const cell = {
    border,
    padding: "0.25rem 0.5rem",
    textAlign: "start",
    verticalAlign: "top"
  };
  return <details className="not-prose" style={{
    border,
    borderRadius: "0.5rem",
    margin: "0.5rem 0",
    padding: "0.5rem 0.75rem",
    fontSize: "0.8125rem",
    lineHeight: "1.125rem"
  }}>
      <summary style={{
    cursor: "pointer",
    fontWeight: 600,
    opacity: 0.72
  }}>
        版本历史
      </summary>
      <table style={{
    borderCollapse: "collapse",
    width: "100%",
    margin: "0.5rem 0 0"
  }}>
        <thead>
          <tr>
            {headers.map(header => <th key={header} style={{
    ...cell,
    fontWeight: 600,
    opacity: 0.72
  }}>
                {header}
              </th>)}
          </tr>
        </thead>
        <tbody>
          {rows.map((row, row_index) => <tr key={row.id ?? row_index}>
              {(row.items ?? []).map((item, item_index) => <td key={item_index} style={{
    ...cell,
    overflowWrap: "anywhere"
  }}>
                  {item?.label}
                </td>)}
            </tr>)}
        </tbody>
      </table>
    </details>;
};

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](/zh/reference/system-tables/merge_tree_settings) 中查看，且由 ClickHouse 源代码自动生成。

<div id="use_adaptive_write_buffer_for_dynamic_subcolumns">
  ## use\_adaptive\_write\_buffer\_for\_dynamic\_subcolumns
</div>

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

允许在写入 Dynamic 子列时使用自适应写入缓冲区，以
降低内存占用

<div id="use_async_block_ids_cache">
  ## use\_async\_block\_ids\_cache
</div>

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

已废弃，不起任何作用。

<div id="use_compact_variant_discriminators_serialization">
  ## use\_compact\_variant\_discriminators\_serialization
</div>

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

为 Variant
数据类型中判别值的二进制序列化启用紧凑模式。
当大多数情况下只有一种 Variant，或存在大量 NULL 值时，
此模式可显著减少在 parts 中存储判别值所需的内存。

<div id="use_const_adaptive_granularity">
  ## use\_const\_adaptive\_granularity
</div>

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

非常量自适应粒度 (默认设置，即 `index_granularity_bytes` 不为 `0`) 会使
粒度的字节大小保持恒定，因此行数会变化：对于每个
写入的块，每个粒度的行数为 `index_granularity_bytes` 除以该
块中行的平均大小，且不超过 `index_granularity`。由于各粒度的行数不同，
必须将parts中每个粒度的行数保存在
内存中，每个占用 8 字节；对于大型表，这些值累计可达数十 GB。

启用常量自适应粒度 (即此设置) 后，粒度的行数将保持恒定，
而字节大小会变化。该行数根据正在写入的parts中行的平均大小计算一次，
parts仅存储这一个值，
而非每个粒度存储一个值。由于所有粒度包含相同数量的行，
因此无需额外存储每个粒度的行数。

这些值当前占用的内存量可通过
`system.asynchronous_metrics` 中的 `TotalIndexGranularityBytesInMemory` 指标查看，
每个parts的值可通过 `system.parts.index_granularity_bytes_in_memory` 查看。

此设置仅应用于更改后写入的parts。使用
[ALTER TABLE ... REWRITE PARTS](/zh/reference/statements/alter/partition#rewrite-parts)
将其应用于现有parts。`Compact` parts始终使用自适应粒度。

<div id="use_metadata_cache">
  ## use\_metadata\_cache
</div>

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

已废弃，不起任何作用。

<div id="use_primary_key_cache">
  ## use\_primary\_key\_cache
</div>

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "24.12"},{"label": "0"},{"label": "新增设置"}]}]} />

使用缓存来存储主索引，
而不是将所有索引都保存在内存中。对于非常大的表，这可能很有用
