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

# query_cache_* session settings

> ClickHouse session settings in the query_cache_* generated group.

export const VersionHistory = ({rows = []}) => {
  if (rows.length === 0) {
    return null;
  }
  const headers = ["Version", "Default value", "Comment"];
  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
  }}>
        Version history
      </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
  }}>Type</div>
      <div style={{
    overflowWrap: "anywhere"
  }}>{type}</div>
      <div style={{
    fontWeight: 600,
    opacity: 0.72,
    marginInlineStart: "0.5rem"
  }}>Default</div>
      <div style={{
    overflowWrap: "anywhere"
  }}>{default_value}</div>
      {changeable_without_restart && <div style={{
    fontWeight: 600,
    opacity: 0.72,
    marginInlineStart: "0.5rem"
  }}>
          Changeable without restart
        </div>}
      {changeable_without_restart && <div style={{
    overflowWrap: "anywhere"
  }}>
          {changeable_without_restart}
        </div>}
    </div>;
};

These settings are available in [system.settings](/reference/system-tables/settings) and are autogenerated from [source](https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/Settings.cpp).

<h2 id="query_cache_compress_entries">
  query\_cache\_compress\_entries
</h2>

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

Compress entries in the [query cache](/concepts/features/performance/caches/query-cache). Lessens the memory consumption of the query cache at the cost of slower inserts into / reads from it.

Possible values:

* 0 - Disabled
* 1 - Enabled

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

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.5"},{"label": "0"},{"label": "New setting to enable propagation of `use_query_cache` into all subqueries. Without it, subqueries are only cached on explicit per-subquery `SETTINGS use_query_cache = true` opt-in."}]}]} />

If turned on, subquery results may be written to and read from the [query cache](/concepts/features/performance/caches/query-cache). This enables propagation of `use_query_cache` into all subqueries.

Possible values:

* 0 - Disabled
* 1 - Enabled

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

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

The maximum number of query results the current user may store in the in-memory [query cache](/concepts/features/performance/caches/query-cache). 0 means unlimited.

This limit does not apply to the query cache on disk (setting `query_cache_on_disk_cache_name`), whose entries are bounded by the size of the underlying filesystem cache instead.

Possible values:

* Positive integer >= 0.

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

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

The maximum amount of memory (in bytes) the current user may allocate in the in-memory [query cache](/concepts/features/performance/caches/query-cache). 0 means unlimited.

This limit does not apply to the query cache on disk (setting `query_cache_on_disk_cache_name`), whose entries are bounded by the size of the underlying filesystem cache instead.

Possible values:

* Positive integer >= 0.

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

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

Minimum duration in milliseconds a query needs to run for its result to be stored in the [query cache](/concepts/features/performance/caches/query-cache).

Possible values:

* Positive integer >= 0.

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

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

Minimum number of times a `SELECT` query must run before its result is stored in the [query cache](/concepts/features/performance/caches/query-cache).

Possible values:

* Positive integer >= 0.

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

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

Controls how the [query cache](/concepts/features/performance/caches/query-cache) handles `SELECT` queries with non-deterministic functions like `rand()` or `now()`.

Possible values:

* `'throw'` - Throw an exception and don't cache the query result.
* `'save'` - Cache the query result.
* `'ignore'` - Don't cache the query result and don't throw an exception.

<h2 id="query_cache_on_disk_cache_name">
  query\_cache\_on\_disk\_cache\_name
</h2>

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.10"},{"label": ""},{"label": "New setting to store entries of the query cache on disk in the named filesystem cache."}]}]} />

The name of a filesystem cache (an entry of the `filesystem_caches` section of the server configuration) which stores entries of the [query cache](/concepts/features/performance/caches/query-cache) on disk. If a name is given (and [use\_query\_cache](/reference/settings/session-settings/use-query#use_query_cache) is enabled), query results are additionally cached in (and served from) the specified filesystem cache. The on-disk query cache provides more space than the in-memory query cache, survives server restarts, and works independently of the in-memory query cache: settings [enable\_reads\_from\_query\_cache\_on\_disk](/reference/settings/session-settings/enable#enable_reads_from_query_cache_on_disk) and [enable\_writes\_to\_query\_cache\_on\_disk](/reference/settings/session-settings/enable#enable_writes_to_query_cache_on_disk) control it separately from the in-memory query cache. The entries in the filesystem cache are ordinary entries of the filesystem cache: they are not held from deletion and they are evicted by the same rules as any other data in it. `SYSTEM CLEAR FILESYSTEM CACHE '<name>'` removes them together with everything else in the filesystem cache, and `SYSTEM CLEAR QUERY CACHE` removes the entries of the query cache on disk from the filesystem cache named by this setting, leaving all other data in place. A dedicated filesystem cache for query results is recommended.

Possible values:

* Empty string - The query cache on disk is disabled
* The name of a preconfigured filesystem cache

<h2 id="query_cache_on_disk_codec">
  query\_cache\_on\_disk\_codec
</h2>

<SettingsInfoBlock type="String" default_value="ZSTD(3)" />

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.10"},{"label": "ZSTD(3)"},{"label": "New setting to control the compression codec of query cache entries on disk."}]}]} />

The compression codec for entries of the [query cache](/concepts/features/performance/caches/query-cache) on disk (see [query\_cache\_on\_disk\_cache\_name](/reference/settings/session-settings/query-cache#query_cache_on_disk_cache_name)). Only affects writing; reading is independent of this setting because the compressed data is self-describing.

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

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

If turned on, the result of `SELECT` queries cached in the [query cache](/concepts/features/performance/caches/query-cache) can be read by other users.
It is not recommended to enable this setting due to security reasons.

Possible values:

* 0 - Disabled
* 1 - Enabled

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

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

Squash partial result blocks to blocks of size [max\_block\_size](/reference/settings/session-settings/max#max_block_size). Reduces performance of inserts into the [query cache](/concepts/features/performance/caches/query-cache) but improves the compressability of cache entries (see [query\_cache\_compress-entries](/reference/settings/session-settings/query-cache#query_cache_compress_entries)).

Possible values:

* 0 - Disabled
* 1 - Enabled

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

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "24.4"},{"label": "throw"},{"label": "The query cache no longer caches results of queries against system tables"}]}]} />

Controls how the [query cache](/concepts/features/performance/caches/query-cache) handles `SELECT` queries against system tables, i.e. tables in databases `system.*` and `information_schema.*`.

Possible values:

* `'throw'` - Throw an exception and don't cache the query result.
* `'save'` - Cache the query result.
* `'ignore'` - Don't cache the query result and don't throw an exception.

<h2 id="query_cache_tag">
  query\_cache\_tag
</h2>

<VersionHistory rows={[{"id": "row-1","items": [{"label": "24.8"},{"label": ""},{"label": "New setting for labeling query cache settings."}]}]} />

A string which acts as a label for [query cache](/concepts/features/performance/caches/query-cache) entries.
The same queries with different tags are considered different by the query cache.

Possible values:

* Any string

<h2 id="query_cache_ttl">
  query\_cache\_ttl
</h2>

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

After this time in seconds entries in the [query cache](/concepts/features/performance/caches/query-cache) become stale.

Possible values:

* Positive integer >= 0.
