> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-parallel-read-in-order-multi-part.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# webassembly_udf_* 会话设置

> webassembly_udf_* 生成分组中的 ClickHouse 会话设置。

export const ExperimentalBadge = () => {
  return <a href="https://clickhouse.com/docs/reference/settings/beta-and-experimental-features#experimental-features" 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 功能
        </a>;
};

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

<h2 id="webassembly_udf_input_split_memory_ratio">
  webassembly\_udf\_input\_split\_memory\_ratio
</h2>

<ExperimentalBadge />

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.9"},{"label": "0.5"},{"label": "新增设置，用于控制单次调用的序列化输入可占用 WebAssembly UDF 实例线性内存的比例，同时启用按序列化大小对该输入进行动态切分；`compatibility` 低于 26.9 时会将其设为 0 并恢复此前的行为，即 `webassembly_udf_max_input_block_size = 0` 表示每个管道块对应一次调用。"}]}]} />

单次调用的序列化输入可占用 WebAssembly UDF 实例线性内存的比例。取值必须不小于 0 且不大于 1；默认值会把另一半留给 guest，供其在输入 buffer 之外存放自身的 working set。

预留出低于 1 的余量正是批处理得以安全进行的关键：guest 自身的数据、栈和 allocator 共享这块内存，且对宿主不可见。比例接近 1 时它们将无内存可用，因此即使调用大小是按该比例计算的，仍可能在 guest 的 allocator 中失败。

该设置仅在 `ABI BUFFERED_V1` 下读取，并且只有当 `webassembly_udf_max_input_block_size` 为 0 时才用于确定调用大小——块大小非零时，则改为限制每次调用的行数。

批次永远不会小于一行，因此当某一行自身的序列化大小已超出预算时，该行会被单独传递；若某一行大到超过模块的线性内存，则会在 guest 的 allocator 中失败。

设为 0 表示不切分输入：整个管道块在一次调用中传入。

<h2 id="webassembly_udf_max_fuel">
  webassembly\_udf\_max\_fuel
</h2>

<ExperimentalBadge />

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.3"},{"label": "100000"},{"label": "用于限制每个 WebAssembly UDF 实例执行期间 CPU 指令（fuel）的新增设置。"}]}]} />

每个 WebAssembly UDF 实例执行期间的 fuel 限制。每条 WebAssembly 指令都会消耗一定数量的 fuel。该值在传递给运行时之前会先乘以 1024，因此 `webassembly_udf_max_fuel = 1` 大致相当于 1024 个 fuel 单位。设为 0 表示不设有限值限制。仅适用于每个函数的 `webassembly_udf_enable_fuel` 设置为 true 的函数；该值默认为 true。

<h2 id="webassembly_udf_max_input_block_size">
  webassembly\_udf\_max\_input\_block\_size
</h2>

<ExperimentalBadge />

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.3"},{"label": "0"},{"label": "用于限制 WebAssembly UDF 输入块大小的新设置。"}]}]} />

单次调用中传递给 WebAssembly UDF 的最大行数。非零值会限制每次调用的行数，并对所有 ABI 生效。

设置为 0 时，改为按序列化输入大小来确定每次调用的规模。这仅适用于 `ABI BUFFERED_V1`，它是唯一会将整个输入块序列化到 guest 内存中的 ABI：其块会被拆分，使单次调用的输入不超过模块线性内存的 `webassembly_udf_input_split_memory_ratio`。`ROW_DIRECT` 以 WebAssembly 值的形式传递参数，`ASSEMBLYSCRIPT` 则为每行构建一个 object，因此二者都没有可用于衡量调用规模的序列化输入，设置为 0 时它们的管道块将保持完整。

<h2 id="webassembly_udf_max_instances">
  webassembly\_udf\_max\_instances
</h2>

<ExperimentalBadge />

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.3"},{"label": "32"},{"label": "新增设置，用于限制每个函数可并行运行的 WebAssembly UDF 实例数。"}]}]} />

每个函数可并行运行的 WebAssembly UDF 实例最大数量。

<h2 id="webassembly_udf_max_memory">
  webassembly\_udf\_max\_memory
</h2>

<ExperimentalBadge />

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.3"},{"label": "134217728"},{"label": "限制每个 WebAssembly UDF 实例内存的新设置。"}]}]} />

每个 WebAssembly UDF 实例的内存限制，以字节为单位。
