본문으로 바로가기
본문으로 바로가기

INFORMATION_SCHEMA

INFORMATION_SCHEMA (또는: information_schema)는 데이터베이스 객체의 메타데이터에 대해 (어느 정도) 표준화된 DBMS 독립적 뷰를 제공하는 시스템 데이터베이스입니다. INFORMATION_SCHEMA의 뷰는 일반적으로 일반 system 테이블에 비해 제공하는 정보가 제한적이지만, 도구에서 이를 사용하여 서로 다른 DBMS 전반에 걸쳐 기본 정보를 얻을 수 있습니다. INFORMATION_SCHEMA의 뷰 구조와 내용은 이전 버전과 호환되는 방식으로 진화하도록 되어 있으며, 즉 새로운 기능만 추가되고 기존 기능은 변경되거나 제거되지 않습니다. 내부 구현 관점에서 INFORMATION_SCHEMA의 뷰는 보통 system.columns, system.databases, system.tables와 같은 일반 system 테이블에 매핑됩니다.

SHOW TABLES FROM INFORMATION_SCHEMA;

-- or:
SHOW TABLES FROM information_schema;
┌─name────────────────────┐
│ COLUMNS                 │
│ KEY_COLUMN_USAGE        │
│ REFERENTIAL_CONSTRAINTS │
│ SCHEMATA                │
| STATISTICS              |
│ TABLES                  │
│ VIEWS                   │
│ columns                 │
│ key_column_usage        │
│ referential_constraints │
│ schemata                │
| statistics              |
│ tables                  │
│ views                   │
└─────────────────────────┘

INFORMATION_SCHEMA에는 다음 뷰들이 포함됩니다:

대소문자를 구분하지 않는 동등한 뷰, 예를 들어 INFORMATION_SCHEMA.columns는 다른 데이터베이스와의 호환성을 위해 제공됩니다. 이 뷰들에 포함된 모든 컬럼에도 동일하게 적용되며, 소문자(예: table_name)와 대문자(TABLE_NAME) 형식이 모두 제공됩니다.

컬럼

system.columns 시스템 테이블에서 읽은 컬럼과, ClickHouse에서 지원되지 않거나 의미가 없어 항상 NULL이지만, 표준에서 요구하기 때문에 포함되어야 하는 컬럼을 포함합니다.

컬럼:

예시

쿼리:

SELECT table_catalog,
       table_schema,
       table_name,
       column_name,
       ordinal_position,
       column_default,
       is_nullable,
       data_type,
       character_maximum_length,
       character_octet_length,
       numeric_precision,
       numeric_precision_radix,
       numeric_scale,
       datetime_precision,
       character_set_catalog,
       character_set_schema,
       character_set_name,
       collation_catalog,
       collation_schema,
       collation_name,
       domain_catalog,
       domain_schema,
       domain_name,
       column_comment,
       column_type
FROM INFORMATION_SCHEMA.COLUMNS
WHERE (table_schema = currentDatabase() OR table_schema = '')
  AND table_name NOT LIKE '%inner%' 
LIMIT 1 
FORMAT Vertical;

결과:

Row 1:
──────
table_catalog:            default
table_schema:             default
table_name:               describe_example
column_name:              id
ordinal_position:         1
column_default:
is_nullable:              0
data_type:                UInt64
character_maximum_length: ᴺᵁᴸᴸ
character_octet_length:   ᴺᵁᴸᴸ
numeric_precision:        64
numeric_precision_radix:  2
numeric_scale:            0
datetime_precision:       ᴺᵁᴸᴸ
character_set_catalog:    ᴺᵁᴸᴸ
character_set_schema:     ᴺᵁᴸᴸ
character_set_name:       ᴺᵁᴸᴸ
collation_catalog:        ᴺᵁᴸᴸ
collation_schema:         ᴺᵁᴸᴸ
collation_name:           ᴺᵁᴸᴸ
domain_catalog:           ᴺᵁᴸᴸ
domain_schema:            ᴺᵁᴸᴸ
domain_name:              ᴺᵁᴸᴸ

SCHEMATA

system.databases 시스템 테이블에서 읽은 컬럼과, ClickHouse에서 지원하지 않거나 의미가 없어 항상 NULL이지만 표준에 따라 존재해야 하는 컬럼들을 포함합니다.

컬럼:

  • catalog_name (String) — 데이터베이스 이름입니다.
  • schema_name (String) — 데이터베이스 이름입니다.
  • schema_owner (String) — 스키마 소유자 이름으로, 항상 'default'입니다.
  • default_character_set_catalog (Nullable(String)) — NULL, 지원되지 않습니다.
  • default_character_set_schema (Nullable(String)) — NULL, 지원되지 않습니다.
  • default_character_set_name (Nullable(String)) — NULL, 지원되지 않습니다.
  • sql_path (Nullable(String)) — NULL, 지원되지 않습니다.

예시

쿼리:

SELECT catalog_name,
       schema_name,
       schema_owner,
       default_character_set_catalog,
       default_character_set_schema,
       default_character_set_name,
       sql_path
FROM information_schema.schemata
WHERE schema_name ILIKE 'information_schema' 
LIMIT 1 
FORMAT Vertical;

결과:

Row 1:
──────
catalog_name:                  INFORMATION_SCHEMA
schema_name:                   INFORMATION_SCHEMA
schema_owner:                  default
default_character_set_catalog: ᴺᵁᴸᴸ
default_character_set_schema:  ᴺᵁᴸᴸ
default_character_set_name:    ᴺᵁᴸᴸ
sql_path:                      ᴺᵁᴸᴸ

테이블

system.tables 시스템 테이블에서 읽은 컬럼을 포함합니다.

컬럼:

  • table_catalog (String) — 테이블이 위치한 데이터베이스 이름입니다.
  • table_schema (String) — 테이블이 위치한 데이터베이스 이름입니다.
  • table_name (String) — 테이블 이름입니다.
  • table_type (String) — 테이블 유형입니다. 가능한 값:
    • BASE TABLE
    • VIEW
    • FOREIGN TABLE
    • LOCAL TEMPORARY
    • SYSTEM VIEW
  • table_rows (Nullable(UInt64)) — 전체 행 수입니다. 결정할 수 없는 경우 NULL입니다.
  • data_length (Nullable(UInt64)) — 디스크에 저장된 데이터의 크기입니다. 결정할 수 없는 경우 NULL입니다.
  • index_length (Nullable(UInt64)) — 기본 키, 보조 인덱스, 그리고 모든 마크의 전체 크기입니다.
  • table_collation (Nullable(String)) — 테이블 기본 콜레이션(collation)입니다. 항상 utf8mb4_0900_ai_ci입니다.
  • table_comment (Nullable(String)) — 테이블 생성 시 사용된 주석입니다.

예시

쿼리:

SELECT table_catalog, 
       table_schema, 
       table_name, 
       table_type, 
       table_collation, 
       table_comment
FROM INFORMATION_SCHEMA.TABLES
WHERE (table_schema = currentDatabase() OR table_schema = '')
  AND table_name NOT LIKE '%inner%'
LIMIT 1 
FORMAT Vertical;

결과:

Row 1:
──────
table_catalog:   default
table_schema:    default
table_name:      describe_example
table_type:      BASE TABLE
table_collation: utf8mb4_0900_ai_ci
table_comment:   

VIEWS

테이블 엔진 View가 사용될 때 system.tables 시스템 테이블에서 읽은 컬럼을 포함합니다.

컬럼:

  • table_catalog (String) — 테이블이 위치한 데이터베이스의 이름.
  • table_schema (String) — 테이블이 위치한 데이터베이스의 이름.
  • table_name (String) — 테이블 이름.
  • view_definition (String) — 뷰에 대한 SELECT 쿼리.
  • check_option (String) — NONE, 검사하지 않음.
  • is_updatable (Enum8) — NO, 뷰가 업데이트되지 않음.
  • is_insertable_into (Enum8) — 생성된 뷰가 materialized인지 여부를 나타냅니다. 가능한 값은 다음과 같습니다.
    • NO — 생성된 뷰가 구체화되지 않음.
    • YES — 생성된 뷰가 구체화됨.
  • is_trigger_updatable (Enum8) — NO, 트리거가 업데이트되지 않음.
  • is_trigger_deletable (Enum8) — NO, 트리거가 삭제되지 않음.
  • is_trigger_insertable_into (Enum8) — NO, 트리거에 데이터가 삽입되지 않음.

예시

쿼리:

CREATE VIEW v (n Nullable(Int32), f Float64) AS SELECT n, f FROM t;
CREATE MATERIALIZED VIEW mv ENGINE = Null AS SELECT * FROM system.one;
SELECT table_catalog,
       table_schema,
       table_name,
       view_definition,
       check_option,
       is_updatable,
       is_insertable_into,
       is_trigger_updatable,
       is_trigger_deletable,
       is_trigger_insertable_into
FROM information_schema.views
WHERE table_schema = currentDatabase() 
LIMIT 1
FORMAT Vertical;

결과:

Row 1:
──────
table_catalog:              default
table_schema:               default
table_name:                 mv
view_definition:            SELECT * FROM system.one
check_option:               NONE
is_updatable:               NO
is_insertable_into:         YES
is_trigger_updatable:       NO
is_trigger_deletable:       NO
is_trigger_insertable_into: NO

KEY_COLUMN_USAGE

제약 조건으로 제한되는 system.tables 시스템 테이블의 컬럼을 포함합니다.

컬럼:

  • constraint_catalog (String) — 현재 사용되지 않습니다. 항상 def입니다.
  • constraint_schema (String) — 제약 조건이 속한 스키마(데이터베이스)의 이름입니다.
  • constraint_name (Nullable(String)) — 제약 조건의 이름입니다.
  • table_catalog (String) — 현재 사용되지 않습니다. 항상 def입니다.
  • table_schema (String) — 테이블이 속한 스키마(데이터베이스)의 이름입니다.
  • table_name (String) — 제약 조건이 적용된 테이블의 이름입니다.
  • column_name (Nullable(String)) — 제약 조건이 적용된 컬럼의 이름입니다.
  • ordinal_position (UInt32) — 현재 사용되지 않습니다. 항상 1입니다.
  • position_in_unique_constraint (Nullable(UInt32)) — 현재 사용되지 않습니다. 항상 NULL입니다.
  • referenced_table_schema (Nullable(String)) — 현재 사용되지 않습니다. 항상 NULL입니다.
  • referenced_table_name (Nullable(String)) — 현재 사용되지 않습니다. 항상 NULL입니다.
  • referenced_column_name (Nullable(String)) — 현재 사용되지 않습니다. 항상 NULL입니다.

예시

CREATE TABLE test (i UInt32, s String) ENGINE MergeTree ORDER BY i;
SELECT constraint_catalog,
       constraint_schema,
       constraint_name,
       table_catalog,
       table_schema,
       table_name,
       column_name,
       ordinal_position,
       position_in_unique_constraint,
       referenced_table_schema,
       referenced_table_name,
       referenced_column_name
FROM information_schema.key_column_usage 
WHERE table_name = 'test' 
FORMAT Vertical;

결과:

Row 1:
──────
constraint_catalog:            def
constraint_schema:             default
constraint_name:               PRIMARY
table_catalog:                 def
table_schema:                  default
table_name:                    test
column_name:                   i
ordinal_position:              1
position_in_unique_constraint: ᴺᵁᴸᴸ
referenced_table_schema:       ᴺᵁᴸᴸ
referenced_table_name:         ᴺᵁᴸᴸ
referenced_column_name:        ᴺᵁᴸᴸ

REFERENTIAL_CONSTRAINTS

외래 키에 대한 정보를 포함합니다. 현재는 결과가 비어 있습니다(행 없음). 이는 Tableau Online과 같은 서드파티 도구와의 호환성을 유지하기에 충분합니다.

컬럼:

  • constraint_catalog (String) — 현재 사용되지 않습니다.
  • constraint_schema (String) — 현재 사용되지 않습니다.
  • constraint_name (Nullable(String)) — 현재 사용되지 않습니다.
  • unique_constraint_catalog (String) — 현재 사용되지 않습니다.
  • unique_constraint_schema (String) — 현재 사용되지 않습니다.
  • unique_constraint_name (Nullable(String)) — 현재 사용되지 않습니다.
  • match_option (String) — 현재 사용되지 않습니다.
  • update_rule (String) — 현재 사용되지 않습니다.
  • delete_rule (String) — 현재 사용되지 않습니다.
  • table_name (String) — 현재 사용되지 않습니다.
  • referenced_table_name (String) — 현재 사용되지 않습니다.

STATISTICS

테이블 인덱스에 대한 정보를 제공합니다. 현재는 빈 결과(행 없음)를 반환합니다. 이는 Tableau Online과 같은 서드파티 도구와의 호환성을 확보하기에는 충분합니다.

컬럼:

  • table_catalog (String) — 현재 사용되지 않습니다.
  • table_schema (String) — 현재 사용되지 않습니다.
  • table_name (String) — 현재 사용되지 않습니다.
  • non_unique (Int32) — 현재 사용되지 않습니다.
  • index_schema (String) — 현재 사용되지 않습니다.
  • index_name (Nullable(String)) — 현재 사용되지 않습니다.
  • seq_in_index (UInt32) — 현재 사용되지 않습니다.
  • column_name (Nullable(String)) — 현재 사용되지 않습니다.
  • collation (Nullable(String)) — 현재 사용되지 않습니다.
  • cardinality (Nullable(Int64)) — 현재 사용되지 않습니다.
  • sub_part (Nullable(Int64)) — 현재 사용되지 않습니다.
  • packed (Nullable(String)) — 현재 사용되지 않습니다.
  • nullable (String) — 현재 사용되지 않습니다.
  • index_type (String) — 현재 사용되지 않습니다.
  • comment (String) — 현재 사용되지 않습니다.
  • index_comment (String) — 현재 사용되지 않습니다.
  • is_visible (String) — 현재 사용되지 않습니다.
  • expression (Nullable(String)) — 현재 사용되지 않습니다.