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

# use_top_k_dynamic_filtering_* 会话设置

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

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="use_top_k_dynamic_filtering">
  ## use\_top\_k\_dynamic\_filtering
</div>

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.5"},{"label": "1"},{"label": "默认启用 TopK 查询的动态过滤优化"}]}, {"id": "row-2","items": [{"label": "25.12"},{"label": "0"},{"label": "新设置。"}]}]} />

在执行 `ORDER BY <column> LIMIT n` 查询时启用动态过滤优化。

启用后，查询执行器会尝试跳过那些不会进入结果集最终 `top N` 行的粒度和行。这项优化具有动态特性，延迟改善效果取决于数据分布以及查询中是否存在其他谓词。

可能的值：

* 0 — 已禁用。
* 1 — 已启用。

<div id="use_top_k_dynamic_filtering_for_variable_length_types">
  ## use\_top\_k\_dynamic\_filtering\_for\_variable\_length\_types
</div>

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.5"},{"label": "0"},{"label": "默认对变长排序列（例如 `String`）禁用 `use_top_k_dynamic_filtering`；此前该优化会无条件应用，此行为在 `compatibility` 下保留。"}]}]} />

允许在排序列为变长数据类型 (例如 `String`、`Array`、`Map`、包含变长元素的 `Tuple`) 时应用 `use_top_k_dynamic_filtering`。

对于这类类型，当列的字典序最小值占主导 (例如大多为空字符串) 且只能跳过很少的粒度时，动态过滤执行逐行阈值比较的开销可能会超过其带来的收益。在这种情况下，动态过滤会增加查询延迟，而非带来改进。

当此设置为 `0` 时，动态过滤仅适用于值在内存中具有固定最大大小的列 (数值、`Date`、`DateTime`、`FixedString`、`Enum`、这些类型的 `Nullable` 以及这些类型的 `Tuple`) 。设置为 `1` 时，动态过滤也会应用于变长类型。

可选值：

* 0 — 禁用。
* 1 — 启用。
