> ## 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.

# columns_cache_* 会话设置

> 自动生成的 columns_cache_* 分组中的 ClickHouse 会话设置。

export const BetaBadge = ({link, galaxyTrack, galaxyEvent}) => {
  if (link) {
    return <a href={link} target="_blank" rel="noopener noreferrer" className="betaBadge" onClick={galaxyTrack && galaxyEvent ? galaxyOnClick(galaxyEvent) : undefined}>
                <span>Beta</span>
            </a>;
  }
  return <a href="https://clickhouse.com/docs/reference/settings/beta-and-experimental-features#beta-features" className="betaBadge">
            <span>Beta 版功能</span>
        </a>;
};

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.settings](/docs/zh/reference/system-tables/settings) 中查看，均由[源代码](https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/Settings.cpp)自动生成。

<h2 id="columns_cache_max_bytes_to_write_to_cache">
  columns\_cache\_max\_bytes\_to\_write\_to\_cache
</h2>

<BetaBadge />

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.10"},{"label": "0"},{"label": "新增设置：单个查询写入列缓存字节数的软阈值；仅为建议性限制，实际写入量最多可能超出一个读取器在单个批次中写入的条目量（0 = 当前列缓存大小上限的一半，该上限在内存压力下会缩小）。"}]}]} />

单个查询写入列缓存字节数的软阈值。系统会统计查询期间写入的字节数，一旦计数达到该值，该查询其余部分的缓存写入都将被跳过。这是一个建议性阈值，而非硬性上限：读取器会累积已读取粒度的条目，再以一个批次统一写入缓存，而越过阈值的那个批次会先被完整存储，之后才计入计数。因此，实际写入量最多可能比该值多出一个读取器在两次写入之间累积的条目量 (即其读取的各列，每个 stripe 一个条目，每个 stripe 约 65536 行) ；若有多个读取器同时运行，则每个读取器都可能超出这么多。该设置旨在防止单次大型扫描把有用数据挤出缓存，而非精确限制缓存用量。

值为 `0` 表示使用列缓存当前大小上限的一半：即所配置的 `columns_cache_size`，若缓存因内存压力而缩小，则为更小的值 (参见 `ColumnsCacheSizeLimit` 指标) 。

<h2 id="columns_cache_max_estimated_bytes_to_write_to_cache">
  columns\_cache\_max\_estimated\_bytes\_to\_write\_to\_cache
</h2>

<BetaBadge />

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.10"},{"label": "0"},{"label": "新增设置：允许写入列缓存时，查询读取的估算未压缩字节数上限（0 = 当前列缓存大小限制的一半，该限制在内存压力下会缩小）。"}]}]} />

如果查询从 `MergeTree` parts 中读取的数据估算大小超过此值，则整个查询都不会写入列缓存。估算以未压缩字节为单位 (缓存也按此单位计费) ，根据查询所读取列 (包括 `PREWHERE` 列、变更列和补丁 part 列) 的大小，按所选标记范围折算得出；查询在读取任何数据之前，就会按全部估算量计费。这样既能防止单次大型扫描把有用数据挤出缓存，也能避免将无法留存在缓存中的数据复制进去。

值为 `0` 表示使用列缓存当前大小限制的一半。服务器内存充裕时，该限制即为所配置的 `columns_cache_size`；但在内存压力下缓存会缩小 (参见 `ColumnsCacheSizeLimit` 指标) ，默认预算也会随之缩小。在默认的 `columns_cache_size_ratio` 下，该限制的一半恰好等于缓存试用段的大小，因此通过该门槛的查询，其数据可以一次性完整写入缓存。

该门槛不适用于在运行过程中会丢弃标记范围的读取，启用 `use_indexes_refiner_in_read_pools` 时即属此类情况：此类读取实际会访问多少所选标记，要到切分每个任务时才能确定，因此上述估算只是一个上界，会把查询根本不会读取的标记也计算在内。对于这类读取，写入量改由 `columns_cache_max_bytes_to_write_to_cache` 限制。
