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

# optimize_move_to_prewhere_* 会话设置

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

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

## optimize\_move\_to\_prewhere

类型

Bool

默认值

1

启用或禁用 [SELECT](https://clickhouse.com/docs/zh/reference/statements/select/index.md) 查询中的自动 [PREWHERE](https://clickhouse.com/docs/zh/reference/statements/select/prewhere.md) 优化。

仅对 [\*MergeTree](https://clickhouse.com/docs/zh/reference/engines/table-engines/mergetree-family/index.md) 表生效。

可能的值：

* 0 — 禁用自动 `PREWHERE` 优化。
* 1 — 启用自动 `PREWHERE` 优化。

## optimize\_move\_to\_prewhere\_if\_final

类型

Bool

默认值

1

启用或禁用在带有 [FINAL](https://clickhouse.com/docs/zh/reference/statements/select/from.md#final-modifier) 修饰符的 [SELECT](https://clickhouse.com/docs/zh/reference/statements/select/index.md) 查询中自动应用 [PREWHERE](https://clickhouse.com/docs/zh/reference/statements/select/prewhere.md) 优化。

仅移动那些只依赖于 sorting key 且在查询内具有确定性的条件，
因此不会影响 `FINAL` 的结果。对于 [GraphiteMergeTree](https://clickhouse.com/docs/zh/reference/engines/table-engines/mergetree-family/graphitemergetree.md)，
`FINAL` 会将同一 path 的相邻行合并为一行。因此，该优化仅移动作用于 path 列的条件，
并且仅在 path 为 sorting key 的第一列时才会生效。

仅适用于 [\*MergeTree](https://clickhouse.com/docs/zh/reference/engines/table-engines/mergetree-family/index.md) 表。

可能的值：

* 0 — 禁用在带有 `FINAL` 修饰符的 `SELECT` 查询中自动应用 `PREWHERE` 优化。
* 1 — 启用在带有 `FINAL` 修饰符的 `SELECT` 查询中自动应用 `PREWHERE` 优化。

**另请参见**

* [optimize\_move\_to\_prewhere](https://clickhouse.com/docs/zh/reference/settings/session-settings/optimize-move-to-prewhere.md#optimize_move_to_prewhere) 设置
