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

# force_* 会话设置

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

export const CloudOnlyBadge = () => {
  return <div className="cloudBadge">
            <div className="cloudIcon">
            <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path fillRule="evenodd" clipRule="evenodd" d="M5.33395 12.6667H12.3739C13.6593 12.6667 14.7073 11.6187 14.7073 10.3334C14.7073 9.04804 13.6593 8.00004 12.3739 8.00004H12.0839V7.33337C12.0839 5.12671 10.2906 3.33337 8.08395 3.33337C6.09928 3.33337 4.45395 4.78537 4.14195 6.68204C2.55728 6.76271 1.29395 8.06204 1.29395 9.66671C1.29395 11.3234 2.63728 12.6667 4.29395 12.6667H5.33395Z" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
            </svg>
        </div>
            {'仅限 ClickHouse Cloud'}
        </div>;
};

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="force_aggregate_partitions_independently">
  ## force\_aggregate\_partitions\_independently
</div>

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

在适用的情况下强制使用该优化，即使启发式规则判断不使用它

<div id="force_aggregation_in_order">
  ## force\_aggregation\_in\_order
</div>

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

该设置由服务器自身使用，用于支持分布式查询。请勿手动更改，否则会破坏正常运行。 (在分布式聚合期间，强制远程节点使用按顺序聚合。)

<div id="force_creating_set_partitions_independently">
  ## force\_creating\_set\_partitions\_independently
</div>

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.8"},{"label": "0"},{"label": "新增设置：即使分区倾斜检查会跳过，也强制在构建 `IN (subquery)` Set 时对每个分区进行预去重。"}]}]} />

当按分区预去重适用，但分区倾斜检查 (最大分区超过平均值的两倍) 决定不使用时，强制在构建 `IN (subquery)` Set 时对每个分区进行预去重。仅绕过 [allow\_creating\_set\_partitions\_independently](/zh/reference/settings/session-settings/allow#allow_creating_set_partitions_independently) 的倾斜检查；其余条件仍然适用。

<div id="force_data_skipping_indices">
  ## force\_data\_skipping\_indices
</div>

如果传入的数据跳过索引未被使用，则禁止查询执行。

请看以下示例：

```sql theme={null}
CREATE TABLE data
(
    key Int,
    d1 Int,
    d1_null Nullable(Int),
    INDEX d1_idx d1 TYPE minmax GRANULARITY 1,
    INDEX d1_null_idx assumeNotNull(d1_null) TYPE minmax GRANULARITY 1
)
Engine=MergeTree()
ORDER BY key;

SELECT * FROM data_01515;
SELECT * FROM data_01515 SETTINGS force_data_skipping_indices=''; -- query will produce CANNOT_PARSE_TEXT error.
SELECT * FROM data_01515 SETTINGS force_data_skipping_indices='d1_idx'; -- query will produce INDEX_NOT_USED error.
SELECT * FROM data_01515 WHERE d1 = 0 SETTINGS force_data_skipping_indices='d1_idx'; -- Ok.
SELECT * FROM data_01515 WHERE d1 = 0 SETTINGS force_data_skipping_indices='`d1_idx`'; -- Ok (example of full featured parser).
SELECT * FROM data_01515 WHERE d1 = 0 SETTINGS force_data_skipping_indices='`d1_idx`, d1_null_idx'; -- query will produce INDEX_NOT_USED error, since d1_null_idx is not used.
SELECT * FROM data_01515 WHERE d1 = 0 AND assumeNotNull(d1_null) = 0 SETTINGS force_data_skipping_indices='`d1_idx`, d1_null_idx'; -- Ok.
```

<div id="force_distinct_partitions_independently">
  ## force\_distinct\_partitions\_independently
</div>

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.8"},{"label": "0"},{"label": "新增设置：即使成本启发式算法会跳过，也强制按分区独立评估 `DISTINCT`。"}]}]} />

当按分区独立评估 `DISTINCT` 适用，但成本启发式算法决定不使用时，强制启用该评估。此设置仅绕过 [allow\_distinct\_partitions\_independently](/zh/reference/settings/session-settings/allow#allow_distinct_partitions_independently) 的成本启发式算法；其余条件仍然适用。

<div id="force_grouping_standard_compatibility">
  ## force\_grouping\_standard\_compatibility
</div>

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "22.9"},{"label": "1"},{"label": "使 GROUPING 函数的返回值与 SQL 标准及其他 DBMS 一致"}]}]} />

使 GROUPING 函数在参数未用作聚合键时返回 1

<div id="force_index_by_date">
  ## force\_index\_by\_date
</div>

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

如果查询不能利用日期索引，则禁用查询执行。

适用于 MergeTree 家族中的表。

如果 `force_index_by_date=1`，ClickHouse 会检查查询是否包含可用于限制数据范围的日期键条件。如果没有合适的条件，则会抛出异常。不过，它不会检查该条件是否减少了需要读取的数据量。例如，条件 `Date != ' 2000-01-01 '` 是允许的，即使它会匹配表中的所有数据 (也就是说，运行该查询需要全表扫描) 。有关 MergeTree 表中数据范围的更多信息，请参见 [MergeTree](/zh/reference/engines/table-engines/mergetree-family/mergetree)。

<div id="force_primary_key">
  ## force\_primary\_key
</div>

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

如果无法利用主键进行索引，则禁用查询执行。

适用于 MergeTree 家族中的表。

如果 `force_primary_key=1`，ClickHouse 会检查查询是否包含可用于限制数据范围的主键条件。如果没有合适的条件，则会抛出异常。不过，它不会检查该条件是否会减少需要读取的数据量。有关 MergeTree 表中数据范围的更多信息，请参见 [MergeTree](/zh/reference/engines/table-engines/mergetree-family/mergetree)。

<div id="force_read_through_distributed_cache">
  ## force\_read\_through\_distributed\_cache
</div>

<CloudOnlyBadge />

<SettingsInfoBlock type="BoolAuto" default_value="auto" />

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.9"},{"label": "auto"},{"label": "新增设置，可针对单个查询覆盖服务器设置 `enable_read_through_distributed_cache`。"}]}, {"id": "row-2","items": [{"label": "26.8"},{"label": "auto"},{"label": "新增设置，可针对单个查询覆盖服务器设置 `enable_read_through_distributed_cache`。"}]}]} />

仅在 ClickHouse Cloud 中生效。可针对单个查询覆盖服务器设置 `enable_read_through_distributed_cache`。`auto` (默认值) 表示沿用服务器设置。

<div id="force_remove_data_recursively_on_drop">
  ## force\_remove\_data\_recursively\_on\_drop
</div>

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

在执行 DROP 查询时递归删除数据。可避免“Directory not empty”错误，但也可能在无提示的情况下删除 detached 数据

<div id="force_window_partitions_independently">
  ## force\_window\_partitions\_independently
</div>

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.8"},{"label": "0"},{"label": "新增设置：即使成本启发式算法决定跳过，也强制按分区独立计算窗口函数。"}]}]} />

当满足适用条件但成本启发式算法决定不采用时，强制按分区独立计算窗口函数。仅绕过 [allow\_window\_partitions\_independently](/zh/reference/settings/session-settings/allow#allow_window_partitions_independently) 的成本启发式算法；其余条件仍然适用。

<div id="force_write_through_distributed_cache">
  ## force\_write\_through\_distributed\_cache
</div>

<CloudOnlyBadge />

<SettingsInfoBlock type="BoolAuto" default_value="auto" />

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.9"},{"label": "auto"},{"label": "用于针对单个查询覆盖服务器设置 `enable_write_through_distributed_cache` 的新增设置。"}]}, {"id": "row-2","items": [{"label": "26.8"},{"label": "auto"},{"label": "用于针对单个查询覆盖服务器设置 `enable_write_through_distributed_cache` 的新增设置。"}]}]} />

仅在 ClickHouse Cloud 中生效。可针对单个查询覆盖服务器设置 `enable_write_through_distributed_cache`。`auto` (默认值) 表示遵循服务器设置。
