본문 바로가기
C.W.K.
Stream
Lesson 02 of 05 · published

Star vs Snowflake — 언제 그리고 왜

~9 min · modeling, schema, kimball

Level 0구경꾼
0 XP0/47 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

두 layout

  • Star schema. Dimension 하나가 비정규화된 테이블 하나야. dim_customersname, country, region, segment 가 한 row 에 다 들어 있어. 그림을 그리면 fact 테이블이 가운데, dimension 이 사방으로 뻗어 — 그래서 "star".
  • Snowflake schema. Dimension 을 더 정규화한 거야. dim_customersregion_key, dim_regionscontinent_key, 그 너머에 dim_continents. Dimension 에서 sub-dimension 이 갈라져 나가는 모양 — 그래서 "snowflake".

김빠지는 진실

분석 작업에선 star 가 거의 항상 이겨. 이유는 이래:

  • Query 당 join 이 적어 — 실행은 빨라지고 SQL 은 또렷해져.
  • BI 도구가 star schema 위에선 깔끔한 query 를 만들어 내.
  • 비정규화된 dimension 은 머리에 넣기도 쉬워.
  • Storage 는 싸 — 비정규화로 몇 byte 더 쓰는 비용은 가독성이 벌어 주는 것에 비하면 없는 셈이야.

Snowflake schema 의 자리도 있긴 해 — sub-dimension 이 거대하고 독립적으로 변할 땐 떼어내는 게 맞을 수 있어. 그래도 새 분석 warehouse 의 default 는 star schema 고, snowflake 는 평평하게 두는 비용이 구체적으로 아플 때만 가는 길이야.

Code

같은 dimension, 두 layout·sql
-- Star: 단일 비정규화 customer dimension
CREATE TABLE dim_customers (
    customer_key  INTEGER PRIMARY KEY,
    customer_id   TEXT NOT NULL,
    name          TEXT,
    region_code   TEXT,                         -- 'KR', 'US', 'JP'
    region_name   TEXT,                         -- 'Korea', 'United States', 'Japan'
    continent     TEXT                          -- 'Asia', 'North America'
);

-- Snowflake: customers → regions → continents
CREATE TABLE dim_customers_snow (
    customer_key  INTEGER PRIMARY KEY,
    customer_id   TEXT NOT NULL,
    name          TEXT,
    region_key    INTEGER REFERENCES dim_regions(region_key)
);
CREATE TABLE dim_regions (
    region_key    INTEGER PRIMARY KEY,
    region_code   TEXT NOT NULL,
    region_name   TEXT,
    continent_key INTEGER REFERENCES dim_continents(continent_key)
);
CREATE TABLE dim_continents (
    continent_key INTEGER PRIMARY KEY,
    name          TEXT NOT NULL
);

-- 대륙별 매출 query:
--   star:  fact JOIN dim_customers              (1 join)
--   snow:  fact JOIN dim_customers_snow JOIN dim_regions JOIN dim_continents (3 join)

External links

Exercise

이전 연습에서 스케치한 dimensional model 의 dimension 마다 결정해 봐: star 야, snowflake 야? Dimension 하나에 한 문장씩 근거를 달아. 이것도 습관 만들기 연습이야 — star 가 기본값이고, snowflake 는 그럴 만한 이유를 입 밖에 내서 말할 수 있을 때만.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.