> ## 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_limit_* セッション設定

> optimize_limit_* の生成グループに含まれる 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) で参照でき、[source](https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/Settings.cpp) から自動生成されています。

<div id="optimize_limit_by_function_keys">
  ## optimize\_limit\_by\_function\_keys
</div>

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

LIMIT BY 句で、他のキーの関数になっているキーを除去します。

例: `LIMIT 5 BY x, f(x)` は `LIMIT 5 BY x` になります。

<div id="optimize_limit_by_in_order">
  ## optimize\_limit\_by\_in\_order
</div>

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

`<cols>` が (順不同で) テーブルのソートキーのプレフィックスを構成する場合、または `WHERE col = const` によって先頭のカラムが固定され、その結果プレフィックスになる場合に、`SELECT ... LIMIT N BY <cols>` クエリを最適化します。これを有効にすると、ログソースはプライマリキー順にデータを読み取るため、`BY` カラムの値が同じ行は各ストリーム内で隣り合って到着します。データが単一のソート済みストリームとして到着する場合、`LIMIT BY` は、出現した `BY` カラムの異なる組み合わせごとに hash table を構築する代わりに、O(1) メモリのストリーミングモードでフィルタリングします。ソート済みデータが複数のストリームに分かれて到着し、同じ `BY` の値が複数のストリームに現れる可能性がある場合は、まず各ストリームをストリーミングモードでグループごとに最大 `LIMIT + OFFSET` 行まで事前にフィルタリングし、その後ストリームを結合して、最後に hash ベースの `LIMIT BY` で複数のストリームにまたがるグループを重複排除します。この最終パスでも、`BY` カラムの異なる組み合わせごとに 1 つのエントリを保持しますが、処理するのは事前にフィルタリング済みの行だけです。
