> ## 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](/ko/reference/system-tables/settings)에서 확인할 수 있으며, [소스 코드](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` 컬럼의 모든 고유 조합에 대한 해시 테이블을 만드는 대신 O(1) 메모리로 스트리밍 방식으로 필터링합니다. 정렬된 데이터가 여러 스트림으로 도착하고 동일한 `BY` 값이 둘 이상의 스트림에 나타날 수 있으면, 먼저 각 스트림을 스트리밍 방식으로 그룹당 최대 `LIMIT + OFFSET`개의 행만 남도록 미리 필터링한 다음 스트림을 결합하고, 마지막으로 해시 기반 `LIMIT BY`를 적용해 여러 스트림에 걸친 그룹의 중복을 제거합니다. 이 마지막 단계에서도 `BY` 컬럼의 모든 고유 조합에 대한 항목을 유지하지만, 미리 필터링된 행만 처리합니다.
