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

# max_partitions_* 会话设置

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

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

<div id="max_partitions_per_insert_block">
  ## max\_partitions\_per\_insert\_block
</div>

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "19.5"},{"label": "100"},{"label": "为单个块中的分区数量添加限制"}]}]} />

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

* 正整数。
* `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`](/docs/zh/reference/settings/session-settings/max-partitions#max_partitions_to_read)。
</Note>
