INFORMATION_SCHEMA 시스템 데이터베이스

INFORMATION_SCHEMA 시스템 데이터베이스

INFORMATION_SCHEMA(또는 information_schema)는 데이터베이스 객체의 메타데이터에 대한 (어느 정도) 표준화된, DBMS에 구애받지 않는 뷰를 제공하는 시스템 데이터베이스예요. INFORMATION_SCHEMA의 뷰는 일반적으로 일반 시스템 테이블보다 못하지만, 도구가 DBMS를 넘나드는 방식으로 기본 정보를 얻는 데 사용할 수 있어요.

출처: 문서

본문

INFORMATION_SCHEMA(또는: information_schema)는 데이터베이스 객체의 메타데이터에 대한 (어느 정도) 표준화된, DBMS-agnostic 뷰를 제공하는 시스템 데이터베이스예요. INFORMATION_SCHEMA의 뷰는 일반적으로 일반 시스템 테이블보다 못하지만, 도구가 DBMS를 넘나드는 방식으로 기본 정보를 얻는 데 사용할 수 있어요. INFORMATION_SCHEMA의 뷰 구조와 내용은 하위 호환되는 방식으로 진화한다고 가정돼요, 즉 새 기능만 추가되고 기존 기능은 변경되거나 제거되지 않아요. 내부 구현 측면에서 INFORMATION_SCHEMA의 뷰는 보통 system.columns, system.databases, system.tables 같은 일반 시스템 테이블에 매핑돼요.

SHOW TABLES FROM INFORMATION_SCHEMA;

-- or:
SHOW TABLES FROM information_schema;
┌─name────────────────────┐
│ COLLATIONS              │
│ 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) 변형이 모두 제공돼요.

COLUMNS

system.columns 시스템 테이블에서 읽은 열과, ClickHouse에서 지원되지 않거나 의미가 없지만 표준상 있어야 하는 열(항상 NULL)을 담고 있어요. Columns:

  • 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)) — 현재 사용되지 않음.

ExampleQuery

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;

Response

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)을 담고 있어요. Columns:

  • 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, 지원되지 않음.

ExampleQuery

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;

Response

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:                      ᴺᵁᴸᴸ

TABLES

system.tables 시스템 테이블에서 읽은 열을 담고 있어요. Columns:

  • 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)) — 기본 키, 보조 인덱스, 모든 marks의 총 크기.
  • table_collation (Nullable(String)) — 테이블 기본 collation. 항상 utf8mb4_0900_ai_ci.
  • table_comment (Nullable(String)) — 테이블을 만들 때 사용된 주석.

ExampleQuery

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;

Response

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 시스템 테이블에서 읽은 열을 담고 있어요. Columns:

  • 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 — 생성된 뷰가 materialized가 아님, YES — 생성된 뷰가 materialized.
  • is_trigger_updatable (Enum8) — NO, 트리거가 갱신되지 않음.
  • is_trigger_deletable (Enum8) — NO, 트리거가 삭제되지 않음.
  • is_trigger_insertable_into (Enum8) — NO, 트리거에 데이터가 삽입되지 않음.

ExampleQuery

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;

Response

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 시스템 테이블의 열을 담고 있어요. Columns:

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

ExampleQuery

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;

Response

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 같은 타사 도구와 호환성을 제공하기에 충분해요. Columns:

  • 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 같은 타사 도구와 호환성을 제공하기에 충분해요.

COLLATIONS

사용 가능한 collation에 대한 정보를 제공해요. system.collations의 collation에 추가로 두 개의 MySQL 호환 행을 담고 있어요: utf8mb4_0900_ai_ci — MySQL 프로토콜이 핸드셰이크, SCHEMATA.DEFAULT_COLLATION_NAME, TABLES.TABLE_COLLATION에서 광고하는 collation — 과 binary — MySQL 프로토콜이 결과 집합 메타데이터의 숫자 및 기타 비문자열 열에 찍는 의사 collation — 그래서 광고된 collation을 따라 이 뷰로 들어오는 MySQL 인식 클라이언트가 그것들을 찾을 수 있어요. Columns:

  • collation_name (String) — collation의 이름.
  • character_set_name (Nullable(String)) — 연관된 문자 집합(utf8mb4_0900_ai_ci에 대해 utf8mb4, binary에 대해 binary, 그 외에는 NULL). MySQL 호환을 위해 제공돼요.
  • id (Nullable(UInt64)) — MySQL collation id(utf8mb4_0900_ai_ci에 대해 255, binary에 대해 63, 그 외에는 NULL). MySQL 호환을 위해 제공돼요.
  • is_default (Nullable(String)) — collation이 해당 문자 집합의 기본인지 여부(두 MySQL 호환 행 모두 Yes, 그 외에는 NULL). MySQL 호환을 위해 제공돼요.
  • is_compiled (Nullable(String)) — collation이 서버에 컴파일되었는지 여부(두 MySQL 호환 행 모두 Yes, 그 외에는 NULL). MySQL 호환을 위해 제공돼요.
  • sortlen (Nullable(UInt64)) — 최소 정렬 길이(utf8mb4_0900_ai_ci에 대해 0, binary에 대해 1, 그 외에는 NULL). MySQL 호환을 위해 제공돼요.
  • pad_attribute (Nullable(String)) — 패드 속성, NO PAD 또는 PAD SPACE(두 MySQL 호환 행 모두 NO PAD, 그 외에는 NULL). MySQL 호환을 위해 제공돼요.

더 알아보기 (Learn more)