> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-postgresql-tls-support.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# optimize_rewrite_* セッション設定

> optimize_rewrite_* グループに含まれる ClickHouse のセッション設定。

export const VersionHistory = ({rows = []}) => {
  if (rows.length === 0) {
    return null;
  }
  const headers = ["バージョン", "デフォルト値", "コメント"];
  const border = "1px solid rgba(128, 128, 128, 0.3)";
  const cell = {
    border,
    padding: "0.25rem 0.5rem",
    textAlign: "start",
    verticalAlign: "top"
  };
  return <details className="not-prose" style={{
    border,
    borderRadius: "0.5rem",
    margin: "0.5rem 0",
    padding: "0.5rem 0.75rem",
    fontSize: "0.8125rem",
    lineHeight: "1.125rem"
  }}>
      <summary style={{
    cursor: "pointer",
    fontWeight: 600,
    opacity: 0.72
  }}>
        バージョン履歴
      </summary>
      <table style={{
    borderCollapse: "collapse",
    width: "100%",
    margin: "0.5rem 0 0"
  }}>
        <thead>
          <tr>
            {headers.map(header => <th key={header} style={{
    ...cell,
    fontWeight: 600,
    opacity: 0.72
  }}>
                {header}
              </th>)}
          </tr>
        </thead>
        <tbody>
          {rows.map((row, row_index) => <tr key={row.id ?? row_index}>
              {(row.items ?? []).map((item, item_index) => <td key={item_index} style={{
    ...cell,
    overflowWrap: "anywhere"
  }}>
                  {item?.label}
                </td>)}
            </tr>)}
        </tbody>
      </table>
    </details>;
};

export const SettingsInfoBlock = ({type, default_value, changeable_without_restart}) => {
  return <div className="not-prose" style={{
    display: "flex",
    flexWrap: "wrap",
    alignItems: "baseline",
    columnGap: "0.5rem",
    rowGap: "0.125rem",
    margin: "0.375rem 0",
    fontSize: "0.8125rem",
    lineHeight: "1.125rem"
  }}>
      <div style={{
    fontWeight: 600,
    opacity: 0.72
  }}>型</div>
      <div style={{
    overflowWrap: "anywhere"
  }}>{type}</div>
      <div style={{
    fontWeight: 600,
    opacity: 0.72,
    marginInlineStart: "0.5rem"
  }}>デフォルト値</div>
      <div style={{
    overflowWrap: "anywhere"
  }}>{default_value}</div>
      {changeable_without_restart && <div style={{
    fontWeight: 600,
    opacity: 0.72,
    marginInlineStart: "0.5rem"
  }}>
          再起動せずに変更可能
        </div>}
      {changeable_without_restart && <div style={{
    overflowWrap: "anywhere"
  }}>
          {changeable_without_restart}
        </div>}
    </div>;
};

これらの設定は [system.settings](/ja/reference/system-tables/settings) で確認でき、[ソース](https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/Settings.cpp) から自動生成されています。

<div id="optimize_rewrite_aggregate_function_with_if">
  ## optimize\_rewrite\_aggregate\_function\_with\_if
</div>

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

論理的に等価な場合、引数に if 式を持つ集約関数を書き換えます。
たとえば、`avg(if(cond, col, null))` は `avgOrNullIf(cond, col)` に書き換え可能です。これにより、パフォーマンスが向上する場合があります。

<Note>
  アナライザ (`enable_analyzer = 1`) でのみサポートされます。
</Note>

<div id="optimize_rewrite_array_exists_to_has">
  ## optimize\_rewrite\_array\_exists\_to\_has
</div>

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

論理的に等価な場合、arrayExists() 関数を has() に書き換えます。たとえば、arrayExists(x -> x = 1, arr) は has(arr, 1) に書き換えられます

<div id="optimize_rewrite_has_to_in">
  ## optimize\_rewrite\_has\_to\_in
</div>

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

最初の引数が定数配列の場合、`has` 関数を `IN` に書き換えます。たとえば、`has([1, 2, 3], x)` は、定数配列に対するパフォーマンス向上のため、`x IN [1, 2, 3]` に書き換えることができます

<div id="optimize_rewrite_like_perfect_affix">
  ## optimize\_rewrite\_like\_perfect\_affix
</div>

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

完全なプレフィックスまたは接尾辞を持つ LIKE 式 (例: `col LIKE 'ClickHouse%'`) を、startsWith または endsWith 関数 (例: `startsWith(col, 'ClickHouse')`) に書き換えます。

<div id="optimize_rewrite_regexp_functions">
  ## optimize\_rewrite\_regexp\_functions
</div>

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

正規表現関連の関数を、より単純で効率的な形式に書き換えます

<div id="optimize_rewrite_sum_if_to_count_if">
  ## optimize\_rewrite\_sum\_if\_to\_count\_if
</div>

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

論理的に等価な場合、sumIf() および sum(if()) 関数を countIf() 関数に書き換えます
