> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# optimize_rewrite_* session settings

> ClickHouse session settings in the optimize_rewrite_* generated group.

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

## optimize\_rewrite\_aggregate\_function\_with\_if

Type

Bool

Default

1

Rewrite aggregate functions with if expression as argument when logically equivalent.
For example, `avg(if(cond, col, null))` can be rewritten to `avgOrNullIf(cond, col)`. It may improve performance.

## optimize\_rewrite\_array\_exists\_to\_has

Type

Bool

Default

1

Rewrite arrayExists() functions to has() when logically equivalent. For example, arrayExists(x -> x = 1, arr) can be rewritten to has(arr, 1)

## optimize\_rewrite\_array\_filter\_length\_to\_array\_count

Type

Bool

Default

1

Rewrite `length(arrayFilter(func, arr))` to `arrayCount(func, arr)`. `arrayFilter` builds an array of the matching elements only for `length` to throw it away, while `arrayCount` just counts them.

## optimize\_rewrite\_has\_to\_in

Type

Bool

Default

1

Rewrite `has` functions to `IN` when the first argument is a constant array. For example, `has([1, 2, 3], x)` can be rewritten to `x IN [1, 2, 3]` for better performance with constant arrays

## optimize\_rewrite\_like\_perfect\_affix

Type

Bool

Default

1

Rewrite LIKE expressions with perfect prefix or suffix (e.g. `col LIKE 'ClickHouse%'`) to startsWith or endsWith functions (e.g. `startsWith(col, 'ClickHouse')`).

## optimize\_rewrite\_regexp\_functions

Type

Bool

Default

1

Rewrite regular expression related functions into simpler and more efficient forms

## optimize\_rewrite\_sum\_if\_to\_count\_if

Type

Bool

Default

1

Rewrite sumIf() and sum(if()) function countIf() function when logically equivalent
