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

# 쿼리에서 프로젝션 사용 여부를 확인하는 방법

> 샘플 데이터로 테스트하고 EXPLAIN으로 프로젝션 사용 여부를 검증해 ClickHouse 쿼리에서 프로젝션이 사용되는지 확인하는 방법을 알아봅니다.

<div id="question">
  ## 질문
</div>

프로젝션 사용 여부는 어떻게 확인하나요?

<div id="answer">
  ## 답변
</div>

1. 샘플 데이터베이스를 생성합니다

```
CREATE database db1;
```

2. column1을 기본 키(primary key)로 사용하는 예제 테이블을 생성합니다.

```
CREATE table db1.table1_projections
(
 column1 Int32,
 column2 Int32
)
engine = MergeTree()
order by column1;
```

3. column2를 기본 키(primary key)로 사용하기 위해 프로젝션 `for_column2`를 추가합니다

```
ALTER table db1.table1_projections add projection for_column2
(
  select * 
  order by column2
);
```

4. 테스트 데이터 삽입

\*이 작업은 column1과 column2에 임의의 숫자가 포함된 100000개의 행을 삽입합니다

```
INSERT INTO db1.table1_projections
select 
 floor(randNormal(50, 5)) as column1,
 floor(randUniform(1, 100)) as column2
from numbers(100000);
```

5. 샘플 데이터 세트 확인

```
clickhouse-cloud :) SELECT * from db1.table1_projections limit 5;

SELECT *
FROM db1.table1_projections
LIMIT 5

Query id: d6940799-b507-4a5e-9843-df55ebe818ab

┌─column1─┬─column2─┐
│      28 │      41 │
│      29 │      12 │
│      30 │      73 │
│      30 │      75 │
│      30 │      70 │
└─────────┴─────────┘
```

6. column1이 있는 원본 테이블을 사용하고 있는지 확인합니다:

```
clickhouse-cloud :) explain indexes = 1 
                    SELECT count() from db1.table1_projections where column1 > 50;

EXPLAIN indexes = 1
SELECT count()
FROM db1.table1_projections
WHERE column1 > 50

Query id: e04d5236-1a05-4f1f-9502-7e41986beb44

┌─explain────────────────────────────────────────────┐
│ Expression ((Projection + Before ORDER BY))        │
│   Aggregating                                      │
│     Expression (Before GROUP BY)                   │
│       Filter (WHERE)                               │
│         ReadFromMergeTree (db1.table1_projections) │
│         Indexes:                                   │
│           PrimaryKey                               │
│             Condition: true                        │
│             Parts: 1/1                             │
│             Granules: 12/12                        │
└────────────────────────────────────────────────────┘
```

\*`db1.table1_projections`에서 읽고 있다는 점을 확인하십시오

7. WHERE 절에서 column2를 사용해 프로젝션에서 읽는지 테스트하십시오

```
clickhouse-cloud :) explain indexes = 1 
                    SELECT * from db1.table1_projections where column2 > 50;

EXPLAIN indexes = 1
SELECT *
FROM db1.table1_projections
WHERE column2 > 50

Query id: d2b20e01-93bf-4b60-a370-4aac7b454267

┌─explain─────────────────────────────────────┐
│ Expression ((Projection + Before ORDER BY)) │
│   Filter                                    │
│     ReadFromMergeTree (for_column2)         │
│     Indexes:                                │
│       PrimaryKey                            │
│         Keys:                               │
│           column2                           │
│         Condition: (column2 in [51, +Inf))  │
│         Parts: 1/1                          │
│         Granules: 6/12                      │
└─────────────────────────────────────────────┘
```

\*이제 `for_column2` 프로젝션이 사용된다는 점에 유의하십시오.

**추가 정보**

프로젝션:
[https://clickhouse.com/docs/sql-reference/statements/alter/projection](https://clickhouse.com/docs/sql-reference/statements/alter/projection)

numbers 테이블 함수: [https://clickhouse.com/docs/sql-reference/table-functions/numbers](https://clickhouse.com/docs/sql-reference/table-functions/numbers)s

무작위 데이터 생성 관련 블로그:
[https://clickhouse.com/blog/generating-random-test-distribution-data-for-clickhouse](https://clickhouse.com/blog/generating-random-test-distribution-data-for-clickhouse)
