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

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

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>;
};

export const ExperimentalBadge = () => {
  return <div className="experimentalBadge">
            <div className="experimentalIcon">
            <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path strokeWidth="1.25" d="M5.5 2H10.5" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
                <path strokeWidth="1.25" d="M9.50015 2V6.19625L13.4283 12.7425C13.4738 12.8183 13.4985 12.9049 13.4996 12.9934C13.5008 13.0818 13.4785 13.169 13.435 13.246C13.3914 13.323 13.3283 13.3871 13.2519 13.4317C13.1755 13.4764 13.0886 13.4999 13.0002 13.5H3.00015C2.91164 13.5 2.8247 13.4766 2.74822 13.432C2.67174 13.3874 2.60847 13.3233 2.56487 13.2463C2.52126 13.1693 2.49889 13.082 2.50004 12.9935C2.50119 12.905 2.52582 12.8184 2.5714 12.7425L6.50015 6.19625V2" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
                <path strokeWidth="1.25" d="M4.47656 9.56754C5.30344 9.41254 6.47656 9.47942 7.99969 10.25C10.0153 11.2707 11.4216 11.0569 12.2184 10.7282" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
            </svg>
        </div>
            Experimental 功能。 <u><a href="/docs/docs/beta-and-experimental-features#experimental-features">了解详情。</a></u>
        </div>;
};

这些设置可在 [system.settings](/docs/zh/reference/system-tables/settings) 中查看，并由 [源代码](https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/Settings.cpp) 自动生成。

<div id="max_analyze_depth">
  ## max\_analyze\_depth
</div>

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

解释器执行分析的最大次数。

<div id="max_autoincrement_series">
  ## max\_autoincrement\_series
</div>

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "25.1"},{"label": "1000"},{"label": "新增设置"}]}]} />

`generateSerialID` 函数可创建的序列数量上限。

由于每个序列都对应 Keeper 中的一个节点，建议其数量不要超过几百万个。

<div id="max_backup_bandwidth">
  ## max\_backup\_bandwidth
</div>

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

服务器上特定备份的最大读取速度 (以每秒字节数计) 。0 表示不受限制。

<div id="max_block_size">
  ## max\_block\_size
</div>

<SettingsInfoBlock type="NonZeroUInt64" default_value="65409" />

在 ClickHouse 中，数据以块为单位进行处理，块由各列的数据片段组成。单个块的内部处理过程效率很高，但处理每个块时仍会产生明显的额外开销。

`max_block_size` 设置表示从表中加载数据时，单个块建议包含的最大行数。但从表中读取的块并不一定总是达到 `max_block_size`：如果 ClickHouse 判断只需检索较少的数据，就会处理更小的块。

块大小不应过小，以免处理每个块时的额外开销过于明显；也不应过大，以确保带有 LIMIT 子句的查询在处理完第一个块后能够快速返回结果。设置 `max_block_size` 时，目标应是避免在多线程提取大量列时占用过多内存，同时尽可能保持一定的缓存局部性。

<div id="max_columns_to_read">
  ## max\_columns\_to\_read
</div>

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

单次查询可从表中读取的最大列数。
如果查询需要读取的列数超过指定数量，
将抛出异常。

<Tip>
  此设置可用于防止查询过于复杂。
</Tip>

`0` 表示不受限制。

<div id="max_compress_block_size">
  ## max\_compress\_block\_size
</div>

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

写入表时，压缩前未压缩数据块的最大大小。默认值为 1,048,576 (1 MiB) 。指定较小的块大小通常会使压缩率略有下降；由于缓存局部性，压缩和解压速度会略有提升，同时还能减少内存消耗。

<Note>
  这是一个专家级设置；如果你刚开始使用 ClickHouse，不建议更改它。
</Note>

不要将用于压缩的块 (由字节组成的一段内存) 与用于查询处理的块 (表中的一组行) 混淆。

<div id="max_consume_snapshots">
  ## max\_consume\_snapshots
</div>

<ExperimentalBadge />

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.5"},{"label": "0"},{"label": "新设置。"}]}]} />

每次增量读取最多可消费的 Paimon 快照数量。0 表示不限制。

<div id="max_estimated_execution_time">
  ## max\_estimated\_execution\_time
</div>

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "24.1"},{"label": "0"},{"label": "将 max_execution_time 与 max_estimated_execution_time 分离"}]}]} />

查询预计的最大执行时间 (秒) 。当
[`timeout_before_checking_execution_speed`](/docs/zh/reference/settings/session-settings/other#timeout_before_checking_execution_speed)
超时后，会对每个数据块进行检查。

<div id="max_expanded_ast_elements">
  ## max\_expanded\_ast\_elements
</div>

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

别名和星号展开后，查询语法树可包含的最大节点数。

<div id="max_fetch_partition_retries_count">
  ## max\_fetch\_partition\_retries\_count
</div>

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

从另一台主机拉取分区时的重试次数。

<div id="max_final_threads">
  ## max\_final\_threads
</div>

<SettingsInfoBlock type="MaxThreads" default_value="auto(N)" />

设置带有 [FINAL](/docs/zh/reference/statements/select/from#final-modifier) 修饰符的 `SELECT` 查询在数据读取阶段可使用的最大并行线程数。

可能的值：

* 正整数。
* 0 或 1 — 禁用。`SELECT` 查询将以单线程执行。

<div id="max_http_get_redirects">
  ## max\_http\_get\_redirects
</div>

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

允许的 HTTP GET 重定向跳转最大次数。该设置可提供额外的安全保护，防止恶意服务器将你的请求重定向到意外的服务。\n\n这种情况会发生在：某个外部服务器重定向到另一个地址，而该地址看起来像是公司基础设施内部的地址。此时，如果向内部服务器发送 HTTP 请求，你可能会从内部网络访问内部 API，绕过身份验证，甚至查询其他服务，例如 Redis 或 Memcached。如果你没有内部基础设施 (包括在 localhost 上运行的内容) ，或者你信任该服务器，那么允许重定向是安全的。不过请记住，如果 URL 使用的是 HTTP 而不是 HTTPS，那么你不仅需要信任远程服务器，还需要信任你的 ISP 以及中间经过的每一层网络。

Cloud 默认值：`10`。

<div id="max_limit_for_vector_search_queries">
  ## max\_limit\_for\_vector\_search\_queries
</div>

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "25.5"},{"label": "1000"},{"label": "新增设置"}]}]} />

LIMIT 大于此设置值的 SELECT 查询将无法使用向量相似性索引。这有助于防止向量相似性索引出现内存溢出。

<div id="max_number_of_partitions_for_independent_aggregation">
  ## max\_number\_of\_partitions\_for\_independent\_aggregation
</div>

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

应用此优化时，表中允许的最大分区数

<div id="max_os_cpu_wait_time_ratio_to_throw">
  ## max\_os\_cpu\_wait\_time\_ratio\_to\_throw
</div>

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "25.5"},{"label": "0"},{"label": "设置值已更改，并回移到 25.4"}]}, {"id": "row-2","items": [{"label": "25.4"},{"label": "0"},{"label": "新增设置"}]}]} />

用于判定是否拒绝查询的最大比率，即 OS CPU 等待时间 (`OSCPUWaitMicroseconds` 指标) 与忙碌时间 (`OSCPUVirtualTimeMicroseconds` 指标) 之间的比率上限。概率通过最小比率与最大比率之间的线性插值计算；在该点处，概率为 1。

<div id="max_parallel_replicas">
  ## max\_parallel\_replicas
</div>

<SettingsInfoBlock type="NonZeroUInt64" default_value="1000" />

<VersionHistory rows={[{"id": "row-1","items": [{"label": "25.1"},{"label": "1000"},{"label": "默认最多使用 1000 个并行副本。"}]}]} />

执行查询时，每个分片可使用的最大副本数。

可能的值：

* 正整数。

**附加信息**

此选项在不同设置下会产生不同的结果。

<div id="parallel-processing-using-sample-key">
  ### 使用 `SAMPLE` 采样键进行并行处理
</div>

如果一个查询在多台服务器上并行执行，处理速度可能会更快。但在以下情况下，查询性能可能会下降：

* 采样键在分区键中的位置不利于高效的范围扫描。
* 向表中添加采样键会降低按其他列进行过滤的效率。
* 采样键是一个计算成本较高的表达式。
* 集群的延迟分布存在长尾，因此查询更多服务器会增加查询的整体延迟。

<div id="parallel-processing-using-parallel_replicas_custom_keyreferencesettingssession-settingsparallel-replicasparallel_replicas_custom_key">
  ### 使用 [parallel\_replicas\_custom\_key](/docs/zh/reference/settings/session-settings/parallel-replicas#parallel_replicas_custom_key) 实现并行处理
</div>

此设置适用于任何启用了复制的表。

<div id="max_parsing_threads">
  ## max\_parsing\_threads
</div>

<SettingsInfoBlock type="MaxThreads" default_value="auto(N)" />

<VersionHistory rows={[{"id": "row-1","items": [{"label": "24.4"},{"label": "0"},{"label": "新增单独的设置，用于控制从文件并行解析时的线程数"}]}]} />

在支持并行解析的输入格式中，用于解析数据的最大线程数。默认会自动确定。

<div id="max_partition_size_to_drop">
  ## max\_partition\_size\_to\_drop
</div>

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

对在查询时删除分区操作的限制。值 `0` 表示删除分区时不受任何限制。

Cloud 默认值：1 TB。

<Note>
  此查询设置会覆盖对应的服务器级设置，参见 [max\_partition\_size\_to\_drop](/docs/zh/reference/settings/server-settings/settings#max_partition_size_to_drop)
</Note>

<div id="max_parts_to_move">
  ## max\_parts\_to\_move
</div>

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "24.10"},{"label": "1000"},{"label": "新增设置"}]}]} />

限制单个查询中可移动的 parts 数量。0 表示不受限制。

<div id="max_projection_rows_to_use_projection_index">
  ## max\_projection\_rows\_to\_use\_projection\_index
</div>

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "25.11"},{"label": "1000000"},{"label": "新增设置"}]}]} />

如果需要从投影索引读取的行数小于或等于此阈值，ClickHouse 将在查询执行期间尝试使用该投影索引。

<div id="max_query_size">
  ## max\_query\_size
</div>

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

由 SQL 解析器解析的查询字符串的最大字节数。
INSERT 查询中 VALUES 子句里的数据由单独的 stream 解析器处理 (占用 O(1) RAM) ，不受此限制影响。

<Note>
  `max_query_size` 不能在 SQL 查询内部设置 (例如 `SELECT now() SETTINGS max_query_size=10000`) ，因为 ClickHouse 需要先分配一个缓冲区来解析查询，而该缓冲区的大小由 `max_query_size` 设置决定，因此必须在查询执行前完成配置。
</Note>

<div id="max_recursive_cte_evaluation_depth">
  ## max\_recursive\_cte\_evaluation\_depth
</div>

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "24.4"},{"label": "1000"},{"label": "递归 CTE 求值深度的最大限制"}]}]} />

递归 CTE 求值深度的最大限制

<div id="max_replica_delay_for_distributed_queries">
  ## max\_replica\_delay\_for\_distributed\_queries
</div>

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

在分布式查询中禁用存在延迟的副本。参见 [复制](/docs/zh/reference/engines/table-engines/mergetree-family/replication)。

设置一个以秒为单位的时间阈值。如果某个副本的延迟大于或等于该值，则不使用该副本。

可选值：

* 正整数。
* 0 — 不检查副本延迟。

要避免使用任何延迟非零的副本，请将此参数设为 1。

在对指向复制表的分布式表执行 `SELECT` 时使用。

<div id="max_reverse_dictionary_lookup_cache_size_bytes">
  ## max\_reverse\_dictionary\_lookup\_cache\_size\_bytes
</div>

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "25.12"},{"label": "104857600"},{"label": "新设置。函数 `dictGetKeys` 使用的每个查询反向字典查找缓存的最大字节数。该缓存会按每个属性值存储序列化后的键 Tuple，以避免在同一查询中重复扫描字典。"}]}]} />

函数 `dictGetKeys` 使用的每个查询反向字典查找缓存的最大字节数。该缓存会按每个属性值存储序列化后的键 Tuple，以避免在同一查询中重复扫描字典。达到限制后，缓存条目将按 LRU 策略被逐出。设置为 0 可禁用缓存。

<div id="max_sessions_for_user">
  ## max\_sessions\_for\_user
</div>

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

每个已通过身份验证的用户在 ClickHouse server 上允许的最大并发会话数。

示例：

```xml theme={null}
<profiles>
    <single_session_profile>
        <max_sessions_for_user>1</max_sessions_for_user>
    </single_session_profile>
    <two_sessions_profile>
        <max_sessions_for_user>2</max_sessions_for_user>
    </two_sessions_profile>
    <unlimited_sessions_profile>
        <max_sessions_for_user>0</max_sessions_for_user>
    </unlimited_sessions_profile>
</profiles>
<users>
    <!-- User Alice can connect to a ClickHouse server no more than once at a time. -->
    <Alice>
        <profile>single_session_user</profile>
    </Alice>
    <!-- User Bob can use 2 simultaneous sessions. -->
    <Bob>
        <profile>two_sessions_profile</profile>
    </Bob>
    <!-- User Charles can use arbitrarily many of simultaneous sessions. -->
    <Charles>
        <profile>unlimited_sessions_profile</profile>
    </Charles>
</users>
```

可能的值：

* 正整数
* `0` - 并发会话数量无限 (默认)

<div id="max_subquery_depth">
  ## max\_subquery\_depth
</div>

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

如果查询中的嵌套子查询数量超过指定值，则会抛出异常。

<Tip>
  可用它进行合理性检查，防止集群用户编写过于复杂的查询。
</Tip>

<div id="max_table_size_to_drop">
  ## max\_table\_size\_to\_drop
</div>

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

对在查询时删除表的限制。值 `0` 表示可以不受任何限制地删除所有表。

Cloud 默认值：1 TB。

<Note>
  此查询设置会覆盖对应的服务器级设置，参见 [max\_table\_size\_to\_drop](/docs/zh/reference/settings/server-settings/settings#max_table_size_to_drop)
</Note>

<div id="max_untracked_memory">
  ## max\_untracked\_memory
</div>

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

较小的内存分配和释放会在线程局部变量中归组，只有当其数量 (按绝对值计算) 大于指定值时，才会被跟踪或分析。如果该值高于 `memory_profiler_step`，则实际上会被下调为 `memory_profiler_step`。

<div id="max_wkb_geometry_elements">
  ## max\_wkb\_geometry\_elements
</div>

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.4"},{"label": "1000000"},{"label": "用于限制 WKB 几何解析中元素数量的新设置，可防止格式错误的数据导致过多内存分配。"}]}]} />

`readWKB` 及相关函数在解析时，单个 WKB 几何元素中允许包含的 Point、Ring 或 Polygon 的最大数量。这可防止格式错误的 WKB 数据导致过多内存分配。设为 0 可使用硬编码限制 (1 亿) 。
