Skip to content
ClickHouse Docs
ClickHouse DocsClickHouse Docs

max_rows_* session settings

These settings are available in system.settings and are autogenerated from source.

max_rows_for_lazy_final

Type
UInt64
Default
10000000
Version history
VersionDefault valueComment
26.410000000New 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.

max_rows_in_distinct

Type
UInt64
Default
0

The maximum number of different rows when using DISTINCT.

max_rows_in_join

Type
UInt64
Default
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 operations and the 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 — see that setting for the per-algorithm behavior (spill, re-partition, switch, or throw/break per join_overflow_mode).

Possible values:

  • Positive integer.
  • 0 — Unlimited number of rows.

max_rows_in_set

Type
UInt64
Default
0

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

max_rows_in_set_to_optimize_join

Type
UInt64
Default
0
Version history
VersionDefault valueComment
24.10Disable 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.

max_rows_to_group_by

Type
UInt64
Default
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.

max_rows_to_read

Type
UInt64
Default
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.

max_rows_to_read_leaf

Type
UInt64
Default
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.

max_rows_to_sort

Type
UInt64
Default
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.

max_rows_to_transfer

Type
UInt64
Default
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.

Navigation