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

# query_cache_* 会话设置

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

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="query_cache_compress_entries">
  ## query\_cache\_compress\_entries
</div>

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

压缩[查询缓存](/docs/zh/concepts/features/performance/caches/query-cache)中的条目。这样可以减少查询缓存的内存占用，但代价是向其中插入数据和从中读取数据都会变慢。

可能的值：

* 0 - 已禁用
* 1 - 已启用

<div id="query_cache_for_subqueries">
  ## query\_cache\_for\_subqueries
</div>

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.5"},{"label": "0"},{"label": "用于启用将 `use_query_cache` 传递到所有子查询的新设置。若未启用，子查询仅会在显式为该子查询设置 `SETTINGS use_query_cache = true` 时才会被缓存。"}]}]} />

启用后，子查询结果可以写入并从[查询缓存](/docs/zh/concepts/features/performance/caches/query-cache)中读取。这会将 `use_query_cache` 传递到所有子查询。

可能的值：

* 0 - 已禁用
* 1 - 已启用

<div id="query_cache_max_entries">
  ## query\_cache\_max\_entries
</div>

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

当前用户可在[查询缓存](/docs/zh/concepts/features/performance/caches/query-cache)中存储的查询结果的最大条目数。0 表示不受限制。

可能的值：

* 大于等于 0 的正整数。

<div id="query_cache_max_size_in_bytes">
  ## query\_cache\_max\_size\_in\_bytes
</div>

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

当前用户可在[查询缓存](/docs/zh/concepts/features/performance/caches/query-cache)中分配的最大内存量 (以字节为单位) 。0 表示不受限制。

可选值：

* 大于或等于 0 的整数。

<div id="query_cache_min_query_duration">
  ## query\_cache\_min\_query\_duration
</div>

<SettingsInfoBlock type="毫秒" default_value="0" />

查询至少需要运行多长时间 (以毫秒为单位) ，其结果才会被存储到[查询缓存](/docs/zh/concepts/features/performance/caches/query-cache)中。

可能的值：

* 大于等于 0 的整数。

<div id="query_cache_min_query_runs">
  ## query\_cache\_min\_query\_runs
</div>

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

`SELECT` 查询的结果在存入 [查询缓存](/docs/zh/concepts/features/performance/caches/query-cache) 之前，至少需要运行的次数。

可能的值：

* 大于等于 0 的整数。

<div id="query_cache_nondeterministic_function_handling">
  ## query\_cache\_nondeterministic\_function\_handling
</div>

<SettingsInfoBlock type="QueryResultCacheNondeterministicFunctionHandling" default_value="throw" />

控制[查询缓存](/docs/zh/concepts/features/performance/caches/query-cache)如何处理包含 `rand()`、`now()` 等非确定性函数的 `SELECT` 查询。

可选值：

* `'throw'` - 抛出异常，并且不缓存查询结果。
* `'save'` - 缓存查询结果。
* `'ignore'` - 不缓存查询结果，也不抛出异常。

<div id="query_cache_share_between_users">
  ## query\_cache\_share\_between\_users
</div>

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

启用后，缓存在 [查询缓存](/docs/zh/concepts/features/performance/caches/query-cache) 中的 `SELECT` 查询结果可供其他用户读取。
基于安全考虑，不建议启用此设置。

可能的值：

* 0 - 已禁用
* 1 - 已启用

<div id="query_cache_squash_partial_results">
  ## query\_cache\_squash\_partial\_results
</div>

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

将部分结果块合并成大小为 [max\_block\_size](/docs/zh/reference/settings/session-settings/max#max_block_size) 的块。这样会降低向[查询缓存](/docs/zh/concepts/features/performance/caches/query-cache)插入数据的性能，但能提升缓存条目的压缩效果 (参见 [query\_cache\_compress-entries](/docs/zh/reference/settings/session-settings/query-cache#query_cache_compress_entries)) 。

可能的值：

* 0 - 已禁用
* 1 - 已启用

<div id="query_cache_system_table_handling">
  ## query\_cache\_system\_table\_handling
</div>

<SettingsInfoBlock type="QueryResultCacheSystemTableHandling" default_value="throw" />

<VersionHistory rows={[{"id": "row-1","items": [{"label": "24.4"},{"label": "throw"},{"label": "查询缓存不再缓存针对系统表的查询结果"}]}]} />

控制[查询缓存](/docs/zh/concepts/features/performance/caches/query-cache)在处理针对系统表的 `SELECT` 查询时的行为，即针对 `system.*` 和 `information_schema.*` 数据库中表的查询。

可选值：

* `'throw'` - 抛出异常，并且不缓存查询结果。
* `'save'` - 缓存查询结果。
* `'ignore'` - 不缓存查询结果，也不抛出异常。

<div id="query_cache_tag">
  ## query\_cache\_tag
</div>

<VersionHistory rows={[{"id": "row-1","items": [{"label": "24.8"},{"label": ""},{"label": "用于为查询缓存设置添加标签的新设置。"}]}]} />

一个字符串，用作[查询缓存](/docs/zh/concepts/features/performance/caches/query-cache)条目的标签。
对于相同的查询，如果标签不同，查询缓存会将其视为不同的查询。

可能的值：

* 任意字符串

<div id="query_cache_ttl">
  ## query\_cache\_ttl
</div>

<SettingsInfoBlock type="Seconds" default_value="60" />

超过此秒数后，[查询缓存](/docs/zh/concepts/features/performance/caches/query-cache)中的条目将过期。

可选值：

* 正整数 >= 0。
