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

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

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_execution_speed">
  ## max\_execution\_speed
</div>

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

每秒最大执行行数。在每个数据块上，都会在
[`timeout_before_checking_execution_speed`](/docs/zh/reference/settings/session-settings/other#timeout_before_checking_execution_speed)
超时后进行检查。如果执行速度过高，系统会降低执行速度。

<div id="max_execution_speed_bytes">
  ## max\_execution\_speed\_bytes
</div>

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

每秒允许的最大执行字节数。当
[`timeout_before_checking_execution_speed`](/docs/zh/reference/settings/session-settings/other#timeout_before_checking_execution_speed)
到期时，会在每个数据块上进行检查。如果执行速度过高，则会降低执行速度。

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

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

查询的最大执行时间 (单位为秒) 。

`max_execution_time` 参数可能有些不好理解。
它的工作方式是根据当前查询的执行速度进行插值计算
(这种行为由 [`timeout_before_checking_execution_speed`](/docs/zh/reference/settings/session-settings/other#timeout_before_checking_execution_speed) 控制) 。

如果预计执行时间超过指定的 `max_execution_time`，ClickHouse 将中断查询。
默认情况下，`timeout_before_checking_execution_speed`
设置为 10 秒。这意味着查询执行 10 秒后，ClickHouse
会开始估算总执行时间。比如，如果 `max_execution_time`
设置为 3600 秒 (1 小时) ，那么当估算出的执行时间超过 3600 秒限制时，ClickHouse 就会终止该查询。
如果将 `timeout_before_checking_execution_speed`
设置为 0，ClickHouse 将以实际时钟时间作为 `max_execution_time` 的依据。

如果查询运行时间超过指定秒数，其行为将由
`timeout_overflow_mode` 决定，默认值为 `throw`。

<Note>
  只有在数据处理过程中的特定位置才会检查是否超时，因此查询也只能在这些位置停止。
  目前无法在聚合状态合并期间或查询分析期间停止，
  因此实际运行时间会高于此设置的值。
</Note>

<div id="max_execution_time_leaf">
  ## max\_execution\_time\_leaf
</div>

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

其语义与 [`max_execution_time`](/docs/zh/reference/settings/session-settings/max-execution#max_execution_time) 类似，但仅
适用于分布式或远程查询中的叶节点。

例如，如果我们希望将叶节点上的执行时间限制为 `10s`，但
对初始节点不设限制，那么在嵌套子查询的设置中，应使用 `max_execution_time_leaf`，而不是 `max_execution_time`：

```sql theme={null}
SELECT count()
FROM cluster(cluster, view(SELECT * FROM t SETTINGS max_execution_time = 10));
```

我们可以将 `max_execution_time_leaf` 作为查询设置使用：

```sql theme={null}
SELECT count()
FROM cluster(cluster, view(SELECT * FROM t)) SETTINGS max_execution_time_leaf = 10;
```
