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

> MergeTree 테이블의 각 (파트, 컬럼, 서브스트림)에서 코덱별로 사용되는 압축 블록 수를 보고합니다.

# mergeTreeCodecBlockCounts

MergeTree 테이블의 (파트, 컬럼, 서브스트림)별로 각 코덱을 사용하는 압축 블록 수를 보고합니다. 이를 통해 기본 코덱이 설정된 컬럼에서 블록별로 코덱을 선택할 수 있는 적응형 코덱 선택(`allow_experimental_adaptive_codec_selection` 설정으로 활성화됨)을 확인할 수 있습니다.

`codec_block_counts`를 선택하면 메타데이터뿐 아니라 `.bin` 데이터 파일도 읽습니다. 다른 컬럼은 메타데이터만 읽습니다.

`columns_substreams.txt`에 서브스트림을 기록하지 않는 파트는 나열되지 않습니다.

현재 사용자에게 해당 테이블의 행 정책이 적용되면, 정책으로 숨겨진 행까지 개수에 포함되므로 `codec_block_counts`를 읽을 때 `ACCESS_DENIED`가 발생합니다. 다른 컬럼은 계속 읽을 수 있으며, `system.parts_columns`는 행 정책과 관계없이 이를 보고합니다.

<div id="syntax">
  ## 구문
</div>

```sql theme={null}
mergeTreeCodecBlockCounts(database, table)
```

<div id="arguments">
  ## 인수
</div>

| 인수         | 설명                    |
| ---------- | --------------------- |
| `database` | 테이블이 속한 데이터베이스 이름입니다. |
| `table`    | MergeTree 테이블 이름입니다.  |

<div id="returned-value">
  ## 반환 값
</div>

원본 테이블의 각 (활성 파트, 컬럼, 서브스트림) 조합에 대해 하나의 행을 포함하는 테이블 객체입니다.

* `part_name` ([String](/docs/ko/reference/data-types/string)) — 컬럼이 속한 활성 데이터 파트입니다.
* `column` ([String](/docs/ko/reference/data-types/string)) — 컬럼명입니다.
* `substream` ([String](/docs/ko/reference/data-types/string)) — 카운트가 집계되는 컬럼의 물리적 스트림입니다. `system.parts_columns.substreams`와 일치합니다.
* `data_compressed_bytes` ([Nullable(UInt64)](/docs/ko/reference/data-types/nullable)) — 서브스트림의 압축된 데이터 크기(바이트)입니다. `Compact` 파트에서는 `NULL`입니다.
* `data_uncompressed_bytes` ([Nullable(UInt64)](/docs/ko/reference/data-types/nullable)) — 서브스트림의 비압축 데이터 크기(바이트)입니다. `Compact` 파트에서는 `NULL`입니다.
* `codec_block_counts` ([Map(String, UInt64)](/docs/ko/reference/data-types/map)) — 코덱별로 그룹화한 이 서브스트림의 압축 블록 수입니다. 컬럼이 하나의 데이터 파일을 공유하므로 스트림별 코덱 정보가 없는 `Compact` 파트에서는 비어 있습니다.

<div id="usage-example">
  ## 사용 예시
</div>

```sql theme={null}
CREATE TABLE mt (a UInt64) ENGINE = MergeTree ORDER BY a
SETTINGS min_bytes_for_wide_part = 0;

INSERT INTO mt SELECT number FROM numbers(100000);

SELECT column, substream, codec_block_counts
FROM mergeTreeCodecBlockCounts(currentDatabase(), mt);
```

```text theme={null}
┌─column─┬─substream─┬─codec_block_counts─┐
│ a      │ a         │ {'LZ4':13}         │
└────────┴───────────┴────────────────────┘
```

컬럼별 합계는 [`sumMap`](/docs/ko/reference/functions/aggregate-functions/sumMap)을 사용하는 `GROUP BY column`입니다.

```sql theme={null}
SELECT column, sumMap(codec_block_counts)
FROM mergeTreeCodecBlockCounts(currentDatabase(), mt)
GROUP BY column;
```

`LowCardinality` 컬럼은 딕셔너리와 인덱스 스트림을 각각 별도로 보고합니다:

```sql theme={null}
CREATE TABLE mt_lc (s LowCardinality(String)) ENGINE = MergeTree ORDER BY tuple()
SETTINGS min_bytes_for_wide_part = 0;

INSERT INTO mt_lc SELECT toString(number % 1000) FROM numbers(1000000);

SELECT substream, codec_block_counts
FROM mergeTreeCodecBlockCounts(currentDatabase(), mt_lc)
WHERE column = 's'
ORDER BY substream;
```

```text theme={null}
┌─substream─┬─codec_block_counts─┐
│ s         │ {'LZ4':31}         │
│ s.dict    │ {'LZ4':1}          │
└───────────┴────────────────────┘
```
