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

# max_streams_* 会话设置

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

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)自动生成。

<div id="max_streams_for_files_processing_in_cluster_functions">
  ## max\_streams\_for\_files\_processing\_in\_cluster\_functions
</div>

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

如果该值不为 0，则限制 \*Cluster 表函数 中从文件读取数据的线程数。

<div id="max_streams_for_merge_tree_reading">
  ## max\_streams\_for\_merge\_tree\_reading
</div>

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

如果该值不为 0，则限制 MergeTree 表的读取流数量。

<div id="max_streams_for_union_step">
  ## max\_streams\_for\_union\_step
</div>

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

限制 `UNION` 步骤中同时活跃的数据流数量 (同时适用于 `UNION ALL` 和 `UNION DISTINCT`，因为 `UNION DISTINCT` 是通过先执行 `UNION ALL` 步骤，再执行 `DISTINCT` 步骤来实现的) 。当一个 `UNION` 查询包含很多子查询时，这些子查询会同时打开各自的读取缓冲区，导致内存占用与子查询数量成正比。此设置会插入 `Concat` 处理器来收窄管道，从而使同时活跃的流数量最多不超过该值，显著降低峰值内存占用。实际限制值为该值与 `max_threads * max_streams_for_union_step_to_max_threads_ratio` 中的较小者 (任一值为 0 都表示忽略该值) 。当两者都为 0 时，则不进行收窄。如果查询计划要求 `UNION` 的每个输出流都分别保持有序 (例如在 `UNION` 上应用按序读取优化时) ，也不会应用该限制；在这种情况下，保证排序正确性的优先次序更高，因此会跳过收窄。

<div id="max_streams_for_union_step_to_max_threads_ratio">
  ## max\_streams\_for\_union\_step\_to\_max\_threads\_ratio
</div>

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

该比率乘以 `max_threads` 后，决定 `UNION` 步骤中可同时活跃的流数量上限 (适用于 `UNION ALL` 和 `UNION DISTINCT`) 。实际限制值取该计算结果与 `max_streams_for_union_step` 两者中的较小值 (任一值为 0 表示忽略该项限制) 。例如，当 `max_threads = 8` 且该比率设为 1 时，最多会有 8 个流同时处于活跃状态。将其设为 0 可禁用基于该比率的限制。与 `max_streams_for_union_step` 一样，当查询计划要求 `UNION` 的每个输出流分别保持有序时，不会应用此限制。

<div id="max_streams_multiplier_for_merge_tables">
  ## max\_streams\_multiplier\_for\_merge\_tables
</div>

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

从 Merge table 读取时请求更多流。这些流会分散到 Merge table 使用的各个表上。这样可以让工作在线程之间分配得更均匀，尤其是在 Merge table 所使用的各个表大小不同时，效果更明显。

<div id="max_streams_to_max_threads_ratio">
  ## max\_streams\_to\_max\_threads\_ratio
</div>

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

允许源的数量多于线程数，以便在线程之间更均匀地分配工作。这里认为这是一种临时解决方案，因为未来可以让源的数量与线程数相等，同时让每个源动态选择自己可处理的可用工作。
