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

# optimize_or_like_chain_* 会话设置

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

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="optimize_or_like_chain">
  ## optimize\_or\_like\_chain
</div>

<SettingsInfoBlock type="Bool" default_value="1" />

将同一表达式上的多个 `OR LIKE/ILIKE/match` 谓词优化为单个 `multiSearchAny`/`multiSearchAnyCaseInsensitiveUTF8` (用于 纯子串 `%needle%` 模式) 或 `multiMatchAny` (用于其他模式，在允许使用 Hyperscan/Vectorscan 时) 。如果这两种快速路径都不适用——例如 Hyperscan 被禁用或不可用，或者模式是原始 `match` Regex、不是有效的 UTF-8、包含嵌入的 NUL，或者 haystack 为 `FixedString`/`Enum`——则会保留原始 `OR` 事件链不变，因为基于 RE2 的合并 `match` 正则分支写法始终比原始的短路 `OR` 更慢。

该优化仅在启用 analyzer 时生效 (`enable_analyzer = 1`，默认值) ；使用旧 analyzer (`enable_analyzer = 0`) 时，`OR` 事件链保持不变。对于纯 `LIKE`/`ILIKE`/`match` 的 `OR` 事件链，原始表达式会保留在 `indexHint()` 中，以支持索引分析；对于包含非 `LIKE` 分支的混合 `OR` 事件链，则会有意跳过 `indexHint()` 包装，以避免仅匹配非 `LIKE` 分支的范围被剪枝。`multiMatchAny` 重写会遵循 `allow_hyperscan`、`max_hyperscan_regexp_length`、`max_hyperscan_regexp_total_length` 和 `reject_expensive_hyperscan_regexps`。

只有当事件链中有足够多的分支共享相同的左侧表达式，并且重写后能够稳定快于短路 `OR` 求值时，才会进行重写：对于 `multiSearchAny` 路径，至少需要 `optimize_or_like_chain_min_substrings` 个分支；对于 `multiMatchAny` 路径，至少需要 `optimize_or_like_chain_min_patterns` 个分支。

<div id="optimize_or_like_chain_min_patterns">
  ## optimize\_or\_like\_chain\_min\_patterns
</div>

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

对于共享同一个左侧表达式的非纯子串 `LIKE`/`ILIKE`/`match` 分支 (前缀/后缀/正则模式) ，这是 `optimize_or_like_chain` 将事件链重写为 `multiMatchAny` 所需的最小分支数。该值基于 `hits` 数据集校准 (参见 `tests/performance/optimize_or_like_chain_hits.xml`) ：对于前缀/正则 `LIKE` 事件链，只有当分支数达到大约 9 个时，`multiMatchAny` (Hyperscan) 重写才会比短路 `OR` 求值更快，因此较短的事件链会保持原样，以避免性能退化。值为 0 或 1 时会禁用此阈值。禁用 `optimize_or_like_chain` 时，此设置不起作用。另请参见纯子串 (`multiSearchAny`) 路径对应的 `optimize_or_like_chain_min_substrings`。

<div id="optimize_or_like_chain_min_substrings">
  ## optimize\_or\_like\_chain\_min\_substrings
</div>

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

对于共享同一左侧表达式的纯子串 (`%needle%`) `LIKE`/`ILIKE` 分支，只有当其数量达到该最小值时，`optimize_or_like_chain` 才会将条件事件链重写为 `multiSearchAny`/`multiSearchAnyCaseInsensitiveUTF8`。基于 `hits` 数据集校准 (参见 `tests/performance/optimize_or_like_chain_hits.xml`) ：当分支数大约达到 4 个时，重写为 `multiSearchAny` 的性能会优于短路 `OR` 求值。值为 0 或 1 时会禁用此阈值。禁用 `optimize_or_like_chain` 时，此设置不起作用。正则表达式 (`multiMatchAny`) 路径请另见 `optimize_or_like_chain_min_patterns`。
