> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-parallel-read-in-order-multi-part.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# use_statistics_* 会话设置

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

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

## use\_statistics

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.1"},{"label": "1"},{"label": "默认启用此优化。"}]}]} />

/// 相较于 'allow\_statistics\_optimize'，更推荐使用此名称，因为它与 'use\_primary\_key' 和 'use\_skip\_indexes' 保持一致
允许使用统计信息优化查询

## use\_statistics\_cache

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.2"},{"label": "1"},{"label": "启用统计信息缓存"}]}, {"id": "row-2","items": [{"label": "25.11"},{"label": "0"},{"label": "新设置"}]}]} />

在查询中使用统计信息缓存，以避免为每个 parts 加载统计信息带来的额外开销

## use\_statistics\_for\_min\_max\_aggregation

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.9"},{"label": "1"},{"label": "新增设置：对于不含 `GROUP BY` 和过滤器的 `min`、`max` 和 `count` 聚合，可直接利用各 part 的列统计信息得出结果（仅限已 materialized 统计信息的 parts），其余 parts 才需读取数据。previous_value=false，因此将 `compatibility` 设置为 26.9 之前的版本时会禁用该优化，恢复原有的执行 plan。"}]}]} />

直接利用各 part 的列统计信息得出 `min`、`max` 和 `count` 聚合结果，而无需读取数据。

启用后，形如 `SELECT min(column), max(column), count() FROM table` 且不含 `GROUP BY` 和过滤器的查询，
对于已 materialized 列统计信息 (例如 MinMax 统计信息，参见 `auto_statistics_types` MergeTree 设置) 的数据 parts，
将直接由列统计信息得出结果，其余 parts 才会被读取。

可能的值：

* 0 — 禁用。
* 1 — 启用。

## use\_statistics\_for\_part\_pruning

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.4"},{"label": "1"},{"label": "在查询执行期间使用统计信息进行 part pruning 的新设置。"}]}]} />

在查询执行期间使用统计信息过滤 parts。

启用后，SELECT 查询中的 pruning 会使用列统计信息 (例如 MinMax 统计信息) ，在读取任何数据之前剔除不可能包含匹配数据的 parts。

可能的值：

* 0 — 已禁用。
* 1 — 已启用。
