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

# max_rows_* session settings

> ClickHouse session settings in the max_rows_* generated group.

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](/docs/reference/system-tables/settings) and are autogenerated from [source](https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/Settings.cpp).

<h2 id="max_rows_for_lazy_final">
  max\_rows\_for\_lazy\_final
</h2>

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.4"},{"label": "10000000"},{"label": "New setting for maximum number of rows in the set for lazy FINAL optimization"}]}]} />

Maximum number of rows in the set for lazy FINAL optimization. If exceeded, falls back to normal FINAL.

<h2 id="max_rows_in_distinct">
  max\_rows\_in\_distinct
</h2>

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

The maximum number of different rows when using DISTINCT.

<h2 id="max_rows_in_join">
  max\_rows\_in\_join
</h2>

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

Limits the number of rows in the right-side data structure (typically a hash
table) used when joining tables.

This setting applies to [SELECT ... JOIN](/docs/reference/statements/select/join)
operations and the [Join](/docs/reference/engines/table-engines/special/join) table engine.

If a query contains multiple joins, ClickHouse checks this setting for every
intermediate result. When the limit is reached, the action depends on the
chosen [`join_algorithm`](/docs/reference/settings/session-settings/join#join_algorithm) — see
that setting for the per-algorithm behavior (spill, re-partition, switch, or
throw/break per [`join_overflow_mode`](/docs/reference/settings/session-settings/join#join_overflow_mode)).

Possible values:

* Positive integer.
* `0` — Unlimited number of rows.

<h2 id="max_rows_in_set">
  max\_rows\_in\_set
</h2>

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

The maximum number of rows for a data set in the IN clause created from a subquery.

<h2 id="max_rows_in_set_to_optimize_join">
  max\_rows\_in\_set\_to\_optimize\_join
</h2>

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "24.1"},{"label": "0"},{"label": "Disable join optimization as it prevents from read in order optimization"}]}]} />

Maximal size of the set to filter joined tables by each other's row sets before joining.

Possible values:

* 0 — Disable.
* Any positive integer.

<h2 id="max_rows_to_group_by">
  max\_rows\_to\_group\_by
</h2>

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

The maximum number of unique keys received from aggregation. This setting lets
you limit memory consumption when aggregating.

If aggregation during GROUP BY is generating more than the specified number of
rows (unique GROUP BY keys), the behavior will be determined by the
'group\_by\_overflow\_mode' which by default is `throw`, but can be also switched
to an approximate GROUP BY mode.

<h2 id="max_rows_to_read">
  max\_rows\_to\_read
</h2>

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

The maximum number of rows that can be read from a table when running a query.
The restriction is checked for each processed chunk of data, applied only to the
deepest table expression and when reading from a remote server, checked only on
the remote server.

<h2 id="max_rows_to_read_leaf">
  max\_rows\_to\_read\_leaf
</h2>

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

The maximum number of rows that can be read from a local table on a leaf node when
running a distributed query. While distributed queries can issue multiple sub-queries
to each shard (leaf) - this limit will be checked only on the read stage on the
leaf nodes and ignored on the merging of results stage on the root node.

For example, a cluster consists of 2 shards and each shard contains a table with
100 rows. The distributed query which is supposed to read all the data from both
tables with setting `max_rows_to_read=150` will fail, as in total there will be
200 rows. A query with `max_rows_to_read_leaf=150` will succeed, since leaf nodes
will read at max 100 rows.

The restriction is checked for each processed chunk of data.

<Note>
  This setting is unstable with `prefer_localhost_replica=1`.
</Note>

<h2 id="max_rows_to_sort">
  max\_rows\_to\_sort
</h2>

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

The maximum number of rows before sorting. This allows you to limit memory consumption when sorting.
If more than the specified amount of records have to be processed for the ORDER BY operation,
the behavior will be determined by the `sort_overflow_mode` which by default is set to `throw`.

<h2 id="max_rows_to_transfer">
  max\_rows\_to\_transfer
</h2>

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

Maximum size (in rows) that can be passed to a remote server or saved in a
temporary table when the GLOBAL IN/JOIN section is executed.
