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

# materialize_statistics_on_insert_* セッション設定

> materialize_statistics_on_insert_* 生成グループに属する 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](/docs/ja/reference/system-tables/settings) で確認でき、[ソース](https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/Settings.cpp) から自動生成されます。

<div id="materialize_statistics_on_insert">
  ## materialize\_statistics\_on\_insert
</div>

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.8"},{"label": "1"},{"label": "materialize_statistics_on_insert_max_table_size 未満のテーブルでは、デフォルトで INSERT 時にカラム統計をマテリアライズします。これにより、新たにロードされたディメンションテーブルに対するコストベースの join 順序変更で適切な推定値が得られます。"}]}, {"id": "row-2","items": [{"label": "26.4"},{"label": "0"},{"label": "デフォルトで INSERT 時に統計を構築しないようにし、代わりにマージに任せます"}]}, {"id": "row-3","items": [{"label": "24.6"},{"label": "1"},{"label": "INSERT 時の統計のマテリアライズを無効にできる新しい設定を追加しました"}]}]} />

有効な場合、INSERT 時に統計が構築され、挿入されます。無効な場合、統計はマージ中または明示的な MATERIALIZE STATISTICS によって構築・保存されます。現在のテーブルサイズと書き込まれるブロックのサイズの合計が `materialize_statistics_on_insert_max_table_size` を超えないテーブルのみが対象です。

<div id="materialize_statistics_on_insert_max_table_size">
  ## materialize\_statistics\_on\_insert\_max\_table\_size
</div>

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.8"},{"label": "26843545600"},{"label": "新しい設定: 現在のサイズと挿入ブロックのサイズの合計がこのしきい値を下回るテーブルに対してのみ、INSERT 時にカラム統計をマテリアライズします。previous_value=0（上限なし）であるため、26.8 より前のバージョンとの `compatibility` を設定すると従来の動作に戻ります（この PR より前にはサイズ上限がなかったため、`materialize_statistics_on_insert` を明示的に再有効化したユーザーは、テーブルサイズにかかわらず統計を引き続きマテリアライズします）。"}]}]} />

ディスク上のアクティブなパーツの現在の合計サイズ (圧縮後、バイト単位) に、書き込み中のブロックの非圧縮インメモリサイズを加えた値がこの値を超えないテーブルに対してのみ、INSERT 時にカラム統計を構築・保存します (`materialize_statistics_on_insert` を参照) 。この仕様は INSERT 単位ではなく、書き込みブロック単位で適用されます。1 回の INSERT はパーティションごとに 1 ブロックに分割され (ストリーミング挿入の場合は複数ブロックに分割され) 、進行中の INSERT によるパーツはまだアクティブではないため、各ブロックはすでにアクティブなパーツのサイズに対してチェックされます。したがって、空のテーブルへの 1 回の一括ロードでは、合計サイズがしきい値を超えていても、すべてのパーツについて統計を構築できます。上限が適用されるのは、その後の INSERT からです。パーツが書き込まれるまでは圧縮サイズが不明であるため、非圧縮ブロックサイズを使用することで、チェックは最大 1 ブロック分だけ意図的に保守的になります。これにより、コストベースの join 順序変更で重要な小規模ディメンションテーブルの統計を最新に保ちつつ、大規模ファクトテーブルでの INSERT ごとのオーバーヘッドを回避します (これらの統計は代わりにマージ中に構築されます) 。`0` はサイズ上限なしを意味します。
