> ## 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_partitions_* 会话设置

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

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_partitions_per_insert_block">
  ## max\_partitions\_per\_insert\_block
</div>

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

限制单个插入块中的最大分区数；
如果该块包含过多分区，则会抛出异常。

* 正整数。
* `0` — 分区数量不受限制。

**详情**

插入数据时，ClickHouse 会计算插入块中的分区数。
如果分区数超过
`max_partitions_per_insert_block`，ClickHouse 会根据 `throw_on_max_partitions_per_insert_block`
记录警告日志或抛出异常。异常文本如下：

> "单个 INSERT 块中的分区过多 (`partitions_count` 个分区，限制为 " + toString(max\_partitions) + ") 。
> 此限制由 'max\_partitions\_per\_insert\_block' 设置控制。
> 大量分区是一种常见误区。这会对性能造成严重负面影响，
> 包括服务器启动缓慢、INSERT 查询变慢
> 以及 SELECT 查询变慢。对于一张表，建议的分区总数应
> 保持在 1000..10000 以下。请注意，分区的目的并不是加速
> SELECT 查询 (ORDER BY 键已足以让范围查询变快) 。
> 分区是用于数据操作的 (DROP PARTITION 等) 。"

<Note>
  此设置属于安全阈值，因为使用大量分区是一种常见误区。
</Note>

<div id="max_partitions_to_read">
  ## max\_partitions\_to\_read
</div>

<SettingsInfoBlock type="Int64" default_value="-1" />

限制单次查询可访问的最大分区数。

创建表时指定的该设置值可以通过查询级别的设置覆盖。

可能的值：

* 正整数
* `-1` - 不受限制 (默认)

<Note>
  你也可以在表的设置中指定 MergeTree 设置 [`max_partitions_to_read`](/zh/reference/settings/session-settings/max-partitions#max_partitions_to_read)。
</Note>
