settings.md 103.2 KB
Newer Older
1
# Settings {#settings}
2

A
Alexey Milovidov 已提交
3
## distributed_product_mode {#distributed-product-mode}
4

D
Daria Mozhaeva 已提交
5
Changes the behaviour of [distributed subqueries](../../sql-reference/operators/in.md).
6

7
ClickHouse applies this setting when the query contains the product of distributed tables, i.e. when the query for a distributed table contains a non-GLOBAL subquery for the distributed table.
8 9 10

Restrictions:

11 12 13
-   Only applied for IN and JOIN subqueries.
-   Only if the FROM section uses a distributed table containing more than one shard.
-   If the subquery concerns a distributed table containing more than one shard.
14
-   Not used for a table-valued [remote](../../sql-reference/table-functions/remote.md) function.
15

16
Possible values:
17

18 19 20 21
-   `deny` — Default value. Prohibits using these types of subqueries (returns the “Double-distributed in/JOIN subqueries is denied” exception).
-   `local` — Replaces the database and table in the subquery with local ones for the destination server (shard), leaving the normal `IN`/`JOIN.`
-   `global` — Replaces the `IN`/`JOIN` query with `GLOBAL IN`/`GLOBAL JOIN.`
-   `allow` — Allows the use of these types of subqueries.
22

A
Alexey Milovidov 已提交
23
## enable_optimize_predicate_expression {#enable-optimize-predicate-expression}
24

25
Turns on predicate pushdown in `SELECT` queries.
26

27
Predicate pushdown may significantly reduce network traffic for distributed queries.
28 29 30

Possible values:

31 32
-   0 — Disabled.
-   1 — Enabled.
33

F
filimonov 已提交
34
Default value: 1.
35

S
Fixes  
Sergei Bocharov 已提交
36
Usage
37

38
Consider the following queries:
39

40 41
1.  `SELECT count() FROM test_table WHERE date = '2018-10-10'`
2.  `SELECT count() FROM (SELECT * FROM test_table) WHERE date = '2018-10-10'`
42

43
If `enable_optimize_predicate_expression = 1`, then the execution time of these queries is equal because ClickHouse applies `WHERE` to the subquery when processing it.
44

D
Daria Mozhaeva 已提交
45
If `enable_optimize_predicate_expression = 0`, then the execution time of the second query is much longer because the `WHERE` clause applies to all the data after the subquery finishes.
46

A
Alexey Milovidov 已提交
47
## fallback_to_stale_replicas_for_distributed_queries {#settings-fallback_to_stale_replicas_for_distributed_queries}
48

49
Forces a query to an out-of-date replica if updated data is not available. See [Replication](../../engines/table-engines/mergetree-family/replication.md).
50 51 52

ClickHouse selects the most relevant from the outdated replicas of the table.

53
Used when performing `SELECT` from a distributed table that points to replicated tables.
54 55 56

By default, 1 (enabled).

A
Alexey Milovidov 已提交
57
## force_index_by_date {#settings-force_index_by_date}
58

59
Disables query execution if the index can’t be used by date.
60 61 62

Works with tables in the MergeTree family.

63
If `force_index_by_date=1`, ClickHouse checks whether the query has a date key condition that can be used for restricting data ranges. If there is no suitable condition, it throws an exception. However, it does not check whether the condition reduces the amount of data to read. For example, the condition `Date != ' 2000-01-01 '` is acceptable even when it matches all the data in the table (i.e., running the query requires a full scan). For more information about ranges of data in MergeTree tables, see [MergeTree](../../engines/table-engines/mergetree-family/mergetree.md).
64

A
Alexey Milovidov 已提交
65
## force_primary_key {#force-primary-key}
66 67 68 69 70

Disables query execution if indexing by the primary key is not possible.

Works with tables in the MergeTree family.

71
If `force_primary_key=1`, ClickHouse checks to see if the query has a primary key condition that can be used for restricting data ranges. If there is no suitable condition, it throws an exception. However, it does not check whether the condition reduces the amount of data to read. For more information about data ranges in MergeTree tables, see [MergeTree](../../engines/table-engines/mergetree-family/mergetree.md).
72

A
Alexey Milovidov 已提交
73
## force_data_skipping_indices {#settings-force_data_skipping_indices}
74 75 76

Disables query execution if passed data skipping indices wasn't used.

77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
Consider the following example:

```sql
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.
```

100 101
Works with tables in the MergeTree family.

A
Alexey Milovidov 已提交
102
## format_schema {#format-schema}
A
Alexander Tokmakov 已提交
103

104
This parameter is useful when you are using formats that require a schema definition, such as [Cap’n Proto](https://capnproto.org/) or [Protobuf](https://developers.google.com/protocol-buffers/). The value depends on the format.
105

A
Alexey Milovidov 已提交
106
## fsync_metadata {#fsync-metadata}
107

108
Enables or disables [fsync](http://pubs.opengroup.org/onlinepubs/9699919799/functions/fsync.html) when writing `.sql` files. Enabled by default.
109

A
alexey-milovidov 已提交
110
It makes sense to disable it if the server has millions of tiny tables that are constantly being created and destroyed.
111

A
Alexey Milovidov 已提交
112
## enable_http_compression {#settings-enable_http_compression}
113

114
Enables or disables data compression in the response to an HTTP request.
115 116 117 118 119

For more information, read the [HTTP interface description](../../interfaces/http.md).

Possible values:

120 121
-   0 — Disabled.
-   1 — Enabled.
122 123 124

Default value: 0.

A
Alexey Milovidov 已提交
125
## http_zlib_compression_level {#settings-http_zlib_compression_level}
126

A
Alexey Milovidov 已提交
127
Sets the level of data compression in the response to an HTTP request if [enable_http_compression = 1](#settings-enable_http_compression).
128

129
Possible values: Numbers from 1 to 9.
130 131 132

Default value: 3.

A
Alexey Milovidov 已提交
133
## http_native_compression_disable_checksumming_on_decompress {#settings-http_native_compression_disable_checksumming_on_decompress}
134

135
Enables or disables checksum verification when decompressing the HTTP POST data from the client. Used only for ClickHouse native compression format (not used with `gzip` or `deflate`).
136 137 138 139 140

For more information, read the [HTTP interface description](../../interfaces/http.md).

Possible values:

141 142
-   0 — Disabled.
-   1 — Enabled.
143 144 145

Default value: 0.

A
Alexey Milovidov 已提交
146
## send_progress_in_http_headers {#settings-send_progress_in_http_headers}
147

148
Enables or disables `X-ClickHouse-Progress` HTTP response headers in `clickhouse-server` responses.
149 150 151 152 153

For more information, read the [HTTP interface description](../../interfaces/http.md).

Possible values:

154 155
-   0 — Disabled.
-   1 — Enabled.
156 157 158

Default value: 0.

A
Alexey Milovidov 已提交
159
## max_http_get_redirects {#setting-max_http_get_redirects}
160

161
Limits the maximum number of HTTP GET redirect hops for [URL](../../engines/table-engines/special/url.md)-engine tables. The setting applies to both types of tables: those created by the [CREATE TABLE](../../sql-reference/statements/create/table.md) query and by the [url](../../sql-reference/table-functions/url.md) table function.
162 163 164

Possible values:

165 166
-   Any positive integer number of hops.
-   0 — No hops allowed.
167 168 169

Default value: 0.

A
Alexey Milovidov 已提交
170
## input_format_allow_errors_num {#settings-input_format_allow_errors_num}
171 172 173 174 175

Sets the maximum number of acceptable errors when reading from text formats (CSV, TSV, etc.).

The default value is 0.

A
Alexander Tokmakov 已提交
176
Always pair it with `input_format_allow_errors_ratio`.
177 178 179

If an error occurred while reading rows but the error counter is still less than `input_format_allow_errors_num`, ClickHouse ignores the row and moves on to the next one.

A
Alexander Tokmakov 已提交
180
If both `input_format_allow_errors_num` and `input_format_allow_errors_ratio` are exceeded, ClickHouse throws an exception.
181

A
Alexey Milovidov 已提交
182
## input_format_allow_errors_ratio {#settings-input_format_allow_errors_ratio}
183 184 185 186 187 188

Sets the maximum percentage of errors allowed when reading from text formats (CSV, TSV, etc.).
The percentage of errors is set as a floating-point number between 0 and 1.

The default value is 0.

A
Alexander Tokmakov 已提交
189
Always pair it with `input_format_allow_errors_num`.
190 191 192

If an error occurred while reading rows but the error counter is still less than `input_format_allow_errors_ratio`, ClickHouse ignores the row and moves on to the next one.

A
Alexander Tokmakov 已提交
193
If both `input_format_allow_errors_num` and `input_format_allow_errors_ratio` are exceeded, ClickHouse throws an exception.
194

A
Alexey Milovidov 已提交
195
## input_format_values_interpret_expressions {#settings-input_format_values_interpret_expressions}
196

197
Enables or disables the full SQL parser if the fast stream parser can’t parse the data. This setting is used only for the [Values](../../interfaces/formats.md#data-format-values) format at the data insertion. For more information about syntax parsing, see the [Syntax](../../sql-reference/syntax.md) section.
198 199 200

Possible values:

201
-   0 — Disabled.
202

203
    In this case, you must provide formatted data. See the [Formats](../../interfaces/formats.md) section.
204

205
-   1 — Enabled.
206

207
    In this case, you can use an SQL expression as a value, but data insertion is much slower this way. If you insert only formatted data, then ClickHouse behaves as if the setting value is 0.
208 209 210

Default value: 1.

S
Fixes  
Sergei Bocharov 已提交
211
Example of Use
212

213
Insert the [DateTime](../../sql-reference/data-types/datetime.md) type value with the different settings.
214

215
``` sql
216 217
SET input_format_values_interpret_expressions = 0;
INSERT INTO datetime_t VALUES (now())
218
```
S
Fixes  
Sergei Bocharov 已提交
219

220
``` text
221 222 223 224
Exception on client:
Code: 27. DB::Exception: Cannot parse input: expected ) before: now()): (at row 1)
```

225
``` sql
226 227
SET input_format_values_interpret_expressions = 1;
INSERT INTO datetime_t VALUES (now())
228
```
S
Fixes  
Sergei Bocharov 已提交
229

230
``` text
231 232 233
Ok.
```

234
The last query is equivalent to the following:
235

236
``` sql
237 238
SET input_format_values_interpret_expressions = 0;
INSERT INTO datetime_t SELECT now()
239
```
S
Fixes  
Sergei Bocharov 已提交
240

241
``` text
242 243 244
Ok.
```

A
Alexey Milovidov 已提交
245
## input_format_values_deduce_templates_of_expressions {#settings-input_format_values_deduce_templates_of_expressions}
S
Fixes  
Sergei Bocharov 已提交
246

D
Daria Mozhaeva 已提交
247
Enables or disables template deduction for SQL expressions in [Values](../../interfaces/formats.md#data-format-values) format. It allows parsing and interpreting expressions in `Values` much faster if expressions in consecutive rows have the same structure. ClickHouse tries to deduce the template of an expression, parse the following rows using this template and evaluate the expression on a batch of successfully parsed rows.
B
BayoNet 已提交
248 249 250 251 252 253 254 255 256

Possible values:

-   0 — Disabled.
-   1 — Enabled.

Default value: 1.

For the following query:
S
Fixes  
Sergei Bocharov 已提交
257

258
``` sql
A
Alexander Tokmakov 已提交
259
INSERT INTO test VALUES (lower('Hello')), (lower('world')), (lower('INSERT')), (upper('Values')), ...
260
```
S
Fixes  
Sergei Bocharov 已提交
261

B
BayoNet 已提交
262 263 264
-   If `input_format_values_interpret_expressions=1` and `format_values_deduce_templates_of_expressions=0`, expressions are interpreted separately for each row (this is very slow for large number of rows).
-   If `input_format_values_interpret_expressions=0` and `format_values_deduce_templates_of_expressions=1`, expressions in the first, second and third rows are parsed using template `lower(String)` and interpreted together, expression in the forth row is parsed with another template (`upper(String)`).
-   If `input_format_values_interpret_expressions=1` and `format_values_deduce_templates_of_expressions=1`, the same as in previous case, but also allows fallback to interpreting expressions separately if it’s not possible to deduce template.
A
Alexander Tokmakov 已提交
265

A
Alexey Milovidov 已提交
266
## input_format_values_accurate_types_of_literals {#settings-input-format-values-accurate-types-of-literals}
S
Fixes  
Sergei Bocharov 已提交
267

D
Daria Mozhaeva 已提交
268
This setting is used only when `input_format_values_deduce_templates_of_expressions = 1`. Expressions for some column may have the same structure, but contain numeric literals of different types, e.g.
269 270

``` sql
A
Alexander Tokmakov 已提交
271 272 273 274
(..., abs(0), ...),             -- UInt64 literal
(..., abs(3.141592654), ...),   -- Float64 literal
(..., abs(-1), ...),            -- Int64 literal
```
S
Fixes  
Sergei Bocharov 已提交
275

B
BayoNet 已提交
276 277 278 279 280 281 282 283 284 285 286
Possible values:

-   0 — Disabled.

    In this case, ClickHouse may use a more general type for some literals (e.g., `Float64` or `Int64` instead of `UInt64` for `42`), but it may cause overflow and precision issues.

-   1 — Enabled.

    In this case, ClickHouse checks the actual type of literal and uses an expression template of the corresponding type. In some cases, it may significantly slow down expression evaluation in `Values`.

Default value: 1.
A
Alexander Tokmakov 已提交
287

A
Alexey Milovidov 已提交
288
## input_format_defaults_for_omitted_fields {#session_settings-input_format_defaults_for_omitted_fields}
289

290
When performing `INSERT` queries, replace omitted input column values with default values of the respective columns. This option only applies to [JSONEachRow](../../interfaces/formats.md#jsoneachrow), [CSV](../../interfaces/formats.md#csv) and [TabSeparated](../../interfaces/formats.md#tabseparated) formats.
291 292

!!! note "Note"
293
    When this option is enabled, extended table metadata are sent from server to client. It consumes additional computing resources on the server and can reduce performance.
294

295 296
Possible values:

297 298
-   0 — Disabled.
-   1 — Enabled.
299

300
Default value: 1.
301

A
Alexey Milovidov 已提交
302
## input_format_tsv_empty_as_default {#settings-input-format-tsv-empty-as-default}
A
fixes  
Alexander Tokmakov 已提交
303 304 305 306 307

When enabled, replace empty input fields in TSV with default values. For complex default expressions `input_format_defaults_for_omitted_fields` must be enabled too.

Disabled by default.

308
## input_format_tsv_enum_as_number {#settings-input_format_tsv_enum_as_number}
309

A
Fixed  
annvsh 已提交
310
Enables or disables parsing enum values as enum ids for TSV input format.
A
annvsh 已提交
311 312

Possible values:
A
Alexander Tokmakov 已提交
313

A
Fixed  
annvsh 已提交
314
-   0 — Enum values are parsed as values.
D
Daria Mozhaeva 已提交
315
-   1 — Enum values are parsed as enum IDs.
A
Alexander Tokmakov 已提交
316

A
annvsh 已提交
317 318 319 320
Default value: 0.

**Example**

A
Fixed  
annvsh 已提交
321
Consider the table:
A
annvsh 已提交
322 323

```sql
A
Fixed  
annvsh 已提交
324
CREATE TABLE table_with_enum_column_for_tsv_insert (Id Int32,Value Enum('first' = 1, 'second' = 2)) ENGINE=Memory();
A
Fixed  
annvsh 已提交
325
```
A
annvsh 已提交
326

327
When the `input_format_tsv_enum_as_number` setting is enabled:
A
annvsh 已提交
328

A
Fixed  
annvsh 已提交
329
```sql
A
annvsh 已提交
330
SET input_format_tsv_enum_as_number = 1;
A
Fixed  
annvsh 已提交
331 332
INSERT INTO table_with_enum_column_for_tsv_insert FORMAT TSV 102	2;
INSERT INTO table_with_enum_column_for_tsv_insert FORMAT TSV 103	1;
A
annvsh 已提交
333 334 335 336 337 338
SELECT * FROM table_with_enum_column_for_tsv_insert;
```

Result:

```text
A
Fixed  
annvsh 已提交
339 340 341 342 343 344
┌──Id─┬─Value──┐
│ 102 │ second │
└─────┴────────┘
┌──Id─┬─Value──┐
│ 103 │ first  │
└─────┴────────┘
A
annvsh 已提交
345
```
346

A
Fixed  
annvsh 已提交
347 348 349 350 351 352 353 354
When the `input_format_tsv_enum_as_number` setting is disabled, the `INSERT` query:

```sql
SET input_format_tsv_enum_as_number = 0;
INSERT INTO table_with_enum_column_for_tsv_insert FORMAT TSV 102	2;
```

throws an exception.
355

A
Alexey Milovidov 已提交
356
## input_format_null_as_default {#settings-input-format-null-as-default}
A
Alexander Tokmakov 已提交
357

358
Enables or disables using default values if input data contain `NULL`, but the data type of the corresponding column in not `Nullable(T)` (for text input formats).
A
Alexander Tokmakov 已提交
359

A
Alexey Milovidov 已提交
360
## input_format_skip_unknown_fields {#settings-input-format-skip-unknown-fields}
361

362
Enables or disables skipping insertion of extra data.
363

364
When writing data, ClickHouse throws an exception if input data contain columns that do not exist in the target table. If skipping is enabled, ClickHouse doesn’t insert extra data and doesn’t throw an exception.
365

366 367
Supported formats:

368 369 370 371
-   [JSONEachRow](../../interfaces/formats.md#jsoneachrow)
-   [CSVWithNames](../../interfaces/formats.md#csvwithnames)
-   [TabSeparatedWithNames](../../interfaces/formats.md#tabseparatedwithnames)
-   [TSKV](../../interfaces/formats.md#tskv)
372 373

Possible values:
374

375 376
-   0 — Disabled.
-   1 — Enabled.
377

378 379
Default value: 0.

A
Alexey Milovidov 已提交
380
## input_format_import_nested_json {#settings-input_format_import_nested_json}
381

382
Enables or disables the insertion of JSON data with nested objects.
383 384 385

Supported formats:

386
-   [JSONEachRow](../../interfaces/formats.md#jsoneachrow)
387 388 389

Possible values:

390 391
-   0 — Disabled.
-   1 — Enabled.
392 393 394

Default value: 0.

S
Fixes  
Sergei Bocharov 已提交
395
See also:
396

397
-   [Usage of Nested Structures](../../interfaces/formats.md#jsoneachrow-nested) with the `JSONEachRow` format.
398

A
Alexey Milovidov 已提交
399
## input_format_with_names_use_header {#settings-input-format-with-names-use-header}
400 401

Enables or disables checking the column order when inserting data.
B
BayoNet 已提交
402

403 404 405
To improve insert performance, we recommend disabling this check if you are sure that the column order of the input data is the same as in the target table.

Supported formats:
406

407 408
-   [CSVWithNames](../../interfaces/formats.md#csvwithnames)
-   [TabSeparatedWithNames](../../interfaces/formats.md#tabseparatedwithnames)
409 410 411

Possible values:

412 413
-   0 — Disabled.
-   1 — Enabled.
414 415

Default value: 1.
416

A
Alexey Milovidov 已提交
417
## date_time_input_format {#settings-date_time_input_format}
418

419
Allows choosing a parser of the text representation of date and time.
420

421
The setting doesn’t apply to [date and time functions](../../sql-reference/functions/date-time-functions.md).
422 423 424

Possible values:

425
-   `'best_effort'` — Enables extended parsing.
426

427
    ClickHouse can parse the basic `YYYY-MM-DD HH:MM:SS` format and all [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date and time formats. For example, `'2018-06-08T01:02:03.000Z'`.
428

429
-   `'basic'` — Use basic parser.
430

D
links  
Daria Mozhaeva 已提交
431
    ClickHouse can parse only the basic `YYYY-MM-DD HH:MM:SS` or `YYYY-MM-DD` format. For example, `2019-08-20 10:18:56` or `2019-08-20`.
432 433

Default value: `'basic'`.
434

S
Fixes  
Sergei Bocharov 已提交
435
See also:
436

437 438
-   [DateTime data type.](../../sql-reference/data-types/datetime.md)
-   [Functions for working with dates and times.](../../sql-reference/functions/date-time-functions.md)
439

440
## date_time_output_format {#settings-date_time_output_format}
441 442 443 444 445

Allows choosing different output formats of the text representation of date and time.

Possible values:

D
Daria Mozhaeva 已提交
446
-   `simple` - Simple output format.
447

D
Daria Mozhaeva 已提交
448
    Clickhouse output date and time `YYYY-MM-DD hh:mm:ss` format. For example, `2019-08-20 10:18:56`. The calculation is performed according to the data type's time zone (if present) or server time zone.
449

D
Daria Mozhaeva 已提交
450
-   `iso` - ISO output format.
451

D
Daria Mozhaeva 已提交
452
    Clickhouse output date and time in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) `YYYY-MM-DDThh:mm:ssZ` format. For example, `2019-08-20T10:18:56Z`. Note that output is in UTC (`Z` means UTC).
453

D
Daria Mozhaeva 已提交
454
-   `unix_timestamp` - Unix timestamp output format.
455

D
Daria Mozhaeva 已提交
456
    Clickhouse output date and time in [Unix timestamp](https://en.wikipedia.org/wiki/Unix_time) format. For example `1566285536`.
457

D
Daria Mozhaeva 已提交
458
Default value: `simple`.
459 460 461 462 463 464

See also:

-   [DateTime data type.](../../sql-reference/data-types/datetime.md)
-   [Functions for working with dates and times.](../../sql-reference/functions/date-time-functions.md)

A
Alexey Milovidov 已提交
465
## join_default_strictness {#settings-join_default_strictness}
B
BayoNet 已提交
466

467
Sets default strictness for [JOIN clauses](../../sql-reference/statements/select/join.md#select-join).
B
BayoNet 已提交
468

469
Possible values:
B
BayoNet 已提交
470

471 472 473 474
-   `ALL` — If the right table has several matching rows, ClickHouse creates a [Cartesian product](https://en.wikipedia.org/wiki/Cartesian_product) from matching rows. This is the normal `JOIN` behaviour from standard SQL.
-   `ANY` — If the right table has several matching rows, only the first one found is joined. If the right table has only one matching row, the results of `ANY` and `ALL` are the same.
-   `ASOF` — For joining sequences with an uncertain match.
-   `Empty string` — If `ALL` or `ANY` is not specified in the query, ClickHouse throws an exception.
B
BayoNet 已提交
475

476
Default value: `ALL`.
B
BayoNet 已提交
477

A
Alexey Milovidov 已提交
478
## join_any_take_last_row {#settings-join_any_take_last_row}
479

480
Changes behaviour of join operations with `ANY` strictness.
481

482
!!! warning "Attention"
483
    This setting applies only for `JOIN` operations with [Join](../../engines/table-engines/special/join.md) engine tables.
484 485 486

Possible values:

487 488
-   0 — If the right table has more than one matching row, only the first one found is joined.
-   1 — If the right table has more than one matching row, only the last one found is joined.
489

B
BayoNet 已提交
490
Default value: 0.
491

S
Fixes  
Sergei Bocharov 已提交
492
See also:
493

494
-   [JOIN clause](../../sql-reference/statements/select/join.md#select-join)
495
-   [Join table engine](../../engines/table-engines/special/join.md)
A
Alexey Milovidov 已提交
496
-   [join_default_strictness](#settings-join_default_strictness)
B
BayoNet 已提交
497

A
Alexey Milovidov 已提交
498
## join_use_nulls {#join_use_nulls}
499

D
Daria Mozhaeva 已提交
500
Sets the type of [JOIN](../../sql-reference/statements/select/join.md) behaviour. When merging tables, empty cells may appear. ClickHouse fills them differently based on this setting.
501

502
Possible values:
503

504
-   0 — The empty cells are filled with the default value of the corresponding field type.
505
-   1 — `JOIN` behaves the same way as in standard SQL. The type of the corresponding field is converted to [Nullable](../../sql-reference/data-types/nullable.md#data_type-nullable), and empty cells are filled with [NULL](../../sql-reference/syntax.md).
506

507 508
Default value: 0.

A
Alexey Milovidov 已提交
509
## partial_merge_join_optimizations {#partial_merge_join_optimizations}
510 511 512

Disables optimizations in partial merge join algorithm for [JOIN](../../sql-reference/statements/select/join.md) queries.

513
By default, this setting enables improvements that could lead to wrong results. If you see suspicious results in your queries, disable optimizations by this setting. Optimizations can be different in different versions of the ClickHouse server.
514 515 516 517 518 519 520 521

Possible values:

-   0 — Optimizations disabled.
-   1 — Optimizations enabled.

Default value: 1.

A
Alexey Milovidov 已提交
522
## partial_merge_join_rows_in_right_blocks {#partial_merge_join_rows_in_right_blocks}
523 524 525 526 527

Limits sizes of right-hand join data blocks in partial merge join algorithm for [JOIN](../../sql-reference/statements/select/join.md) queries.

ClickHouse server:

528
1.  Splits right-hand join data into blocks with up to the specified number of rows.
D
Daria Mozhaeva 已提交
529 530
2.  Indexes each block with its minimum and maximum values.
3.  Unloads prepared blocks to disk if it is possible.
531 532 533

Possible values:

534
-   Any positive integer. Recommended range of values: \[1000, 100000\].
535 536 537

Default value: 65536.

A
Alexey Milovidov 已提交
538
## join_on_disk_max_files_to_merge {#join_on_disk_max_files_to_merge}
539

540
Limits the number of files allowed for parallel sorting in MergeJoin operations when they are executed on disk.
541 542 543 544 545

The bigger the value of the setting, the more RAM used and the less disk I/O needed.

Possible values:

546
-   Any positive integer, starting from 2.
547 548 549

Default value: 64.

A
Alexey Milovidov 已提交
550
## any_join_distinct_right_table_keys {#any_join_distinct_right_table_keys}
551

D
Daria Mozhaeva 已提交
552
Enables legacy ClickHouse server behaviour in `ANY INNER|LEFT JOIN` operations.
553 554

!!! note "Warning"
D
Daria Mozhaeva 已提交
555
    Use this setting only for backward compatibility if your use cases depend on legacy `JOIN` behaviour.
556

D
Daria Mozhaeva 已提交
557
When the legacy behaviour enabled:
558

559 560
-   Results of `t1 ANY LEFT JOIN t2` and `t2 ANY RIGHT JOIN t1` operations are not equal because ClickHouse uses the logic with many-to-one left-to-right table keys mapping.
-   Results of `ANY INNER JOIN` operations contain all rows from the left table like the `SEMI LEFT JOIN` operations do.
561

D
Daria Mozhaeva 已提交
562
When the legacy behaviour disabled:
563

564
-   Results of `t1 ANY LEFT JOIN t2` and `t2 ANY RIGHT JOIN t1` operations are equal because ClickHouse uses the logic which provides one-to-many keys mapping in `ANY RIGHT JOIN` operations.
D
Daria Mozhaeva 已提交
565
-   Results of `ANY INNER JOIN` operations contain one row per key from both the left and right tables.
566 567 568

Possible values:

D
Daria Mozhaeva 已提交
569 570
-   0 — Legacy behaviour is disabled.
-   1 — Legacy behaviour is enabled.
571 572 573 574 575

Default value: 0.

See also:

576
-   [JOIN strictness](../../sql-reference/statements/select/join.md#join-settings)
577

A
Alexey Milovidov 已提交
578
## temporary_files_codec {#temporary_files_codec}
579 580 581

Sets compression codec for temporary files used in sorting and joining operations on disk.

582
Possible values:
583

584 585
-   LZ4 — [LZ4](https://en.wikipedia.org/wiki/LZ4_(compression_algorithm)) compression is applied.
-   NONE — No compression is applied.
586 587 588

Default value: LZ4.

A
Alexey Milovidov 已提交
589
## max_block_size {#setting-max_block_size}
590

591
In ClickHouse, data is processed by blocks (sets of column parts). The internal processing cycles for a single block are efficient enough, but there are noticeable expenditures on each block. The `max_block_size` setting is a recommendation for what size of the block (in a count of rows) to load from tables. The block size shouldn’t be too small, so that the expenditures on each block are still noticeable, but not too large so that the query with LIMIT that is completed after the first block is processed quickly. The goal is to avoid consuming too much memory when extracting a large number of columns in multiple threads and to preserve at least some cache locality.
592

593
Default value: 65,536.
594 595 596

Blocks the size of `max_block_size` are not always loaded from the table. If it is obvious that less data needs to be retrieved, a smaller block is processed.

A
Alexey Milovidov 已提交
597
## preferred_block_size_bytes {#preferred-block-size-bytes}
598 599 600

Used for the same purpose as `max_block_size`, but it sets the recommended block size in bytes by adapting it to the number of rows in the block.
However, the block size cannot be more than `max_block_size` rows.
601
By default: 1,000,000. It only works when reading from MergeTree engines.
602

A
Alexey Milovidov 已提交
603
## merge_tree_min_rows_for_concurrent_read {#setting-merge-tree-min-rows-for-concurrent-read}
B
BayoNet 已提交
604

605
If the number of rows to be read from a file of a [MergeTree](../../engines/table-engines/mergetree-family/mergetree.md) table exceeds `merge_tree_min_rows_for_concurrent_read` then ClickHouse tries to perform a concurrent reading from this file on several threads.
B
BayoNet 已提交
606

607
Possible values:
B
BayoNet 已提交
608

609
-   Any positive integer.
610 611 612

Default value: 163840.

A
Alexey Milovidov 已提交
613
## merge_tree_min_bytes_for_concurrent_read {#setting-merge-tree-min-bytes-for-concurrent-read}
614

615
If the number of bytes to read from one file of a [MergeTree](../../engines/table-engines/mergetree-family/mergetree.md)-engine table exceeds `merge_tree_min_bytes_for_concurrent_read`, then ClickHouse tries to concurrently read from this file in several threads.
616

617
Possible value:
618

619
-   Any positive integer.
B
BayoNet 已提交
620

621
Default value: 251658240.
B
BayoNet 已提交
622

A
Alexey Milovidov 已提交
623
## merge_tree_min_rows_for_seek {#setting-merge-tree-min-rows-for-seek}
B
BayoNet 已提交
624

625
If the distance between two data blocks to be read in one file is less than `merge_tree_min_rows_for_seek` rows, then ClickHouse does not seek through the file but reads the data sequentially.
B
BayoNet 已提交
626

627
Possible values:
B
BayoNet 已提交
628

629
-   Any positive integer.
630 631 632

Default value: 0.

A
Alexey Milovidov 已提交
633
## merge_tree_min_bytes_for_seek {#setting-merge-tree-min-bytes-for-seek}
634

635
If the distance between two data blocks to be read in one file is less than `merge_tree_min_bytes_for_seek` bytes, then ClickHouse sequentially reads a range of file that contains both blocks, thus avoiding extra seek.
636 637 638

Possible values:

639
-   Any positive integer.
640 641

Default value: 0.
B
BayoNet 已提交
642

A
Alexey Milovidov 已提交
643
## merge_tree_coarse_index_granularity {#setting-merge-tree-coarse-index-granularity}
B
BayoNet 已提交
644

645
When searching for data, ClickHouse checks the data marks in the index file. If ClickHouse finds that required keys are in some range, it divides this range into `merge_tree_coarse_index_granularity` subranges and searches the required keys there recursively.
B
BayoNet 已提交
646

647
Possible values:
B
BayoNet 已提交
648

649
-   Any positive even integer.
B
BayoNet 已提交
650

651
Default value: 8.
B
BayoNet 已提交
652

A
Alexey Milovidov 已提交
653
## merge_tree_max_rows_to_use_cache {#setting-merge-tree-max-rows-to-use-cache}
B
BayoNet 已提交
654

655
If ClickHouse should read more than `merge_tree_max_rows_to_use_cache` rows in one query, it doesn’t use the cache of uncompressed blocks.
B
BayoNet 已提交
656

A
Alexey Milovidov 已提交
657
The cache of uncompressed blocks stores data extracted for queries. ClickHouse uses this cache to speed up responses to repeated small queries. This setting protects the cache from trashing by queries that read a large amount of data. The [uncompressed_cache_size](../../operations/server-configuration-parameters/settings.md#server-settings-uncompressed_cache_size) server setting defines the size of the cache of uncompressed blocks.
658 659 660

Possible values:

661
-   Any positive integer.
662 663

Default value: 128 ✕ 8192.
B
BayoNet 已提交
664

A
Alexey Milovidov 已提交
665
## merge_tree_max_bytes_to_use_cache {#setting-merge-tree-max-bytes-to-use-cache}
666

667
If ClickHouse should read more than `merge_tree_max_bytes_to_use_cache` bytes in one query, it doesn’t use the cache of uncompressed blocks.
668

A
Alexey Milovidov 已提交
669
The cache of uncompressed blocks stores data extracted for queries. ClickHouse uses this cache to speed up responses to repeated small queries. This setting protects the cache from trashing by queries that read a large amount of data. The [uncompressed_cache_size](../../operations/server-configuration-parameters/settings.md#server-settings-uncompressed_cache_size) server setting defines the size of the cache of uncompressed blocks.
670

671
Possible value:
672

673
-   Any positive integer.
B
BayoNet 已提交
674

675
Default value: 2013265920.
B
BayoNet 已提交
676

A
Alexey Milovidov 已提交
677
## min_bytes_to_use_direct_io {#settings-min-bytes-to-use-direct-io}
678

679
The minimum data volume required for using direct I/O access to the storage disk.
680

681
ClickHouse uses this setting when reading data from tables. If the total storage volume of all the data to be read exceeds `min_bytes_to_use_direct_io` bytes, then ClickHouse reads the data from the storage disk with the `O_DIRECT` option.
682

S
Fixes  
Sergei Bocharov 已提交
683
Possible values:
684

685 686
-   0 — Direct I/O is disabled.
-   Positive integer.
687

S
Fixes  
Sergei Bocharov 已提交
688
Default value: 0.
689

690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714
## network_compression_method {#network_compression_method}

Sets the method of data compression that is used for communication between servers and between server and [clickhouse-client](../../interfaces/cli.md).

Possible values:

-   `LZ4` — sets LZ4 compression method.
-   `ZSTD` — sets ZSTD compression method.

Default value: `LZ4`.

**See Also**

-   [network_zstd_compression_level](#network_zstd_compression_level)

## network_zstd_compression_level {#network_zstd_compression_level}

Adjusts the level of ZSTD compression. Used only when [network_compression_method](#network_compression_method) is set to `ZSTD`.

Possible values:

-   Positive integer from 1 to 15.

Default value: `1`.

A
Alexey Milovidov 已提交
715
## log_queries {#settings-log-queries}
716

717
Setting up query logging.
718

A
Alexey Milovidov 已提交
719
Queries sent to ClickHouse with this setup are logged according to the rules in the [query_log](../../operations/server-configuration-parameters/settings.md#server_configuration_parameters-query-log) server configuration parameter.
720

S
Fixes  
Sergei Bocharov 已提交
721
Example:
722

723
``` text
S
Fixes  
Sergei Bocharov 已提交
724 725
log_queries=1
```
726

727 728
## log_queries_min_query_duration_ms {#settings-log-queries-min-query-duration-ms}

729
If enabled (non-zero), queries faster then the value of this setting will not be logged (you can think about this as a `long_query_time` for [MySQL Slow Query Log](https://dev.mysql.com/doc/refman/5.7/en/slow-query-log.html)), and this basically means that you will not find them in the following tables:
730 731 732 733 734 735 736 737 738 739 740 741

- `system.query_log`
- `system.query_thread_log`

Only the queries with the following type will get to the log:

- `QUERY_FINISH`
- `EXCEPTION_WHILE_PROCESSING`

-   Type: milliseconds
-   Default value: 0 (any query)

A
Alexey Milovidov 已提交
742
## log_queries_min_type {#settings-log-queries-min-type}
743 744 745 746 747 748 749 750 751 752 753

`query_log` minimal type to log.

Possible values:
- `QUERY_START` (`=1`)
- `QUERY_FINISH` (`=2`)
- `EXCEPTION_BEFORE_START` (`=3`)
- `EXCEPTION_WHILE_PROCESSING` (`=4`)

Default value: `QUERY_START`.

D
Daria Mozhaeva 已提交
754
Can be used to limit which entities will go to `query_log`, say you are interested only in errors, then you can use `EXCEPTION_WHILE_PROCESSING`:
755 756 757 758 759

``` text
log_queries_min_type='EXCEPTION_WHILE_PROCESSING'
```

A
Alexey Milovidov 已提交
760
## log_query_threads {#settings-log-query-threads}
761 762 763

Setting up query threads logging.

A
Alexey Milovidov 已提交
764
Queries’ threads runned by ClickHouse with this setup are logged according to the rules in the [query_thread_log](../../operations/server-configuration-parameters/settings.md#server_configuration_parameters-query_thread_log) server configuration parameter.
765

S
Fixes  
Sergei Bocharov 已提交
766
Example:
767

768
``` text
S
Fixes  
Sergei Bocharov 已提交
769 770
log_query_threads=1
```
771

A
Alexey Milovidov 已提交
772
## max_insert_block_size {#settings-max_insert_block_size}
773

774
The size of blocks (in a count of rows) to form for insertion into a table.
775 776
This setting only applies in cases when the server forms the blocks.
For example, for an INSERT via the HTTP interface, the server parses the data format and forms blocks of the specified size.
A
Alexey Milovidov 已提交
777
But when using clickhouse-client, the client parses the data itself, and the ‘max_insert_block_size’ setting on the server doesn’t affect the size of the inserted blocks.
778
The setting also doesn’t have a purpose when using INSERT SELECT, since data is inserted using the same blocks that are formed after SELECT.
779

780
Default value: 1,048,576.
781

D
Daria Mozhaeva 已提交
782
The default is slightly more than `max_block_size`. The reason for this is because certain table engines (`*MergeTree`) form a data part on the disk for each inserted block, which is a fairly large entity. Similarly, `*MergeTree` tables sort data during insertion, and a large enough block size allow sorting more data in RAM.
783

A
Alexey Milovidov 已提交
784
## min_insert_block_size_rows {#min-insert-block-size-rows}
785

D
Daria Mozhaeva 已提交
786
Sets the minimum number of rows in the block which can be inserted into a table by an `INSERT` query. Smaller-sized blocks are squashed into bigger ones.
787 788 789

Possible values:

790 791
-   Positive integer.
-   0 — Squashing disabled.
792 793 794

Default value: 1048576.

A
Alexey Milovidov 已提交
795
## min_insert_block_size_bytes {#min-insert-block-size-bytes}
796

D
Daria Mozhaeva 已提交
797
Sets the minimum number of bytes in the block which can be inserted into a table by an `INSERT` query. Smaller-sized blocks are squashed into bigger ones.
798 799 800

Possible values:

801 802
-   Positive integer.
-   0 — Squashing disabled.
803 804 805

Default value: 268435456.

A
Alexey Milovidov 已提交
806
## max_replica_delay_for_distributed_queries {#settings-max_replica_delay_for_distributed_queries}
807

808
Disables lagging replicas for distributed queries. See [Replication](../../engines/table-engines/mergetree-family/replication.md).
809 810 811

Sets the time in seconds. If a replica lags more than the set value, this replica is not used.

812
Default value: 300.
813

814
Used when performing `SELECT` from a distributed table that points to replicated tables.
815

A
Alexey Milovidov 已提交
816
## max_threads {#settings-max_threads}
817

A
Alexey Milovidov 已提交
818
The maximum number of query processing threads, excluding threads for retrieving data from remote servers (see the ‘max_distributed_connections’ parameter).
819 820

This parameter applies to threads that perform the same stages of the query processing pipeline in parallel.
A
Alexey Milovidov 已提交
821
For example, when reading from a table, if it is possible to evaluate expressions with functions, filter with WHERE and pre-aggregate for GROUP BY in parallel using at least ‘max_threads’ number of threads, then ‘max_threads’ are used.
822

A
alexey-milovidov 已提交
823
Default value: the number of physical CPU cores.
824 825 826

If less than one SELECT query is normally run on a server at a time, set this parameter to a value slightly less than the actual number of processor cores.

A
Alexey Milovidov 已提交
827
For queries that are completed quickly because of a LIMIT, you can set a lower ‘max_threads’. For example, if the necessary number of entries are located in every block and max_threads = 8, then 8 blocks are retrieved, although it would have been enough to read just one.
828 829 830

The smaller the `max_threads` value, the less memory is consumed.

A
Alexey Milovidov 已提交
831
## max_insert_threads {#settings-max-insert-threads}
D
Denis Zhuravlev 已提交
832 833 834 835 836

The maximum number of threads to execute the `INSERT SELECT` query.

Possible values:

837 838
-   0 (or 1) — `INSERT SELECT` no parallel execution.
-   Positive integer. Bigger than 1.
D
Denis Zhuravlev 已提交
839 840 841

Default value: 0.

A
Alexey Milovidov 已提交
842
Parallel `INSERT SELECT` has effect only if the `SELECT` part is executed in parallel, see [max_threads](#settings-max_threads) setting.
D
Denis Zhuravlev 已提交
843 844
Higher values will lead to higher memory usage.

A
Alexey Milovidov 已提交
845
## max_compress_block_size {#max-compress-block-size}
846

847
The maximum size of blocks of uncompressed data before compressing for writing to a table. By default, 1,048,576 (1 MiB). Specifying smaller block size generally leads to slightly reduced compression ratio, the compression and decompression speed increases slightly due to cache locality, and memory consumption is reduced.
848

849 850
!!! note "Warning"
    This is an expert-level setting, and you shouldn't change it if you're just getting started with Clickhouse.
851

852
Don’t confuse blocks for compression (a chunk of memory consisting of bytes) with blocks for query processing (a set of rows from a table).
853

A
Alexey Milovidov 已提交
854
## min_compress_block_size {#min-compress-block-size}
855

856
For [MergeTree](../../engines/table-engines/mergetree-family/mergetree.md) tables. In order to reduce latency when processing queries, a block is compressed when writing the next mark if its size is at least `min_compress_block_size`. By default, 65,536.
857

858
The actual size of the block, if the uncompressed data is less than `max_compress_block_size`, is no less than this value and no less than the volume of data for one mark.
859

860
Let’s look at an example. Assume that `index_granularity` was set to 8192 during table creation.
861

A
Alexey Milovidov 已提交
862
We are writing a UInt32-type column (4 bytes per value). When writing 8192 rows, the total will be 32 KB of data. Since min_compress_block_size = 65,536, a compressed block will be formed for every two marks.
863

864
We are writing a URL column with the String type (average size of 60 bytes per value). When writing 8192 rows, the average will be slightly less than 500 KB of data. Since this is more than 65,536, a compressed block will be formed for each mark. In this case, when reading data from the disk in the range of a single mark, extra data won’t be decompressed.
865

866 867
!!! note "Warning"
    This is an expert-level setting, and you shouldn't change it if you're just getting started with Clickhouse.
868

A
Alexey Milovidov 已提交
869
## max_query_size {#settings-max_query_size}
870 871 872 873

The maximum part of a query that can be taken to RAM for parsing with the SQL parser.
The INSERT query also contains data for INSERT that is processed by a separate stream parser (that consumes O(1) RAM), which is not included in this restriction.

874
Default value: 256 KiB.
875

A
Alexey Milovidov 已提交
876
## max_parser_depth {#max_parser_depth}
B
BayoNet 已提交
877

D
Daria Mozhaeva 已提交
878
Limits maximum recursion depth in the recursive descent parser. Allows controlling the stack size.
B
BayoNet 已提交
879 880 881

Possible values:

882 883
-   Positive integer.
-   0 — Recursion depth is unlimited.
B
BayoNet 已提交
884 885 886

Default value: 1000.

A
Alexey Milovidov 已提交
887
## interactive_delay {#interactive-delay}
888

889
The interval in microseconds for checking whether request execution has been cancelled and sending the progress.
890

891
Default value: 100,000 (checks for cancelling and sends the progress ten times per second).
892

A
Alexey Milovidov 已提交
893
## connect_timeout, receive_timeout, send_timeout {#connect-timeout-receive-timeout-send-timeout}
894 895 896

Timeouts in seconds on the socket used for communicating with the client.

897
Default value: 10, 300, 300.
898

A
Alexey Milovidov 已提交
899
## cancel_http_readonly_queries_on_client_close {#cancel-http-readonly-queries-on-client-close}
900

901
Cancels HTTP read-only queries (e.g. SELECT) when a client closes the connection without waiting for the response.
902 903 904

Default value: 0

A
Alexey Milovidov 已提交
905
## poll_interval {#poll-interval}
906 907 908

Lock in a wait loop for the specified number of seconds.

909
Default value: 10.
910

A
Alexey Milovidov 已提交
911
## max_distributed_connections {#max-distributed-connections}
912 913 914

The maximum number of simultaneous connections with remote servers for distributed processing of a single query to a single Distributed table. We recommend setting a value no less than the number of servers in the cluster.

915
Default value: 1024.
916 917 918

The following parameters are only used when creating Distributed tables (and when launching a server), so there is no reason to change them at runtime.

A
Alexey Milovidov 已提交
919
## distributed_connections_pool_size {#distributed-connections-pool-size}
920 921 922

The maximum number of simultaneous connections with remote servers for distributed processing of all queries to a single Distributed table. We recommend setting a value no less than the number of servers in the cluster.

923
Default value: 1024.
924

A
Alexey Milovidov 已提交
925
## connect_timeout_with_failover_ms {#connect-timeout-with-failover-ms}
926

927
The timeout in milliseconds for connecting to a remote server for a Distributed table engine, if the ‘shard’ and ‘replica’ sections are used in the cluster definition.
928 929
If unsuccessful, several attempts are made to connect to various replicas.

930
Default value: 50.
931

A
Alexey Milovidov 已提交
932
## connection_pool_max_wait_ms {#connection-pool-max-wait-ms}
B
BayoNet 已提交
933 934 935 936 937 938 939 940 941 942

The wait time in milliseconds for a connection when the connection pool is full.

Possible values:

- Positive integer.
- 0 — Infinite timeout.

Default value: 0.

A
Alexey Milovidov 已提交
943
## connections_with_failover_max_tries {#connections-with-failover-max-tries}
944

945
The maximum number of connection attempts with each replica for the Distributed table engine.
946

947
Default value: 3.
948

949
## extremes {#extremes}
950 951

Whether to count extreme values (the minimums and maximums in columns of a query result). Accepts 0 or 1. By default, 0 (disabled).
952
For more information, see the section “Extreme values”.
953

A
Alexey Milovidov 已提交
954
## kafka_max_wait_ms {#kafka-max-wait-ms}
B
BayoNet 已提交
955 956 957 958 959 960 961 962 963 964 965 966 967 968

The wait time in milliseconds for reading messages from [Kafka](../../engines/table-engines/integrations/kafka.md#kafka) before retry.

Possible values:

- Positive integer.
- 0 — Infinite timeout.

Default value: 5000.

See also:

-   [Apache Kafka](https://kafka.apache.org/)

A
Alexey Milovidov 已提交
969
## use_uncompressed_cache {#setting-use_uncompressed_cache}
970

971
Whether to use a cache of uncompressed blocks. Accepts 0 or 1. By default, 0 (disabled).
A
Alexey Milovidov 已提交
972
Using the uncompressed cache (only for tables in the MergeTree family) can significantly reduce latency and increase throughput when working with a large number of short queries. Enable this setting for users who send frequent short requests. Also pay attention to the [uncompressed_cache_size](../../operations/server-configuration-parameters/settings.md#server-settings-uncompressed_cache_size) configuration parameter (only set in the config file) – the size of uncompressed cache blocks. By default, it is 8 GiB. The uncompressed cache is filled in as needed and the least-used data is automatically deleted.
973

A
Alexey Milovidov 已提交
974
For queries that read at least a somewhat large volume of data (one million rows or more), the uncompressed cache is disabled automatically to save space for truly small queries. This means that you can keep the ‘use_uncompressed_cache’ setting always set to 1.
975

A
Alexey Milovidov 已提交
976
## replace_running_query {#replace-running-query}
977

A
Alexey Milovidov 已提交
978 979
When using the HTTP interface, the ‘query_id’ parameter can be passed. This is any string that serves as the query identifier.
If a query from the same user with the same ‘query_id’ already exists at this time, the behaviour depends on the ‘replace_running_query’ parameter.
980

A
Alexey Milovidov 已提交
981
`0` (default) – Throw an exception (don’t allow the query to run if a query with the same ‘query_id’ is already running).
982 983 984

`1` – Cancel the old query and start running the new one.

985
Yandex.Metrica uses this parameter set to 1 for implementing suggestions for segmentation conditions. After entering the next character, if the old query hasn’t finished yet, it should be cancelled.
986

A
Alexey Milovidov 已提交
987
## replace_running_query_max_wait_ms {#replace-running-query-max-wait-ms}
B
BayoNet 已提交
988

D
Daria Mozhaeva 已提交
989
The wait time for running the query with the same `query_id` to finish, when the [replace_running_query](#replace-running-query) setting is active.
B
BayoNet 已提交
990 991 992 993

Possible values:

- Positive integer.
D
Daria Mozhaeva 已提交
994
- 0 — Throwing an exception that does not allow to run a new query if the server already executes a query with the same `query_id`.
B
BayoNet 已提交
995 996 997

Default value: 5000.

A
Alexey Milovidov 已提交
998
## stream_flush_interval_ms {#stream-flush-interval-ms}
999

A
Alexey Milovidov 已提交
1000
Works for tables with streaming in the case of a timeout, or when a thread generates [max_insert_block_size](#settings-max_insert_block_size) rows.
1001 1002 1003 1004 1005

The default value is 7500.

The smaller the value, the more often data is flushed into the table. Setting the value too low leads to poor performance.

A
Alexey Milovidov 已提交
1006
## load_balancing {#settings-load_balancing}
1007

1008
Specifies the algorithm of replicas selection that is used for distributed query processing.
1009

1010
ClickHouse supports the following algorithms of choosing replicas:
1011

1012 1013 1014 1015
-   [Random](#load_balancing-random) (by default)
-   [Nearest hostname](#load_balancing-nearest_hostname)
-   [In order](#load_balancing-in_order)
-   [First or random](#load_balancing-first_or_random)
A
Azat Khuzhin 已提交
1016
-   [Round robin](#load_balancing-round_robin)
1017

1018 1019
See also:

A
Alexey Milovidov 已提交
1020
-   [distributed_replica_max_ignored_errors](#settings-distributed_replica_max_ignored_errors)
1021

I
Ivan Blinkov 已提交
1022
### Random (by Default) {#load_balancing-random}
1023

1024
``` sql
1025 1026
load_balancing = random
```
1027

1028
The number of errors is counted for each replica. The query is sent to the replica with the fewest errors, and if there are several of these, to anyone of them.
1029 1030
Disadvantages: Server proximity is not accounted for; if the replicas have different data, you will also get different data.

1031
### Nearest Hostname {#load_balancing-nearest_hostname}
1032

1033
``` sql
1034 1035
load_balancing = nearest_hostname
```
1036

1037
The number of errors is counted for each replica. Every 5 minutes, the number of errors is integrally divided by 2. Thus, the number of errors is calculated for a recent time with exponential smoothing. If there is one replica with a minimal number of errors (i.e. errors occurred recently on the other replicas), the query is sent to it. If there are multiple replicas with the same minimal number of errors, the query is sent to the replica with a hostname that is most similar to the server’s hostname in the config file (for the number of different characters in identical positions, up to the minimum length of both hostnames).
1038 1039

For instance, example01-01-1 and example01-01-2.yandex.ru are different in one position, while example01-01-1 and example01-02-2 differ in two places.
1040
This method might seem primitive, but it doesn’t require external data about network topology, and it doesn’t compare IP addresses, which would be complicated for our IPv6 addresses.
1041 1042 1043 1044

Thus, if there are equivalent replicas, the closest one by name is preferred.
We can also assume that when sending a query to the same server, in the absence of failures, a distributed query will also go to the same servers. So even if different data is placed on the replicas, the query will return mostly the same results.

1045
### In Order {#load_balancing-in_order}
1046

1047
``` sql
1048 1049
load_balancing = in_order
```
1050

1051
Replicas with the same number of errors are accessed in the same order as they are specified in the configuration.
1052 1053
This method is appropriate when you know exactly which replica is preferable.

1054
### First or Random {#load_balancing-first_or_random}
1055

1056
``` sql
1057 1058 1059
load_balancing = first_or_random
```

1060
This algorithm chooses the first replica in the set or a random replica if the first is unavailable. It’s effective in cross-replication topology setups, but useless in other configurations.
1061

1062
The `first_or_random` algorithm solves the problem of the `in_order` algorithm. With `in_order`, if one replica goes down, the next one gets a double load while the remaining replicas handle the usual amount of traffic. When using the `first_or_random` algorithm, the load is evenly distributed among replicas that are still available.
1063

1064 1065
It's possible to explicitly define what the first replica is by using the setting `load_balancing_first_offset`. This gives more control to rebalance query workloads among replicas.

1066
### Round Robin {#load_balancing-round_robin}
A
Azat Khuzhin 已提交
1067 1068 1069 1070 1071

``` sql
load_balancing = round_robin
```

D
Daria Mozhaeva 已提交
1072
This algorithm uses a round-robin policy across replicas with the same number of errors (only the queries with `round_robin` policy is accounted).
A
Azat Khuzhin 已提交
1073

A
Alexey Milovidov 已提交
1074
## prefer_localhost_replica {#settings-prefer-localhost-replica}
1075 1076 1077 1078 1079

Enables/disables preferable using the localhost replica when processing distributed queries.

Possible values:

1080
-   1 — ClickHouse always sends a query to the localhost replica if it exists.
A
Alexey Milovidov 已提交
1081
-   0 — ClickHouse uses the balancing strategy specified by the [load_balancing](#settings-load_balancing) setting.
1082 1083 1084

Default value: 1.

1085
!!! warning "Warning"
A
Alexey Milovidov 已提交
1086
    Disable this setting if you use [max_parallel_replicas](#settings-max_parallel_replicas).
1087

A
Alexey Milovidov 已提交
1088
## totals_mode {#totals-mode}
1089

A
Alexey Milovidov 已提交
1090
How to calculate TOTALS when HAVING is present, as well as when max_rows_to_group_by and group_by_overflow_mode = ‘any’ are present.
1091
See the section “WITH TOTALS modifier”.
1092

A
Alexey Milovidov 已提交
1093
## totals_auto_threshold {#totals-auto-threshold}
1094

1095
The threshold for `totals_mode = 'auto'`.
1096
See the section “WITH TOTALS modifier”.
1097

A
Alexey Milovidov 已提交
1098
## max_parallel_replicas {#settings-max_parallel_replicas}
1099

1100 1101 1102 1103 1104 1105 1106 1107
The maximum number of replicas for each shard when executing a query. In limited circumstances, this can make a query faster by executing it on more servers. This setting is only useful for replicated tables with a sampling key. There are cases where performance will not improve or even worsen:

- the position of the sampling key in the partitioning key's order doesn't allow efficient range scans
- adding a sampling key to the table makes filtering by other columns less efficient
- the sampling key is an expression that is expensive to calculate
- the cluster's latency distribution has a long tail, so that querying more servers increases the query's overall latency

In addition, this setting will produce incorrect results when joins or subqueries are involved, and all tables don't meet certain conditions. See [Distributed Subqueries and max_parallel_replicas](../../sql-reference/operators/in.md/#max_parallel_replica-subqueries) for more details.
1108

1109
## compile {#compile}
1110 1111 1112

Enable compilation of queries. By default, 0 (disabled).

1113
The compilation is only used for part of the query-processing pipeline: for the first stage of aggregation (GROUP BY).
D
Daria Mozhaeva 已提交
1114
If this portion of the pipeline was compiled, the query may run faster due to the deployment of short cycles and inlining aggregate function calls. The maximum performance improvement (up to four times faster in rare cases) is seen for queries with multiple simple aggregate functions. Typically, the performance gain is insignificant. In very rare cases, it may slow down query execution.
1115

A
Alexey Milovidov 已提交
1116
## min_count_to_compile {#min-count-to-compile}
1117 1118

How many times to potentially use a compiled chunk of code before running compilation. By default, 3.
1119 1120
For testing, the value can be set to 0: compilation runs synchronously and the query waits for the end of the compilation process before continuing execution. For all other cases, use values ​​starting with 1. Compilation normally takes about 5-10 seconds.
If the value is 1 or more, compilation occurs asynchronously in a separate thread. The result will be used as soon as it is ready, including queries that are currently running.
1121 1122

Compiled code is required for each different combination of aggregate functions used in the query and the type of keys in the GROUP BY clause.
1123
The results of the compilation are saved in the build directory in the form of .so files. There is no restriction on the number of compilation results since they don’t use very much space. Old results will be used after server restarts, except in the case of a server upgrade – in this case, the old results are deleted.
1124

A
Alexey Milovidov 已提交
1125
## output_format_json_quote_64bit_integers {#session_settings-output_format_json_quote_64bit_integers}
1126

1127
If the value is true, integers appear in quotes when using JSON\* Int64 and UInt64 formats (for compatibility with most JavaScript implementations); otherwise, integers are output without the quotes.
I
Ivan Zhukov 已提交
1128

A
Alexey Milovidov 已提交
1129
## output_format_json_quote_denormals {#settings-output_format_json_quote_denormals}
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227

Enables `+nan`, `-nan`, `+inf`, `-inf` outputs in [JSON](../../interfaces/formats.md#json) output format.

Possible values:

-   0 — Disabled.
-   1 — Enabled.

Default value: 0.

**Example**

Consider the following table `account_orders`:

```text
┌─id─┬─name───┬─duration─┬─period─┬─area─┐
│  1 │ Andrew │       20 │      0 │  400 │
│  2 │ John   │       40 │      0 │    0 │
│  3 │ Bob    │       15 │      0 │ -100 │
└────┴────────┴──────────┴────────┴──────┘
```

When `output_format_json_quote_denormals = 0`, the query returns `null` values in output:

```sql
SELECT area/period FROM account_orders FORMAT JSON;
```

```json
{
        "meta":
        [
                {
                        "name": "divide(area, period)",
                        "type": "Float64"
                }
        ],

        "data":
        [
                {
                        "divide(area, period)": null
                },
                {
                        "divide(area, period)": null
                },
                {
                        "divide(area, period)": null
                }
        ],

        "rows": 3,

        "statistics":
        {
                "elapsed": 0.003648093,
                "rows_read": 3,
                "bytes_read": 24
        }
}
```

When `output_format_json_quote_denormals = 1`, the query returns:

```json
{
        "meta":
        [
                {
                        "name": "divide(area, period)",
                        "type": "Float64"
                }
        ],

        "data":
        [
                {
                        "divide(area, period)": "inf"
                },
                {
                        "divide(area, period)": "-nan"
                },
                {
                        "divide(area, period)": "-inf"
                }
        ],

        "rows": 3,

        "statistics":
        {
                "elapsed": 0.000070241,
                "rows_read": 3,
                "bytes_read": 24
        }
}
```

A
Alexey Milovidov 已提交
1228
## format_csv_delimiter {#settings-format_csv_delimiter}
I
Ivan Zhukov 已提交
1229

D
Daria Mozhaeva 已提交
1230
The character is interpreted as a delimiter in the CSV data. By default, the delimiter is `,`.
1231

A
Alexey Milovidov 已提交
1232
## input_format_csv_unquoted_null_literal_as_null {#settings-input_format_csv_unquoted_null_literal_as_null}
A
Alexander Tokmakov 已提交
1233 1234 1235

For CSV input format enables or disables parsing of unquoted `NULL` as literal (synonym for `\N`).

1236
## input_format_csv_enum_as_number {#settings-input_format_csv_enum_as_number}
1237

A
Fixed  
annvsh 已提交
1238
Enables or disables parsing enum values as enum ids for CSV input format.
A
annvsh 已提交
1239 1240 1241

Possible values:

A
Fixed  
annvsh 已提交
1242 1243
-   0 — Enum values are parsed as values.
-   1 — Enum values are parsed as enum IDs.
A
annvsh 已提交
1244 1245 1246

Default value: 0.

A
Fixed  
annvsh 已提交
1247
**Examples**
A
annvsh 已提交
1248

A
Fixed  
annvsh 已提交
1249
Consider the table:
A
annvsh 已提交
1250 1251

```sql
A
Fixed  
annvsh 已提交
1252 1253
CREATE TABLE table_with_enum_column_for_csv_insert (Id Int32,Value Enum('first' = 1, 'second' = 2)) ENGINE=Memory();
```
A
annvsh 已提交
1254

1255
When the `input_format_csv_enum_as_number` setting is enabled:
A
annvsh 已提交
1256

A
Fixed  
annvsh 已提交
1257
```sql
A
annvsh 已提交
1258 1259 1260 1261 1262 1263 1264 1265
SET input_format_csv_enum_as_number = 1;
INSERT INTO table_with_enum_column_for_csv_insert FORMAT CSV 102,2;
SELECT * FROM table_with_enum_column_for_csv_insert;
```

Result:

```text
A
Fixed  
annvsh 已提交
1266 1267 1268
┌──Id─┬─Value─────┐
│ 102 │ second    │
└─────┴───────────┘
A
annvsh 已提交
1269
```
1270

A
Fixed  
annvsh 已提交
1271 1272 1273 1274 1275 1276 1277 1278
When the `input_format_csv_enum_as_number` setting is disabled, the `INSERT` query:

```sql
SET input_format_csv_enum_as_number = 0;
INSERT INTO table_with_enum_column_for_csv_insert FORMAT CSV 102,2;
```

throws an exception.
1279

A
Alexey Milovidov 已提交
1280
## output_format_csv_crlf_end_of_line {#settings-output-format-csv-crlf-end-of-line}
M
Mikhail Korotov 已提交
1281

1282
Use DOS/Windows-style line separator (CRLF) in CSV instead of Unix style (LF).
M
Mikhail Korotov 已提交
1283

A
Alexey Milovidov 已提交
1284
## output_format_tsv_crlf_end_of_line {#settings-output-format-tsv-crlf-end-of-line}
M
millb 已提交
1285

1286
Use DOC/Windows-style line separator (CRLF) in TSV instead of Unix style (LF).
M
millb 已提交
1287

A
Alexey Milovidov 已提交
1288
## insert_quorum {#settings-insert_quorum}
1289

1290
Enables the quorum writes.
1291

1292 1293
-   If `insert_quorum < 2`, the quorum writes are disabled.
-   If `insert_quorum >= 2`, the quorum writes are enabled.
1294

1295
Default value: 0.
1296

S
Fixes  
Sergei Bocharov 已提交
1297
Quorum writes
1298 1299 1300 1301 1302

`INSERT` succeeds only when ClickHouse manages to correctly write data to the `insert_quorum` of replicas during the `insert_quorum_timeout`. If for any reason the number of replicas with successful writes does not reach the `insert_quorum`, the write is considered failed and ClickHouse will delete the inserted block from all the replicas where data has already been written.

All the replicas in the quorum are consistent, i.e., they contain data from all previous `INSERT` queries. The `INSERT` sequence is linearized.

A
Alexey Milovidov 已提交
1303
When reading the data written from the `insert_quorum`, you can use the [select_sequential_consistency](#settings-select_sequential_consistency) option.
1304

S
Fixes  
Sergei Bocharov 已提交
1305
ClickHouse generates an exception
1306

1307 1308
-   If the number of available replicas at the time of the query is less than the `insert_quorum`.
-   At an attempt to write data when the previous block has not yet been inserted in the `insert_quorum` of replicas. This situation may occur if the user tries to perform an `INSERT` before the previous one with the `insert_quorum` is completed.
1309

S
Fixes  
Sergei Bocharov 已提交
1310
See also:
1311

A
Alexey Milovidov 已提交
1312 1313
-   [insert_quorum_timeout](#settings-insert_quorum_timeout)
-   [select_sequential_consistency](#settings-select_sequential_consistency)
1314

A
Alexey Milovidov 已提交
1315
## insert_quorum_timeout {#settings-insert_quorum_timeout}
1316

1317
Write to a quorum timeout in milliseconds. If the timeout has passed and no write has taken place yet, ClickHouse will generate an exception and the client must repeat the query to write the same block to the same or any other replica.
1318

1319
Default value: 600 000 milliseconds (ten minutes).
1320

S
Fixes  
Sergei Bocharov 已提交
1321
See also:
1322

A
Alexey Milovidov 已提交
1323 1324
-   [insert_quorum](#settings-insert_quorum)
-   [select_sequential_consistency](#settings-select_sequential_consistency)
1325

A
Alexey Milovidov 已提交
1326
## select_sequential_consistency {#settings-select_sequential_consistency}
1327

1328 1329 1330
Enables or disables sequential consistency for `SELECT` queries:

Possible values:
1331

1332 1333
-   0 — Disabled.
-   1 — Enabled.
1334

1335
Default value: 0.
1336

S
Fixes  
Sergei Bocharov 已提交
1337
Usage
1338

1339 1340
When sequential consistency is enabled, ClickHouse allows the client to execute the `SELECT` query only for those replicas that contain data from all previous `INSERT` queries executed with `insert_quorum`. If the client refers to a partial replica, ClickHouse will generate an exception. The SELECT query will not include data that has not yet been written to the quorum of replicas.

S
Fixes  
Sergei Bocharov 已提交
1341
See also:
1342

A
Alexey Milovidov 已提交
1343 1344
-   [insert_quorum](#settings-insert_quorum)
-   [insert_quorum_timeout](#settings-insert_quorum_timeout)
1345

A
Alexey Milovidov 已提交
1346
## insert_deduplicate {#settings-insert-deduplicate}
D
Denis Zhuravlev 已提交
1347

1348
Enables or disables block deduplication of `INSERT` (for Replicated\* tables).
D
Denis Zhuravlev 已提交
1349 1350 1351

Possible values:

1352 1353
-   0 — Disabled.
-   1 — Enabled.
D
Denis Zhuravlev 已提交
1354 1355 1356

Default value: 1.

F
Fan() 已提交
1357 1358
By default, blocks inserted into replicated tables by the `INSERT` statement are deduplicated (see [Data Replication](../../engines/table-engines/mergetree-family/replication.md)).

A
Alexey Milovidov 已提交
1359
## deduplicate_blocks_in_dependent_materialized_views {#settings-deduplicate-blocks-in-dependent-materialized-views}
D
Denis Zhuravlev 已提交
1360

1361
Enables or disables the deduplication check for materialized views that receive data from Replicated\* tables.
D
Denis Zhuravlev 已提交
1362 1363 1364

Possible values:

1365 1366
      0 — Disabled.
      1 — Enabled.
D
Denis Zhuravlev 已提交
1367 1368 1369 1370 1371

Default value: 0.

Usage

1372
By default, deduplication is not performed for materialized views but is done upstream, in the source table.
D
Daria Mozhaeva 已提交
1373 1374
If an INSERTed block is skipped due to deduplication in the source table, there will be no insertion into attached materialized views. This behaviour exists to enable the insertion of highly aggregated data into materialized views, for cases where inserted blocks are the same after materialized view aggregation but derived from different INSERTs into the source table.
At the same time, this behaviour “breaks” `INSERT` idempotency. If an `INSERT` into the main table was successful and `INSERT` into a materialized view failed (e.g. because of communication failure with Zookeeper) a client will get an error and can retry the operation. However, the materialized view won’t receive the second insert because it will be discarded by deduplication in the main (source) table. The setting `deduplicate_blocks_in_dependent_materialized_views` allows for changing this behaviour. On retry, a materialized view will receive the repeat insert and will perform a deduplication check by itself,
1375
ignoring check result for the source table, and will insert rows lost because of the first failure.
D
Denis Zhuravlev 已提交
1376

A
Alexey Milovidov 已提交
1377
## max_network_bytes {#settings-max-network-bytes}
1378

1379
Limits the data volume (in bytes) that is received or transmitted over the network when executing a query. This setting applies to every individual query.
1380 1381 1382

Possible values:

1383 1384
-   Positive integer.
-   0 — Data volume control is disabled.
1385 1386 1387

Default value: 0.

A
Alexey Milovidov 已提交
1388
## max_network_bandwidth {#settings-max-network-bandwidth}
1389

1390
Limits the speed of the data exchange over the network in bytes per second. This setting applies to every query.
1391 1392 1393

Possible values:

1394 1395
-   Positive integer.
-   0 — Bandwidth control is disabled.
1396 1397 1398

Default value: 0.

A
Alexey Milovidov 已提交
1399
## max_network_bandwidth_for_user {#settings-max-network-bandwidth-for-user}
1400

1401
Limits the speed of the data exchange over the network in bytes per second. This setting applies to all concurrently running queries performed by a single user.
1402 1403 1404

Possible values:

1405 1406
-   Positive integer.
-   0 — Control of the data speed is disabled.
1407 1408 1409

Default value: 0.

A
Alexey Milovidov 已提交
1410
## max_network_bandwidth_for_all_users {#settings-max-network-bandwidth-for-all-users}
1411

1412
Limits the speed that data is exchanged at over the network in bytes per second. This setting applies to all concurrently running queries on the server.
1413 1414 1415

Possible values:

1416 1417
-   Positive integer.
-   0 — Control of the data speed is disabled.
1418 1419 1420

Default value: 0.

A
Alexey Milovidov 已提交
1421
## count_distinct_implementation {#settings-count_distinct_implementation}
1422

1423
Specifies which of the `uniq*` functions should be used to perform the [COUNT(DISTINCT …)](../../sql-reference/aggregate-functions/reference/count.md#agg_function-count) construction.
1424 1425 1426

Possible values:

1427 1428 1429 1430 1431
-   [uniq](../../sql-reference/aggregate-functions/reference/uniq.md#agg_function-uniq)
-   [uniqCombined](../../sql-reference/aggregate-functions/reference/uniqcombined.md#agg_function-uniqcombined)
-   [uniqCombined64](../../sql-reference/aggregate-functions/reference/uniqcombined64.md#agg_function-uniqcombined64)
-   [uniqHLL12](../../sql-reference/aggregate-functions/reference/uniqhll12.md#agg_function-uniqhll12)
-   [uniqExact](../../sql-reference/aggregate-functions/reference/uniqexact.md#agg_function-uniqexact)
1432 1433

Default value: `uniqExact`.
I
Ivan Blinkov 已提交
1434

A
Alexey Milovidov 已提交
1435
## skip_unavailable_shards {#settings-skip_unavailable_shards}
1436

1437
Enables or disables silently skipping of unavailable shards.
1438

1439
Shard is considered unavailable if all its replicas are unavailable. A replica is unavailable in the following cases:
1440

1441
-   ClickHouse can’t connect to replica for any reason.
1442

1443
    When connecting to a replica, ClickHouse performs several attempts. If all these attempts fail, the replica is considered unavailable.
1444

1445
-   Replica can’t be resolved through DNS.
1446

1447
    If replica’s hostname can’t be resolved through DNS, it can indicate the following situations:
1448

1449
    -   Replica’s host has no DNS record. It can occur in systems with dynamic DNS, for example, [Kubernetes](https://kubernetes.io), where nodes can be unresolvable during downtime, and this is not an error.
1450

1451
    -   Configuration error. ClickHouse configuration file contains a wrong hostname.
1452 1453 1454

Possible values:

1455
-   1 — skipping enabled.
1456

1457
    If a shard is unavailable, ClickHouse returns a result based on partial data and doesn’t report node availability issues.
1458

1459
-   0 — skipping disabled.
1460

1461
    If a shard is unavailable, ClickHouse throws an exception.
1462

1463 1464
Default value: 0.

A
Alexey Milovidov 已提交
1465
## distributed_group_by_no_merge {#distributed-group-by-no-merge}
1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505

Do not merge aggregation states from different servers for distributed query processing, you can use this in case it is for certain that there are different keys on different shards

Possible values:

-   0 — Disabled (final query processing is done on the initiator node).
-   1 - Do not merge aggregation states from different servers for distributed query processing (query completelly processed on the shard, initiator only proxy the data).
-   2 - Same as 1 but apply `ORDER BY` and `LIMIT` on the initiator (can be used for queries with `ORDER BY` and/or `LIMIT`).

**Example**

```sql
SELECT *
FROM remote('127.0.0.{2,3}', system.one)
GROUP BY dummy
LIMIT 1
SETTINGS distributed_group_by_no_merge = 1
FORMAT PrettyCompactMonoBlock

┌─dummy─┐
     0 
     0 
└───────┘
```

```sql
SELECT *
FROM remote('127.0.0.{2,3}', system.one)
GROUP BY dummy
LIMIT 1
SETTINGS distributed_group_by_no_merge = 2
FORMAT PrettyCompactMonoBlock

┌─dummy─┐
     0 
└───────┘
```

Default value: 0

A
Alexey Milovidov 已提交
1506
## optimize_skip_unused_shards {#optimize-skip-unused-shards}
1507

1508 1509 1510 1511
Enables or disables skipping of unused shards for [SELECT](../../sql-reference/statements/select/index.md) queries that have sharding key condition in `WHERE/PREWHERE` (assuming that the data is distributed by sharding key, otherwise does nothing).

Possible values:

1512 1513
-   0 — Disabled.
-   1 — Enabled.
1514 1515 1516

Default value: 0

1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527
## allow_nondeterministic_optimize_skip_unused_shards {#allow-nondeterministic-optimize-skip-unused-shards}

Allow nondeterministic (like `rand` or `dictGet`, since later has some caveats with updates) functions in sharding key.

Possible values:

-   0 — Disallowed.
-   1 — Allowed.

Default value: 0

A
Alexey Milovidov 已提交
1528
## optimize_skip_unused_shards_nesting {#optimize-skip-unused-shards-nesting}
1529

A
Azat Khuzhin 已提交
1530
Controls [`optimize_skip_unused_shards`](#optimize-skip-unused-shards) (hence still requires [`optimize_skip_unused_shards`](#optimize-skip-unused-shards)) depends on the nesting level of the distributed query (case when you have `Distributed` table that look into another `Distributed` table).
1531 1532 1533

Possible values:

A
Azat Khuzhin 已提交
1534 1535 1536
-   0 — Disabled, `optimize_skip_unused_shards` works always.
-   1 — Enables `optimize_skip_unused_shards` only for the first level.
-   2 — Enables `optimize_skip_unused_shards` up to the second level.
1537 1538 1539

Default value: 0

A
Alexey Milovidov 已提交
1540
## force_optimize_skip_unused_shards {#force-optimize-skip-unused-shards}
1541

A
Alexey Milovidov 已提交
1542
Enables or disables query execution if [optimize_skip_unused_shards](#optimize-skip-unused-shards) is enabled and skipping of unused shards is not possible. If the skipping is not possible and the setting is enabled, an exception will be thrown.
1543 1544 1545

Possible values:

1546
-   0 — Disabled. ClickHouse doesn’t throw an exception.
1547 1548
-   1 — Enabled. Query execution is disabled only if the table has a sharding key.
-   2 — Enabled. Query execution is disabled regardless of whether a sharding key is defined for the table.
1549 1550 1551

Default value: 0

A
Alexey Milovidov 已提交
1552
## force_optimize_skip_unused_shards_nesting {#settings-force_optimize_skip_unused_shards_nesting}
1553

A
Azat Khuzhin 已提交
1554
Controls [`force_optimize_skip_unused_shards`](#force-optimize-skip-unused-shards) (hence still requires [`force_optimize_skip_unused_shards`](#force-optimize-skip-unused-shards)) depends on the nesting level of the distributed query (case when you have `Distributed` table that look into another `Distributed` table).
1555 1556 1557

Possible values:

A
Azat Khuzhin 已提交
1558 1559 1560
-   0 - Disabled, `force_optimize_skip_unused_shards` works always.
-   1 — Enables `force_optimize_skip_unused_shards` only for the first level.
-   2 — Enables `force_optimize_skip_unused_shards` up to the second level.
1561

A
Azat Khuzhin 已提交
1562
Default value: 0
1563

A
Alexey Milovidov 已提交
1564
## optimize_distributed_group_by_sharding_key {#optimize-distributed-group-by-sharding-key}
1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591

Optimize `GROUP BY sharding_key` queries, by avoiding costly aggregation on the initiator server (which will reduce memory usage for the query on the initiator server).

The following types of queries are supported (and all combinations of them):

- `SELECT DISTINCT [..., ]sharding_key[, ...] FROM dist`
- `SELECT ... FROM dist GROUP BY sharding_key[, ...]`
- `SELECT ... FROM dist GROUP BY sharding_key[, ...] ORDER BY x`
- `SELECT ... FROM dist GROUP BY sharding_key[, ...] LIMIT 1`
- `SELECT ... FROM dist GROUP BY sharding_key[, ...] LIMIT 1 BY x`

The following types of queries are not supported (support for some of them may be added later):

- `SELECT ... GROUP BY sharding_key[, ...] WITH TOTALS`
- `SELECT ... GROUP BY sharding_key[, ...] WITH ROLLUP`
- `SELECT ... GROUP BY sharding_key[, ...] WITH CUBE`
- `SELECT ... GROUP BY sharding_key[, ...] SETTINGS extremes=1`

Possible values:

-   0 — Disabled.
-   1 — Enabled.

Default value: 0

See also:

A
Alexey Milovidov 已提交
1592 1593
-   [distributed_group_by_no_merge](#distributed-group-by-no-merge)
-   [optimize_skip_unused_shards](#optimize-skip-unused-shards)
1594 1595 1596 1597

!!! note "Note"
    Right now it requires `optimize_skip_unused_shards` (the reason behind this is that one day it may be enabled by default, and it will work correctly only if data was inserted via Distributed table, i.e. data is distributed according to sharding_key).

A
Alexey Milovidov 已提交
1598
## optimize_throw_if_noop {#setting-optimize_throw_if_noop}
1599

1600
Enables or disables throwing an exception if an [OPTIMIZE](../../sql-reference/statements/misc.md#misc_operations-optimize) query didn’t perform a merge.
1601

1602
By default, `OPTIMIZE` returns successfully even if it didn’t do anything. This setting lets you differentiate these situations and get the reason in an exception message.
1603 1604 1605

Possible values:

1606 1607
-   1 — Throwing an exception is enabled.
-   0 — Throwing an exception is disabled.
1608 1609

Default value: 0.
1610

A
Alexey Milovidov 已提交
1611
## distributed_replica_error_half_life {#settings-distributed_replica_error_half_life}
V
Vasily Nemkov 已提交
1612

1613 1614
-   Type: seconds
-   Default value: 60 seconds
V
Vasily Nemkov 已提交
1615

A
Alexey Milovidov 已提交
1616
Controls how fast errors in distributed tables are zeroed. If a replica is unavailable for some time, accumulates 5 errors, and distributed_replica_error_half_life is set to 1 second, then the replica is considered normal 3 seconds after the last error.
V
Vasily Nemkov 已提交
1617

S
Fixes  
Sergei Bocharov 已提交
1618
See also:
V
Vasily Nemkov 已提交
1619

A
Alexey Milovidov 已提交
1620
-   [load_balancing](#load_balancing-round_robin)
1621
-   [Table engine Distributed](../../engines/table-engines/special/distributed.md)
A
Alexey Milovidov 已提交
1622 1623
-   [distributed_replica_error_cap](#settings-distributed_replica_error_cap)
-   [distributed_replica_max_ignored_errors](#settings-distributed_replica_max_ignored_errors)
V
Vasily Nemkov 已提交
1624

A
Alexey Milovidov 已提交
1625
## distributed_replica_error_cap {#settings-distributed_replica_error_cap}
V
Vasily Nemkov 已提交
1626

1627 1628
-   Type: unsigned int
-   Default value: 1000
V
Vasily Nemkov 已提交
1629

D
Daria Mozhaeva 已提交
1630
The error count of each replica is capped at this value, preventing a single replica from accumulating too many errors.
V
Vasily Nemkov 已提交
1631

S
Fixes  
Sergei Bocharov 已提交
1632
See also:
V
Vasily Nemkov 已提交
1633

A
Alexey Milovidov 已提交
1634
-   [load_balancing](#load_balancing-round_robin)
1635
-   [Table engine Distributed](../../engines/table-engines/special/distributed.md)
A
Alexey Milovidov 已提交
1636 1637
-   [distributed_replica_error_half_life](#settings-distributed_replica_error_half_life)
-   [distributed_replica_max_ignored_errors](#settings-distributed_replica_max_ignored_errors)
1638

A
Alexey Milovidov 已提交
1639
## distributed_replica_max_ignored_errors {#settings-distributed_replica_max_ignored_errors}
1640 1641 1642 1643

-   Type: unsigned int
-   Default value: 0

D
Daria Mozhaeva 已提交
1644
The number of errors that will be ignored while choosing replicas (according to `load_balancing` algorithm).
1645 1646 1647

See also:

A
Alexey Milovidov 已提交
1648
-   [load_balancing](#load_balancing-round_robin)
1649
-   [Table engine Distributed](../../engines/table-engines/special/distributed.md)
A
Alexey Milovidov 已提交
1650 1651
-   [distributed_replica_error_cap](#settings-distributed_replica_error_cap)
-   [distributed_replica_error_half_life](#settings-distributed_replica_error_half_life)
1652

A
Alexey Milovidov 已提交
1653
## distributed_directory_monitor_sleep_time_ms {#distributed_directory_monitor_sleep_time_ms}
1654

1655
Base interval for the [Distributed](../../engines/table-engines/special/distributed.md) table engine to send data. The actual interval grows exponentially in the event of errors.
1656 1657 1658

Possible values:

1659
-   A positive integer number of milliseconds.
1660 1661 1662

Default value: 100 milliseconds.

A
Alexey Milovidov 已提交
1663
## distributed_directory_monitor_max_sleep_time_ms {#distributed_directory_monitor_max_sleep_time_ms}
1664

A
Alexey Milovidov 已提交
1665
Maximum interval for the [Distributed](../../engines/table-engines/special/distributed.md) table engine to send data. Limits exponential growth of the interval set in the [distributed_directory_monitor_sleep_time_ms](#distributed_directory_monitor_sleep_time_ms) setting.
1666 1667 1668

Possible values:

1669
-   A positive integer number of milliseconds.
1670 1671 1672

Default value: 30000 milliseconds (30 seconds).

A
Alexey Milovidov 已提交
1673
## distributed_directory_monitor_batch_inserts {#distributed_directory_monitor_batch_inserts}
1674

D
Daria Mozhaeva 已提交
1675
Enables/disables inserted data sending in batches.
1676

1677
When batch sending is enabled, the [Distributed](../../engines/table-engines/special/distributed.md) table engine tries to send multiple files of inserted data in one operation instead of sending them separately. Batch sending improves cluster performance by better-utilizing server and network resources.
1678 1679 1680

Possible values:

1681 1682
-   1 — Enabled.
-   0 — Disabled.
1683

1684
Default value: 0.
1685

A
Alexey Milovidov 已提交
1686
## os_thread_priority {#setting-os-thread-priority}
1687

1688
Sets the priority ([nice](https://en.wikipedia.org/wiki/Nice_(Unix))) for threads that execute queries. The OS scheduler considers this priority when choosing the next thread to run on each available CPU core.
1689 1690

!!! warning "Warning"
1691
    To use this setting, you need to set the `CAP_SYS_NICE` capability. The `clickhouse-server` package sets it up during installation. Some virtual environments don’t allow you to set the `CAP_SYS_NICE` capability. In this case, `clickhouse-server` shows a message about it at the start.
1692 1693 1694

Possible values:

1695
-   You can set values in the range `[-20, 19]`.
1696

1697
Lower values mean higher priority. Threads with low `nice` priority values are executed more frequently than threads with high values. High values are preferable for long-running non-interactive queries because it allows them to quickly give up resources in favour of short interactive queries when they arrive.
1698 1699 1700

Default value: 0.

A
Alexey Milovidov 已提交
1701
## query_profiler_real_time_period_ns {#query_profiler_real_time_period_ns}
1702

1703
Sets the period for a real clock timer of the [query profiler](../../operations/optimizing-performance/sampling-query-profiler.md). Real clock timer counts wall-clock time.
1704 1705 1706

Possible values:

1707
-   Positive integer number, in nanoseconds.
1708

1709
    Recommended values:
1710

1711 1712
            - 10000000 (100 times a second) nanoseconds and less for single queries.
            - 1000000000 (once a second) for cluster-wide profiling.
1713

1714
-   0 for turning off the timer.
1715

1716
Type: [UInt64](../../sql-reference/data-types/int-uint.md).
1717

1718
Default value: 1000000000 nanoseconds (once a second).
1719

S
Fixes  
Sergei Bocharov 已提交
1720
See also:
B
BayoNet 已提交
1721

A
Alexey Milovidov 已提交
1722
-   System table [trace_log](../../operations/system-tables/trace_log.md#system_tables-trace_log)
1723

A
Alexey Milovidov 已提交
1724
## query_profiler_cpu_time_period_ns {#query_profiler_cpu_time_period_ns}
1725

1726
Sets the period for a CPU clock timer of the [query profiler](../../operations/optimizing-performance/sampling-query-profiler.md). This timer counts only CPU time.
1727 1728 1729

Possible values:

1730
-   A positive integer number of nanoseconds.
1731

1732
    Recommended values:
1733

1734 1735
            - 10000000 (100 times a second) nanoseconds and more for single queries.
            - 1000000000 (once a second) for cluster-wide profiling.
1736

1737
-   0 for turning off the timer.
1738

1739
Type: [UInt64](../../sql-reference/data-types/int-uint.md).
1740 1741 1742

Default value: 1000000000 nanoseconds.

S
Fixes  
Sergei Bocharov 已提交
1743
See also:
B
BayoNet 已提交
1744

A
Alexey Milovidov 已提交
1745
-   System table [trace_log](../../operations/system-tables/trace_log.md#system_tables-trace_log)
B
BayoNet 已提交
1746

A
Alexey Milovidov 已提交
1747
## allow_introspection_functions {#settings-allow_introspection_functions}
1748

1749
Enables or disables [introspections functions](../../sql-reference/functions/introspection.md) for query profiling.
1750 1751 1752

Possible values:

1753 1754
-   1 — Introspection functions enabled.
-   0 — Introspection functions disabled.
1755 1756 1757

Default value: 0.

1758 1759
**See Also**

1760
-   [Sampling Query Profiler](../../operations/optimizing-performance/sampling-query-profiler.md)
A
Alexey Milovidov 已提交
1761
-   System table [trace_log](../../operations/system-tables/trace_log.md#system_tables-trace_log)
1762

A
Alexey Milovidov 已提交
1763
## input_format_parallel_parsing {#input-format-parallel-parsing}
N
docs  
Nikita Mikhaylov 已提交
1764

1765 1766
-   Type: bool
-   Default value: True
N
docs  
Nikita Mikhaylov 已提交
1767

D
Daria Mozhaeva 已提交
1768
Enable order-preserving parallel parsing of data formats. Supported only for TSV, TKSV, CSV, and JSONEachRow formats.
N
docs  
Nikita Mikhaylov 已提交
1769

A
Alexey Milovidov 已提交
1770
## min_chunk_bytes_for_parallel_parsing {#min-chunk-bytes-for-parallel-parsing}
N
docs  
Nikita Mikhaylov 已提交
1771

1772 1773
-   Type: unsigned int
-   Default value: 1 MiB
N
docs  
Nikita Mikhaylov 已提交
1774

A
Alexander Kuzmenkov 已提交
1775
The minimum chunk size in bytes, which each thread will parse in parallel.
1776

A
Alexey Milovidov 已提交
1777
## output_format_avro_codec {#settings-output_format_avro_codec}
A
Andrew Onyshchuk 已提交
1778 1779 1780 1781 1782 1783 1784

Sets the compression codec used for output Avro file.

Type: string

Possible values:

1785 1786 1787
-   `null` — No compression
-   `deflate` — Compress with Deflate (zlib)
-   `snappy` — Compress with [Snappy](https://google.github.io/snappy/)
A
Andrew Onyshchuk 已提交
1788 1789 1790

Default value: `snappy` (if available) or `deflate`.

A
Alexey Milovidov 已提交
1791
## output_format_avro_sync_interval {#settings-output_format_avro_sync_interval}
A
Andrew Onyshchuk 已提交
1792 1793 1794 1795 1796 1797 1798 1799 1800

Sets minimum data size (in bytes) between synchronization markers for output Avro file.

Type: unsigned int

Possible values: 32 (32 bytes) - 1073741824 (1 GiB)

Default value: 32768 (32 KiB)

A
Alexey Milovidov 已提交
1801
## format_avro_schema_registry_url {#format_avro_schema_registry_url}
A
Andrew Onyshchuk 已提交
1802

1803
Sets [Confluent Schema Registry](https://docs.confluent.io/current/schema-registry/index.html) URL to use with [AvroConfluent](../../interfaces/formats.md#data-format-avro-confluent) format.
A
Andrew Onyshchuk 已提交
1804

1805
Default value: `Empty`.
A
Andrew Onyshchuk 已提交
1806

1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817
## input_format_avro_allow_missing_fields {#input_format_avro_allow_missing_fields}

Enables using fields that are not specified in [Avro](../../interfaces/formats.md#data-format-avro) or [AvroConfluent](../../interfaces/formats.md#data-format-avro-confluent) format schema. When a field is not found in the schema, ClickHouse uses the default value instead of throwing an exception.

Possible values:

-   0 — Disabled.
-   1 — Enabled.

Default value: 0.

A
Alexey Milovidov 已提交
1818
## background_pool_size {#background_pool_size}
1819

D
Daria Mozhaeva 已提交
1820
Sets the number of threads performing background operations in table engines (for example, merges in [MergeTree engine](../../engines/table-engines/mergetree-family/index.md) tables). This setting is applied from the `default` profile at the ClickHouse server start and can’t be changed in a user session. By adjusting this setting, you manage CPU and disk load. Smaller pool size utilizes less CPU and disk resources, but background processes advance slower which might eventually impact query performance.
1821

A
alesapin 已提交
1822
Before changing it, please also take a look at related [MergeTree settings](../../operations/server-configuration-parameters/settings.md#server_configuration_parameters-merge_tree), such as `number_of_free_entries_in_pool_to_lower_max_size_of_merge` and `number_of_free_entries_in_pool_to_execute_mutation`.
1823 1824 1825 1826 1827 1828 1829

Possible values:

-   Any positive integer.

Default value: 16.

1830 1831
## parallel_distributed_insert_select {#parallel_distributed_insert_select}

1832
Enables parallel distributed `INSERT ... SELECT` query.
1833 1834 1835 1836 1837 1838

If we execute `INSERT INTO distributed_table_a SELECT ... FROM distributed_table_b` queries and both tables use the same cluster, and both tables are either [replicated](../../engines/table-engines/mergetree-family/replication.md) or non-replicated, then this query is processed locally on every shard.

Possible values:

-   0 — Disabled.
D
Daria Mozhaeva 已提交
1839 1840
-   1 — `SELECT` will be executed on each shard from the underlying table of the distributed engine.
-   2 — `SELECT` and `INSERT` will be executed on each shard from/to the underlying table of the distributed engine.
1841 1842 1843

Default value: 0.

1844 1845 1846 1847
## insert_distributed_sync {#insert_distributed_sync}

Enables or disables synchronous data insertion into a [Distributed](../../engines/table-engines/special/distributed.md#distributed) table.

1848
By default, when inserting data into a `Distributed` table, the ClickHouse server sends data to cluster nodes in asynchronous mode. When `insert_distributed_sync=1`, the data is processed synchronously, and the `INSERT` operation succeeds only after all the data is saved on all shards (at least one replica for each shard if `internal_replication` is true).
1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860

Possible values:

-   0 — Data is inserted in asynchronous mode.
-   1 — Data is inserted in synchronous mode.

Default value: `0`.

**See Also**

-   [Distributed Table Engine](../../engines/table-engines/special/distributed.md#distributed)
-   [Managing Distributed Tables](../../sql-reference/statements/system.md#query-language-system-distributed)
1861

1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873
## insert_distributed_one_random_shard {#insert_distributed_one_random_shard}

Enables or disables random shard insertion into a [Distributed](../../engines/table-engines/special/distributed.md#distributed) table when there is no distributed key.

By default, when inserting data into a `Distributed` table with more than one shard, the ClickHouse server will any insertion request if there is no distributed key. When `insert_distributed_one_random_shard = 1`, insertions are allowed and data is forwarded randomly among all shards.

Possible values:

-   0 — Insertion is rejected if there are multiple shards and no distributed key is given.
-   1 — Insertion is done randomly among all available shards when no distributed key is given.

Default value: `0`.
1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889

## use_compact_format_in_distributed_parts_names {#use_compact_format_in_distributed_parts_names}

Uses compact format for storing blocks for async (`insert_distributed_sync`) INSERT into tables with `Distributed` engine.

Possible values:

-   0 — Uses `user[:password]@host:port#default_database` directory format.
-   1 — Uses `[shard{shard_index}[_replica{replica_index}]]` directory format.

Default value: `1`.

!!! note "Note"
    - with `use_compact_format_in_distributed_parts_names=0` changes from cluster definition will not be applied for async INSERT.
    - with `use_compact_format_in_distributed_parts_names=1` changing the order of the nodes in the cluster definition, will change the `shard_index`/`replica_index` so be aware.

A
Alexey Milovidov 已提交
1890
## background_buffer_flush_schedule_pool_size {#background_buffer_flush_schedule_pool_size}
1891

D
Daria Mozhaeva 已提交
1892
Sets the number of threads performing background flush in [Buffer](../../engines/table-engines/special/buffer.md)-engine tables. This setting is applied at the ClickHouse server start and can’t be changed in a user session.
1893

1894 1895 1896 1897 1898 1899
Possible values:

-   Any positive integer.

Default value: 16.

A
Alexey Milovidov 已提交
1900
## background_move_pool_size {#background_move_pool_size}
1901

D
Daria Mozhaeva 已提交
1902
Sets the number of threads performing background moves of data parts for [MergeTree](../../engines/table-engines/mergetree-family/mergetree.md#table_engine-mergetree-multiple-volumes)-engine tables. This setting is applied at the ClickHouse server start and can’t be changed in a user session.
1903 1904 1905 1906 1907 1908 1909

Possible values:

-   Any positive integer.

Default value: 8.

A
Alexey Milovidov 已提交
1910
## background_schedule_pool_size {#background_schedule_pool_size}
1911

1912
Sets the number of threads performing background tasks for [replicated](../../engines/table-engines/mergetree-family/replication.md) tables, [Kafka](../../engines/table-engines/integrations/kafka.md) streaming, [DNS cache updates](../../operations/server-configuration-parameters/settings.md#server-settings-dns-cache-update-period). This setting is applied at ClickHouse server start and can’t be changed in a user session.
1913 1914 1915 1916 1917 1918 1919

Possible values:

-   Any positive integer.

Default value: 16.

A
Alexey Milovidov 已提交
1920
## always_fetch_merged_part {#always_fetch_merged_part}
1921

1922
Prohibits data parts merging in [Replicated\*MergeTree](../../engines/table-engines/mergetree-family/replication.md)-engine tables.
1923

D
Daria Mozhaeva 已提交
1924
When merging is prohibited, the replica never merges parts and always downloads merged parts from other replicas. If there is no required data yet, the replica waits for it. CPU and disk load on the replica server decreases, but the network load on the cluster increases. This setting can be useful on servers with relatively weak CPUs or slow disks, such as servers for backups storage.
1925 1926 1927 1928

Possible values:

-   0 — `Replicated*MergeTree`-engine tables merge data parts at the replica.
1929
-   1 — `Replicated*MergeTree`-engine tables don’t merge data parts at the replica. The tables download merged data parts from other replicas.
1930 1931 1932

Default value: 0.

1933
**See Also**
1934 1935 1936

-   [Data Replication](../../engines/table-engines/mergetree-family/replication.md)

A
Alexey Milovidov 已提交
1937
## background_distributed_schedule_pool_size {#background_distributed_schedule_pool_size}
1938

D
Daria Mozhaeva 已提交
1939
Sets the number of threads performing background tasks for [distributed](../../engines/table-engines/special/distributed.md) sends. This setting is applied at the ClickHouse server start and can’t be changed in a user session.
1940 1941 1942 1943 1944

Possible values:

-   Any positive integer.

1945 1946
Default value: 16.

1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961
## background_message_broker_schedule_pool_size {#background_message_broker_schedule_pool_size}

Sets the number of threads performing background tasks for message streaming. This setting is applied at the ClickHouse server start and can’t be changed in a user session.

Possible values:

-   Any positive integer.

Default value: 16.

**See Also**

-   [Kafka](../../engines/table-engines/integrations/kafka.md#kafka) engine
-   [RabbitMQ](../../engines/table-engines/integrations/rabbitmq.md#rabbitmq-engine) engine

A
Alexey Milovidov 已提交
1962
## validate_polygons {#validate_polygons}
1963

1964
Enables or disables throwing an exception in the [pointInPolygon](../../sql-reference/functions/geo/index.md#pointinpolygon) function, if the polygon is self-intersecting or self-tangent.
1965 1966 1967 1968 1969 1970 1971 1972

Possible values:

- 0 — Throwing an exception is disabled. `pointInPolygon` accepts invalid polygons and returns possibly incorrect results for them.
- 1 — Throwing an exception is enabled.

Default value: 1.

A
Alexey Milovidov 已提交
1973
## transform_null_in {#transform_null_in}
B
BayoNet 已提交
1974 1975 1976

Enables equality of [NULL](../../sql-reference/syntax.md#null-literal) values for [IN](../../sql-reference/operators/in.md) operator.

1977
By default, `NULL` values can’t be compared because `NULL` means undefined value. Thus, comparison `expr = NULL` must always return `false`. With this setting `NULL = NULL` returns `true` for `IN` operator.
B
BayoNet 已提交
1978 1979 1980 1981 1982 1983 1984 1985

Possible values:

-   0 — Comparison of `NULL` values in `IN` operator returns `false`.
-   1 — Comparison of `NULL` values in `IN` operator returns `true`.

Default value: 0.

1986
**Example**
B
BayoNet 已提交
1987 1988 1989

Consider the `null_in` table:

1990
``` text
B
BayoNet 已提交
1991 1992 1993 1994 1995 1996 1997 1998 1999
┌──idx─┬─────i─┐
│    1 │     1 │
│    2 │  NULL │
│    3 │     3 │
└──────┴───────┘
```

Query:

2000
``` sql
B
BayoNet 已提交
2001 2002 2003 2004 2005
SELECT idx, i FROM null_in WHERE i IN (1, NULL) SETTINGS transform_null_in = 0;
```

Result:

2006
``` text
B
BayoNet 已提交
2007 2008 2009 2010 2011 2012 2013
┌──idx─┬────i─┐
│    1 │    1 │
└──────┴──────┘
```

Query:

2014
``` sql
B
BayoNet 已提交
2015 2016 2017 2018 2019
SELECT idx, i FROM null_in WHERE i IN (1, NULL) SETTINGS transform_null_in = 1;
```

Result:

2020
``` text
B
BayoNet 已提交
2021 2022 2023 2024 2025 2026
┌──idx─┬─────i─┐
│    1 │     1 │
│    2 │  NULL │
└──────┴───────┘
```

2027
**See Also**
B
BayoNet 已提交
2028 2029 2030

-   [NULL Processing in IN Operators](../../sql-reference/operators/in.md#in-null-processing)

A
Alexey Milovidov 已提交
2031
## low_cardinality_max_dictionary_size {#low_cardinality_max_dictionary_size}
B
BayoNet 已提交
2032

2033
Sets a maximum size in rows of a shared global dictionary for the [LowCardinality](../../sql-reference/data-types/lowcardinality.md) data type that can be written to a storage file system. This setting prevents issues with RAM in case of unlimited dictionary growth. All the data that can’t be encoded due to maximum dictionary size limitation ClickHouse writes in an ordinary method.
B
BayoNet 已提交
2034 2035 2036 2037 2038 2039 2040

Possible values:

-   Any positive integer.

Default value: 8192.

A
Alexey Milovidov 已提交
2041
## low_cardinality_use_single_dictionary_for_part {#low_cardinality_use_single_dictionary_for_part}
B
BayoNet 已提交
2042 2043 2044

Turns on or turns off using of single dictionary for the data part.

D
Daria Mozhaeva 已提交
2045
By default, the ClickHouse server monitors the size of dictionaries and if a dictionary overflows then the server starts to write the next one. To prohibit creating several dictionaries set `low_cardinality_use_single_dictionary_for_part = 1`.
B
BayoNet 已提交
2046 2047 2048

Possible values:

2049 2050
-   1 — Creating several dictionaries for the data part is prohibited.
-   0 — Creating several dictionaries for the data part is not prohibited.
B
BayoNet 已提交
2051 2052 2053

Default value: 0.

A
Alexey Milovidov 已提交
2054
## low_cardinality_allow_in_native_format {#low_cardinality_allow_in_native_format}
B
BayoNet 已提交
2055 2056 2057 2058 2059

Allows or restricts using the [LowCardinality](../../sql-reference/data-types/lowcardinality.md) data type with the [Native](../../interfaces/formats.md#native) format.

If usage of `LowCardinality` is restricted, ClickHouse server converts `LowCardinality`-columns to ordinary ones for `SELECT` queries, and convert ordinary columns to `LowCardinality`-columns for `INSERT` queries.

2060
This setting is required mainly for third-party clients which don’t support `LowCardinality` data type.
B
BayoNet 已提交
2061 2062 2063

Possible values:

2064 2065
-   1 — Usage of `LowCardinality` is not restricted.
-   0 — Usage of `LowCardinality` is restricted.
B
BayoNet 已提交
2066 2067 2068

Default value: 1.

A
Alexey Milovidov 已提交
2069
## allow_suspicious_low_cardinality_types {#allow_suspicious_low_cardinality_types}
B
BayoNet 已提交
2070 2071 2072 2073 2074

Allows or restricts using [LowCardinality](../../sql-reference/data-types/lowcardinality.md) with data types with fixed size of 8 bytes or less: numeric data types and `FixedString(8_bytes_or_less)`.

For small fixed values using of `LowCardinality` is usually inefficient, because ClickHouse stores a numeric index for each row. As a result:

2075 2076 2077
-   Disk space usage can rise.
-   RAM consumption can be higher, depending on a dictionary size.
-   Some functions can work slower due to extra coding/encoding operations.
B
BayoNet 已提交
2078 2079 2080 2081 2082

Merge times in [MergeTree](../../engines/table-engines/mergetree-family/mergetree.md)-engine tables can grow due to all the reasons described above.

Possible values:

2083 2084
-   1 — Usage of `LowCardinality` is not restricted.
-   0 — Usage of `LowCardinality` is restricted.
B
BayoNet 已提交
2085 2086 2087

Default value: 0.

A
Alexey Milovidov 已提交
2088
## min_insert_block_size_rows_for_materialized_views {#min-insert-block-size-rows-for-materialized-views}
E
Evgenia Sudarikova 已提交
2089

D
Daria Mozhaeva 已提交
2090
Sets the minimum number of rows in the block which can be inserted into a table by an `INSERT` query. Smaller-sized blocks are squashed into bigger ones. This setting is applied only for blocks inserted into [materialized view](../../sql-reference/statements/create/view.md). By adjusting this setting, you control blocks squashing while pushing to materialized view and avoid excessive memory usage.
E
Evgenia Sudarikova 已提交
2091 2092 2093 2094 2095 2096 2097 2098 2099 2100

Possible values:

-   Any positive integer.
-   0 — Squashing disabled.

Default value: 1048576.

**See Also**

A
Alexey Milovidov 已提交
2101
-   [min_insert_block_size_rows](#min-insert-block-size-rows)
E
Evgenia Sudarikova 已提交
2102

A
Alexey Milovidov 已提交
2103
## min_insert_block_size_bytes_for_materialized_views {#min-insert-block-size-bytes-for-materialized-views}
E
Evgenia Sudarikova 已提交
2104

D
Daria Mozhaeva 已提交
2105
Sets the minimum number of bytes in the block which can be inserted into a table by an `INSERT` query. Smaller-sized blocks are squashed into bigger ones. This setting is applied only for blocks inserted into [materialized view](../../sql-reference/statements/create/view.md). By adjusting this setting, you control blocks squashing while pushing to materialized view and avoid excessive memory usage.
E
Evgenia Sudarikova 已提交
2106 2107 2108 2109 2110 2111 2112 2113 2114 2115

Possible values:

-   Any positive integer.
-   0 — Squashing disabled.

Default value: 268435456.

**See also**

A
Alexey Milovidov 已提交
2116
-   [min_insert_block_size_bytes](#min-insert-block-size-bytes)
E
Evgenia Sudarikova 已提交
2117

A
Alexey Milovidov 已提交
2118
## output_format_pretty_grid_charset {#output-format-pretty-grid-charset}
2119

D
Daria Mozhaeva 已提交
2120
Allows changing a charset which is used for printing grids borders. Available charsets are UTF-8, ASCII.
2121

2122
**Example**
2123

2124
``` text
2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136
SET output_format_pretty_grid_charset = 'UTF-8';
SELECT * FROM a;
┌─a─┐
│ 1 │
└───┘

SET output_format_pretty_grid_charset = 'ASCII';
SELECT * FROM a;
+-a-+
| 1 |
+---+
```
2137 2138 2139 2140 2141 2142
## optimize_read_in_order {#optimize_read_in_order}

Enables [ORDER BY](../../sql-reference/statements/select/order-by.md#optimize_read_in_order) optimization in [SELECT](../../sql-reference/statements/select/index.md) queries for reading data from [MergeTree](../../engines/table-engines/mergetree-family/mergetree.md) tables.

Possible values:

2143 2144
-   0 — `ORDER BY` optimization is disabled.
-   1 — `ORDER BY` optimization is enabled.
2145 2146 2147 2148 2149 2150

Default value: `1`.

**See Also**

-   [ORDER BY Clause](../../sql-reference/statements/select/order-by.md#optimize_read_in_order)
2151

O
Olga Revyakina 已提交
2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166
## optimize_aggregation_in_order {#optimize_aggregation_in_order}

Enables [GROUP BY](../../sql-reference/statements/select/group-by.md) optimization in [SELECT](../../sql-reference/statements/select/index.md) queries for aggregating data in corresponding order in [MergeTree](../../engines/table-engines/mergetree-family/mergetree.md) tables.

Possible values:

-   0 — `GROUP BY` optimization is disabled.
-   1 — `GROUP BY` optimization is enabled.

Default value: `0`.

**See Also**

-   [GROUP BY optimization](../../sql-reference/statements/select/group-by.md#aggregation-in-order)

2167 2168 2169 2170 2171 2172
## mutations_sync {#mutations_sync}

Allows to execute `ALTER TABLE ... UPDATE|DELETE` queries ([mutations](../../sql-reference/statements/alter/index.md#mutations)) synchronously.

Possible values:

2173 2174
-   0 - Mutations execute asynchronously.
-   1 - The query waits for all mutations to complete on the current server.
2175 2176 2177 2178 2179 2180 2181 2182 2183
-   2 - The query waits for all mutations to complete on all replicas (if they exist).

Default value: `0`.

**See Also**

-   [Synchronicity of ALTER Queries](../../sql-reference/statements/alter/index.md#synchronicity-of-alter-queries)
-   [Mutations](../../sql-reference/statements/alter/index.md#mutations)

2184 2185
## ttl_only_drop_parts {#ttl_only_drop_parts}

2186
Enables or disables complete dropping of data parts where all rows are expired in [MergeTree](../../engines/table-engines/mergetree-family/mergetree.md) tables.
2187

2188
When `ttl_only_drop_parts` is disabled (by default), the ClickHouse server only deletes expired rows according to their TTL.
2189

2190
When `ttl_only_drop_parts` is enabled, the ClickHouse server drops a whole part when all rows in it are expired.
2191

D
Daria Mozhaeva 已提交
2192
Dropping whole parts instead of partial cleaning TTL-d rows allows having shorter `merge_with_ttl_timeout` times and lower impact on system performance.
2193 2194 2195

Possible values:

D
Daria Mozhaeva 已提交
2196 2197
-   0 — The complete dropping of data parts is disabled.
-   1 — The complete dropping of data parts is enabled.
2198 2199 2200

Default value: `0`.

2201
**See Also**
2202 2203 2204 2205

-   [CREATE TABLE query clauses and settings](../../engines/table-engines/mergetree-family/mergetree.md#mergetree-query-clauses) (`merge_with_ttl_timeout` setting)
-   [Table TTL](../../engines/table-engines/mergetree-family/mergetree.md#mergetree-table-ttl)

2206 2207
## lock_acquire_timeout {#lock_acquire_timeout}

2208
Defines how many seconds a locking request waits before failing.
2209

D
Daria Mozhaeva 已提交
2210
Locking timeout is used to protect from deadlocks while executing read/write operations with tables. When the timeout expires and the locking request fails, the ClickHouse server throws an exception "Locking attempt timed out! Possible deadlock avoided. Client should retry." with error code `DEADLOCK_AVOIDED`.
2211 2212 2213

Possible values:

2214
-   Positive integer (in seconds).
2215 2216
-   0 — No locking timeout.

2217
Default value: `120` seconds.
2218

2219 2220
## cast_keep_nullable {#cast_keep_nullable}

O
olgarev 已提交
2221
Enables or disables keeping of the `Nullable` data type in [CAST](../../sql-reference/functions/type-conversion-functions.md#type_conversion_function-cast) operations.
2222

2223
When the setting is enabled and the argument of `CAST` function is `Nullable`, the result is also transformed to `Nullable` type. When the setting is disabled, the result always has the destination type exactly.
2224 2225 2226

Possible values:

2227
-  0 — The `CAST` result has exactly the destination type specified.
2228
-  1 — If the argument type is `Nullable`, the `CAST` result is transformed to `Nullable(DestinationDataType)`.
2229 2230 2231

Default value: `0`.

2232
**Examples**
2233

2234
The following query results in the destination data type exactly:
2235 2236 2237 2238 2239 2240 2241 2242

```sql
SET cast_keep_nullable = 0;
SELECT CAST(toNullable(toInt32(0)) AS Int32) as x, toTypeName(x);
```

Result:

O
Olga Revyakina 已提交
2243
```text
2244 2245 2246 2247 2248
┌─x─┬─toTypeName(CAST(toNullable(toInt32(0)), 'Int32'))─┐
│ 0 │ Int32                                             │
└───┴───────────────────────────────────────────────────┘
```

2249
The following query results in the `Nullable` modification on the destination data type:
2250 2251 2252 2253 2254 2255 2256 2257

```sql
SET cast_keep_nullable = 1;
SELECT CAST(toNullable(toInt32(0)) AS Int32) as x, toTypeName(x);
```

Result:

O
Olga Revyakina 已提交
2258
```text
2259 2260 2261 2262 2263
┌─x─┬─toTypeName(CAST(toNullable(toInt32(0)), 'Int32'))─┐
│ 0 │ Nullable(Int32)                                   │
└───┴───────────────────────────────────────────────────┘
```

2264
**See Also**
2265

2266
-   [CAST](../../sql-reference/functions/type-conversion-functions.md#type_conversion_function-cast) function
2267

2268 2269
## output_format_pretty_max_value_width {#output_format_pretty_max_value_width}

2270
Limits the width of value displayed in [Pretty](../../interfaces/formats.md#pretty) formats. If the value width exceeds the limit, the value is cut.
2271 2272 2273

Possible values:

2274
-   Positive integer.
2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317
-   0 — The value is cut completely.

Default value: `10000` symbols.

**Examples**

Query:
```sql
SET output_format_pretty_max_value_width = 10;
SELECT range(number) FROM system.numbers LIMIT 10 FORMAT PrettyCompactNoEscapes;
```
Result:
```text
┌─range(number)─┐
│ []            │
│ [0]           │
│ [0,1]         │
│ [0,1,2]       │
│ [0,1,2,3]     │
│ [0,1,2,3,4⋯   │
│ [0,1,2,3,4⋯   │
│ [0,1,2,3,4⋯   │
│ [0,1,2,3,4⋯   │
│ [0,1,2,3,4⋯   │
└───────────────┘
```

Query with zero width:
```sql
SET output_format_pretty_max_value_width = 0;
SELECT range(number) FROM system.numbers LIMIT 5 FORMAT PrettyCompactNoEscapes;
```
Result:
```text
┌─range(number)─┐
│ ⋯             │
│ ⋯             │
│ ⋯             │
│ ⋯             │
│ ⋯             │
└───────────────┘
```

2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345
## output_format_pretty_row_numbers {#output_format_pretty_row_numbers}

Adds row numbers to output in the [Pretty](../../interfaces/formats.md#pretty) format.

Possible values:

-   0 — Output without row numbers.
-   1 — Output with row numbers.

Default value: `0`.

**Example**

Query:

```sql
SET output_format_pretty_row_numbers = 1;
SELECT TOP 3 name, value FROM system.settings;
```

Result:
```text
   ┌─name────────────────────┬─value───┐
1. │ min_compress_block_size │ 65536   │
2. │ max_compress_block_size │ 1048576 │
3. │ max_block_size          │ 65505   │
   └─────────────────────────┴─────────┘
```
2346

2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387
## system_events_show_zero_values {#system_events_show_zero_values}

Allows to select zero-valued events from [`system.events`](../../operations/system-tables/events.md).

Some monitoring systems require passing all the metrics values to them for each checkpoint, even if the metric value is zero.

Possible values:

-   0 — Disabled.
-   1 — Enabled.

Default value: `0`.

**Examples**

Query

```sql
SELECT * FROM system.events WHERE event='QueryMemoryLimitExceeded';
```

Result

```text
Ok.
```

Query
```sql
SET system_events_show_zero_values = 1;
SELECT * FROM system.events WHERE event='QueryMemoryLimitExceeded';
```

Result

```text
┌─event────────────────────┬─value─┬─description───────────────────────────────────────────┐
│ QueryMemoryLimitExceeded │     0 │ Number of times when memory limit exceeded for query. │
└──────────────────────────┴───────┴───────────────────────────────────────────────────────┘
```

2388 2389 2390 2391 2392 2393 2394 2395 2396
## allow_experimental_bigint_types {#allow_experimental_bigint_types}

Enables or disables integer values exceeding the range that is supported by the int data type.

Possible values:

-   1 — The bigint data type is enabled.
-   0 — The bigint data type is disabled.

2397
Default value: `0`.
2398

2399 2400
## persistent {#persistent}

2401
Disables persistency for the [Set](../../engines/table-engines/special/set.md#set) and [Join](../../engines/table-engines/special/join.md#join) table engines.
2402 2403 2404 2405 2406 2407 2408 2409 2410 2411

Reduces the I/O overhead. Suitable for scenarios that pursue performance and do not require persistence.

Possible values:

- 1 — Enabled.
- 0 — Disabled.

Default value: `1`.

E
Evgeniia Sudarikova 已提交
2412 2413
## output_format_tsv_null_representation {#output_format_tsv_null_representation}

E
Evgeniia Sudarikova 已提交
2414
Defines the representation of `NULL` for [TSV](../../interfaces/formats.md#tabseparated) output format. User can set any string as a value, for example, `My NULL`.
E
Evgeniia Sudarikova 已提交
2415 2416 2417

Default value: `\N`.

E
Evgeniia Sudarikova 已提交
2418 2419 2420 2421 2422
**Examples**

Query

```sql
E
Evgeniia Sudarikova 已提交
2423
SELECT * FROM tsv_custom_null FORMAT TSV;
E
Evgeniia Sudarikova 已提交
2424 2425 2426 2427 2428 2429 2430
```

Result

```text
788
\N
E
Evgeniia Sudarikova 已提交
2431
\N
E
Evgeniia Sudarikova 已提交
2432 2433 2434 2435 2436
```

Query

```sql
E
Evgeniia Sudarikova 已提交
2437 2438
SET output_format_tsv_null_representation = 'My NULL';
SELECT * FROM tsv_custom_null FORMAT TSV;
E
Evgeniia Sudarikova 已提交
2439 2440 2441 2442 2443 2444 2445 2446 2447 2448
```

Result

```text
788
My NULL
My NULL
```

D
Dmitriy 已提交
2449 2450
## output_format_json_array_of_rows {#output-format-json-array-of-rows}

2451
Enables the ability to output all rows as a JSON array in the [JSONEachRow](../../interfaces/formats.md#jsoneachrow) format.
D
Dmitriy 已提交
2452 2453 2454

Possible values:

D
Dmitriy 已提交
2455 2456
-   1 — ClickHouse outputs all rows as an array, each row in the `JSONEachRow` format.
-   0 — ClickHouse outputs each row separately in the `JSONEachRow` format.
D
Dmitriy 已提交
2457 2458 2459

Default value: `0`.

D
Dmitriy 已提交
2460
**Example of a query with the enabled setting**
D
Dmitriy 已提交
2461 2462 2463 2464 2465

Query:

```sql
SET output_format_json_array_of_rows = 1;
D
Dmitriy 已提交
2466
SELECT number FROM numbers(3) FORMAT JSONEachRow;
D
Dmitriy 已提交
2467 2468 2469 2470 2471 2472 2473 2474
```

Result:

```text
[
{"number":"0"},
{"number":"1"},
2475
{"number":"2"}
D
Dmitriy 已提交
2476 2477 2478
]
```

D
Dmitriy 已提交
2479 2480 2481 2482 2483 2484
**Example of a query with the disabled setting**

Query:

```sql
SET output_format_json_array_of_rows = 0;
D
Dmitriy 已提交
2485
SELECT number FROM numbers(3) FORMAT JSONEachRow;
D
Dmitriy 已提交
2486 2487 2488 2489 2490 2491 2492 2493 2494 2495
```

Result:

```text
{"number":"0"}
{"number":"1"}
{"number":"2"}
```

2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506
## allow_nullable_key {#allow-nullable-key}

Allows using of the [Nullable](../../sql-reference/data-types/nullable.md#data_type-nullable)-typed values in a sorting and a primary key for [MergeTree](../../engines/table-engines/mergetree-family/mergetree.md#table_engines-mergetree) tables.

Possible values:

- 1 — `Nullable`-type expressions are allowed in keys.
- 0 — `Nullable`-type expressions are not allowed in keys.

Default value: `0`.

2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522
## aggregate_functions_null_for_empty {#aggregate_functions_null_for_empty}

Enables or disables rewriting all aggregate functions in a query, adding [-OrNull](../../sql-reference/aggregate-functions/combinators.md#agg-functions-combinator-ornull) suffix to them. Enable it for SQL standard compatibility.
It is implemented via query rewrite (similar to [count_distinct_implementation](#settings-count_distinct_implementation) setting) to get consistent results for distributed queries. 

Possible values:

-   0 — Disabled.
-   1 — Enabled.

Default value: 0.

**Example**

Consider the following query with aggregate functions:
```sql
2523
SELECT SUM(-1), MAX(0) FROM system.one WHERE 0;
2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539
```

With `aggregate_functions_null_for_empty = 0` it would produce:
```text
┌─SUM(-1)─┬─MAX(0)─┐
│       0 │      0 │
└─────────┴────────┘
```

With `aggregate_functions_null_for_empty = 1` the result would be:
```text
┌─SUMOrNull(-1)─┬─MAXOrNull(0)─┐
│          NULL │         NULL │
└───────────────┴──────────────┘
```

D
Dmitriy 已提交
2540 2541
## union_default_mode {#union-default-mode}

D
Dmitriy 已提交
2542
Sets a mode for combining `SELECT` query results. The setting is only used when shared with [UNION](../../sql-reference/statements/select/union.md) without explicitly specifying the `UNION ALL` or `UNION DISTINCT`.
D
Dmitriy 已提交
2543 2544 2545 2546 2547 2548 2549

Possible values:

-   `'DISTINCT'` — ClickHouse outputs rows as a result of combining queries removing duplicate rows.
-   `'ALL'` — ClickHouse outputs all rows as a result of combining queries including duplicate rows.
-   `''` — Clickhouse generates an exception when used with `UNION`.

A
alexey-milovidov 已提交
2550
Default value: `''`.
D
Dmitriy 已提交
2551

D
Dmitriy 已提交
2552
See examples in [UNION](../../sql-reference/statements/select/union.md).
D
Dmitriy 已提交
2553

A
Anna 已提交
2554 2555
## data_type_default_nullable {#data_type_default_nullable}

A
fixed  
Anna 已提交
2556
Allows data types without explicit modifiers [NULL or NOT NULL](../../sql-reference/statements/create/table.md#null-modifiers) in column definition will be [Nullable](../../sql-reference/data-types/nullable.md#data_type-nullable).
A
Anna 已提交
2557 2558 2559

Possible values:

A
fixed  
Anna 已提交
2560 2561
- 1 — The data types in column definitions are set to `Nullable` by default.
- 0 — The data types in column definitions are set to not `Nullable` by default.
A
Anna 已提交
2562 2563 2564

Default value: `0`.

2565 2566 2567 2568 2569 2570 2571
## execute_merges_on_single_replica_time_threshold {#execute-merges-on-single-replica-time-threshold}

Enables special logic to perform merges on replicas.

Possible values:

-   Positive integer (in seconds).
D
Dmitriy 已提交
2572
-   0 — Special merges logic is not used. Merges happen in the usual way on all the replicas.
2573 2574 2575

Default value: `0`.

D
Dmitriy 已提交
2576
**Usage**
2577

D
Dmitriy 已提交
2578 2579 2580
Selects one replica to perform the merge on. Sets the time threshold from the start of the merge. Other replicas wait for the merge to finish, then download the result. If the time threshold passes and the selected replica does not perform the merge, then the merge is performed on other replicas as usual.

High values for that threshold may lead to replication delays.
2581

D
Dmitriy 已提交
2582
It can be useful when merges are CPU bounded not IO bounded (performing heavy data compression, calculating aggregate functions or default expressions that require a large amount of calculations, or just very high number of tiny merges).
D
Dmitriy 已提交
2583

D
Dmitriy 已提交
2584 2585
## max_final_threads {#max-final-threads}

2586
Sets the maximum number of parallel threads for the `SELECT` query data read phase with the [FINAL](../../sql-reference/statements/select/from.md#select-from-final) modifier.
D
Dmitriy 已提交
2587 2588 2589 2590

Possible values:

-   Positive integer.
D
Dmitriy 已提交
2591
-   0 or 1 — Disabled. `SELECT` queries are executed in a single thread.
D
Dmitriy 已提交
2592 2593

Default value: `16`.
2594

D
Daria Mozhaeva 已提交
2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648
## optimize_on_insert {#optimize-on-insert}

Enables or disables data transformation before the insertion, as if merge was done on this block (according to table engine).

Possible values:

-   0 — Disabled.
-   1 — Enabled.

Default value: 1.

**Example**

The difference between enabled and disabled:

Query:

```sql
SET optimize_on_insert = 1;

CREATE TABLE test1 (`FirstTable` UInt32) ENGINE = ReplacingMergeTree ORDER BY FirstTable;

INSERT INTO test1 SELECT number % 2 FROM numbers(5);

SELECT * FROM test1;

SET optimize_on_insert = 0;

CREATE TABLE test2 (`SecondTable` UInt32) ENGINE = ReplacingMergeTree ORDER BY SecondTable;

INSERT INTO test2 SELECT number % 2 FROM numbers(5);

SELECT * FROM test2;
```

Result:

``` text
┌─FirstTable─┐
│          0 │
│          1 │
└────────────┘

┌─SecondTable─┐
│           0 │
│           0 │
│           0 │
│           1 │
│           1 │
└─────────────┘
```

Note that this setting influences [Materialized view](../../sql-reference/statements/create/view.md#materialized) and [MaterializeMySQL](../../engines/database-engines/materialize-mysql.md) behaviour.

I
Ivan Blinkov 已提交
2649
[Original article](https://clickhouse.tech/docs/en/operations/settings/settings/) <!-- hide -->