๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐“ก๐“ธ๐“ธ๐“ถ5: ๐’ฆ๐‘œ๐“‡๐‘’๐’ถ ๐’ฐ๐“ƒ๐’พ๐“‹/Database(COSE371)

[๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค] CH7. Relational Database Design(Normalization)

0. Intro

1. Features of Good Relational Design

  • ์šฐ๋ฆฌ๊ฐ€ instructor ๊ณผ department๋ฅผ in_dep์ด๋ผ๋Š” table๋กœ ํ•ฉ์ณค๋‹ค๊ณ  ์ƒ๊ฐํ•ด๋ณด์ž.
    ์ด๋Ÿฌ๋ฉด ๊ฐ™์€ dept ์ •๋ณด๊ฐ€ ๊ณ„์† ๋ฐ˜๋ณตํ•ด์„œ ๋“ค์–ด๊ฐ€๊ณ , ๋งŒ์•ฝ ํ•™๊ณผ๊ฐ€ ์ƒˆ๋กœ ๋งŒ๋“ค์–ด ์กŒ์„ ๋•Œ ๊ต์ˆ˜์ž๊ฐ€ ์•„์ง ์—†๋‹ค๋ฉด null๊ฐ’์œผ๋กœ ๋„ฃ์–ด ์ถ”๊ฐ€ํ•ด์•ผ ํ•˜๋Š” ๋ฌธ์ œ๋„ ๋ฐœ์ƒํ•œ๋‹ค. ์‹ฌ์ง€์–ด id๊ฐ€ not null์ด๋ฉด ์ด๊ฒƒ๋„ ๋ถˆ๊ฐ€๋Šฅ ํ•˜๋‹ค.

  • ์ฆ‰, ๋ฌด์กฐ๊ฑด table์„ ํ•ฉ์นœ๋‹ค๊ณ  ์ข‹์€ ๊ฒƒ์ด ์•„๋‹ˆ๋‹ค.

    Combined schema without repetition

  • ๊ทธ๋Ÿฌ๋‚˜ ํ•ฉ์นœ๋‹ค๊ณ  ๋˜ ๋ฌด์กฐ๊ฑด ์ค‘๋ณต์ด ์ƒ๊ธฐ๋Š” ๊ฑด ์•„๋‹ˆ๋‹ค.
  • sec_class์™€ section์„ ํ•ฉ์น  ๊ฒฝ์šฐ ์ค‘๋ณต๋˜๋Š” ์ •๋ณด๊ฐ€ ์—†๊ฒŒ ๋œ๋‹ค.

2. Decomposition : table ์ชผ๊ฐœ๊ธฐ.

์šฐ๋ฆฌ๊ฐ€ ์•ž์„œ ๋ณธ in_dep schema์˜ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋ ค๋ฉด table์„ ๋‘ ๊ฐœ๋กœ ์ชผ๊ฐœ์•ผ ํ•œ๋‹ค. (instructor๊ณผ department)
๊ทผ๋ฐ ๋˜ ๋ชจ๋“  decomposition์ด ์ข‹์€ ๊ฑด ์•„๋‹ˆ๋‹ค.

employee(ID, name, street, city, salary) ๋ฅผ
employee1(ID, name)
employee2(name, street, city, salary)๋กœ ์ชผ๊ฐœ๊ฐœ ๋˜๋ฉด

๋งŒ์•ฝ ๋™๋ช…์ด์ธ์ด ์žˆ์„ ๊ฒฝ์šฐ joinํ•  ๋•Œ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.

๋™๋ช…์ด์ธ์žˆ์œผ๋ฉด ์ •๋ณด ์ผ๋ถ€๊ฐ€ ๋‚ ๋ผ๊ฐ€ ์›๋ž˜์˜ table๋กœ ๋ณต์›์ด ๋ถˆ๊ฐ€ํ•˜๊ฒŒ ๋˜๋Š”๋ฐ ์ด๋ฅผ lossy decomposition์ด๋ผ๊ณ  ํ•œ๋‹ค.

(๋ฐ์ดํ„ฐ ์–‘(tuple)์€ ์ฆ๊ฐ€ํ•˜๋Š”๋ฐ information์€ ๋ˆ„๋ฝ(less)๋œ๋‹ค)

Lossless Decomposition

-> Table์„ ๋‹ค์‹œ ํ•ฉ์ณค์„ ๋•Œ ์ •๋ณด ๋ˆ„๋ฝ์ด ์—†๋„๋ก ํ•˜๋Š” decomposition (<-> lossy)

3. Normalization Theory

: relation schema R์ด ์ง€๊ธˆ ํ˜„์žฌ 'good' ํ•œ ํ˜•ํƒœ์ธ์ง€ decideํ•˜๋Š” ์ด๋ก .
๋งŒ์•ฝ good form ์ด ์•„๋‹ˆ๋ผ๋ฉด, decomposeํ•ด์„œ relation์„ ์ชผ๊ฐœ์•ผ ํ•œ๋‹ค. (๋‹น์—ฐํžˆ ์ชผ๊ฐ  ํ›„์— relation์€ good form์ด์–ด์•ผ ํ•˜๊ณ , lossless decomposition์ด์–ด์•ผํ•จ)

ํฌ๊ฒŒ ๋‘ ๊ฐœ๋กœ ๋‚˜๋ˆ„์–ด ์‚ดํŽด๋ณผ ๊ฒƒ !

  1. Functional dependencies
  2. Multivalued dependencies

1. Funtional dependency

  • ์šฐ๋ฆฌ๊ฐ€ ์‚ด์•„๊ฐ€๋Š” ์„ธ์ƒ์˜ ๋ฐ์ดํ„ฐ์—๋Š” ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์ œํ•œ (constraints, rule)์ด ์กด์žฌํ•œ๋‹ค.

  • ์ด๋Ÿฌํ•œ ๋ชจ๋“  real-world constraints๋ฅผ ๋งŒ์กฑํ•˜๋Š” relation์˜ instance๋ฅผ legal instance ๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค.
    ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ legal instance๋Š” relation์˜ instance๊ฐ€ ๋ชจ๋‘ legal instance์ผ ๋•Œ๋ฅผ ๋งํ•œ๋‹ค.

  • functional dependency : legal relations์˜ constraints๋กœ ์ธํ•ด ํŠน์ • attributes์˜ ์ง‘ํ•ฉ์ด ๋‹ค๋ฅธ set of attribute๋ฅผ ์œ ์ผํ•˜๊ฒŒ ๊ฒฐ์ •ํ•˜๋„๋ก ํ•ด์•ผํ•œ๋‹ค.
    ๋ง์ด ์–ด๋ ต๊ธด ํ•œ๋ฐ, ๊ทธ๋ƒฅ key ๊ฐœ๋…์„ ์ผ๋ฐ˜ํ™” ํ•œ ๊ฒƒ
    legal instance๋ฅผ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด ์กฐ๊ฑด์„ ์ถ”๊ฐ€ํ•จ์œผ๋กœ ์ธํ•ด ํŠน์ • attribute๊ฐ„์˜ ์ข…์†์„ฑ์ด ์ƒ์„ฑ๋œ๋‹ค.

relation R์— a, b attribute๊ฐ€ ์žˆ์„ ๋•Œ,

functional dependency a -> b๋Š” a๊ฐ€ ๊ฒฐ์ •๋จ์— ๋”ฐ๋ผ b๊ฐ€ ๊ฒฐ์ •๋  ๋•Œ์— ์–ด๋–ค legal relations r(R)์— ๋Œ€ํ•ด์„œ hold on R ๋œ๋‹ค.
์ฆ‰ ์•ž์˜ ๊ฒƒ์ด UNIQUE ํ•  ๋•Œ ๋’ค์˜ ๊ฒƒ์ด ํ•˜๋‚˜๋กœ ๊ฒฐ์ •๋˜๋Š” ๊ฒฝ์šฐ๋ฅผ functional dependency ๊ฐ€ HOLD ๋œ๋‹ค๊ณ  ๋งํ•œ๋‹ค.

Closure of a set of functional dependencies

๋งŒ์•ฝ A->B, B->C๋ผ๋Š” Functional dependency๊ฐ€ ์žˆ๋‹ค๋ฉด ์šฐ๋ฆฐ A->C๋„ hold๋จ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค. ์ด๋Ÿฐ ์‹์œผ๋กœ funstional dependencies ์˜ ์ง‘ํ•ฉ F๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, F๋กœ ๋ถ€ํ„ฐ ์ถ”๋ก ํ•ด์„œ ์–ป์–ด ๋‚ผ ์ˆ˜ ์žˆ๋Š” ๋ชจ๋“  functional dependency๋ฅผ closure of F๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค.

F+ ๋ผ๊ณ  ํ‘œ๊ธฐํ•œ๋‹ค.

Keys and Functional Dependency

  • K๊ฐ€ relation schema R์˜ superkey๋ผ๊ณ  ํ•˜๋ฉด, K->R์ด๋‹ค. (๋ฐ˜๋Œ€๋„ ์„ฑ๋ฆฝํ•œ๋‹ค.)

  • K๊ฐ€ candidate key๋ผ๋ฉด

    1. K->R
    2. a โŠ‚ K, a->R ์ธ ๋˜๋‹ค๋ฅธ a ๋Š” ์กด์žฌํ•˜์ง€ ์•Š์Œ
  • fd๋Š” ์šฐ๋ฆฌ๊ฐ€ superkey๋กœ๋Š” ํ‘œํ˜„ํ•˜์ง€ ๋ชปํ–ˆ๋˜ constraints๋ฅผ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค.

Use of Functional Dependencies

  1. ์ฃผ์–ด์ง„ functional dependencies์—์„œ relation์ด legalํ•œ์ง€ ํ™•์ธํ•œ๋‹ค.

    • ๋งŒ์•ฝ functional dependencies F ์•„๋ž˜์—์„œ, relation instance r์ด legalํ•˜๋‹ค๋ฉด r satisfies F๋ผ๊ณ  ๋งํ•œ๋‹ค.
  2. legal relations์˜ ์ง‘ํ•ฉ์— constraints๋ฅผ ์ง€์ •ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•œ๋‹ค.

    • ๋งŒ์•ฝ R์˜ ๋ชจ๋“  legal relation์ด funtional dependencies F๋ฅผ ๋งŒ์กฑํ•œ๋‹ค๋ฉด F holds on R ๋ผ๊ณ  ๋งํ•œ๋‹ค.

    satisfy๋Š” ํŠน์ • instance๊ฐ€ fd๋ฅผ ๋งŒ์กฑํ•˜๋Š” ๊ฒƒ, hold๋Š” ์Šคํ‚ค๋งˆ ์ž์ฒด๊ฐ€ legalํ•œ ๊ฒƒ.
    holdํ•˜์ง€ ์•Š๋”๋ผ๋„ ์šฐ์—ฐํžˆ satisfy๋Š” ํ•  ์ˆ˜ ์žˆ์Œ

Trivial Functional Dependencies

  • ๋‹น์—ฐํ•œ ์‚ฌ์‹ค๋“ค (์ž๋ช…ํ•œ ๊ฒƒ๋“ค)

    ex) ID , NAME -> ID
    NAME -> NAME

  • ๋ณดํ†ต a->b ์—์„œ bโŠ†a ์ผ ๋•Œ trivial ํ•˜๋‹ค๊ณ  ๋งํ•จ

Lossless Decomposition

  • functional dependency๋ฅผ ์ด์šฉํ•ด decomposition์ด lossless ํ•œ์ง€ ์•„๋‹Œ์ง€๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

    R = (R1, R2)๊ฐ€ ์žˆ์„ ๋•Œ, R์„ R1๊ณผ R2๋กœ decompositionํ•  ๋•Œ, ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ข…์†์„ฑ์„ ์ ์–ด๋„ ํ•˜๋‚˜ F+๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ์–ด์•ผ lossless decomposition์ด๋ผ๊ณ  ํ•  ์ˆ˜ ์žˆ๋‹ค.

  1. R1 โˆฉ R2 -> R1
  2. R1 โˆฉ R2 -> R2

์œ„ functional dependency๋Š” loseless join decomposition์„ ์œ„ํ•ด ํ•„์š”ํ•œ ์กฐ๊ฑด์ด๋‹ค.
์œ„ dependency๋Š” ๋ชจ๋“  constraints๊ฐ€ functional dependencies์ธ ๊ฒฝ์šฐ์—๋งŒ ํ•„์š”ํ•œ ์กฐ๊ฑด์ด๋‹ค.

์˜ˆ๋ฅผ ๋ณด์ž.

R=(A, B, C)
F = {A->B, B->C}

R1 = (A, B), R2= (B, C)
R1 โˆฉ R2 = {B} AND B->BC

R1 = (A,B) , R2 = (A, C)
R1 โˆฉ R2 = {A} AND A -> AB

์ฐธ๊ณ ๋กœ, AB = {A, B}๋ผ๊ณ  ๋ณด๋ฉด ๋จ

์œ„ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋‹ˆ๊นŒ ๋‘˜ ๋‹ค ์˜ฌ๋ฐ”๋ฅธ Decomposition!

Dependency Preservation

: dependency constraints๊ฐ€ ์ง€์ผœ์กŒ๋Š”์ง€ ์•„๋‹Œ์ง€๋ฅผ ๋งค๋ฒˆ join์„ ํ•ด๋ด์•ผ ์•„๋Š”์ง€, ์•„๋‹ˆ๋ฉด ๋ฐ”๋กœ ์•Œ ์ˆ˜ ์žˆ๋Š”์ง€ ์—ฌ๋ถ€๊ฐ€ ์ด๊ฒƒ!

  • ๋””๋น„๊ฐ€ ์—…๋ฐ์ดํŠธ ๋  ๋•Œ ๋งˆ๋‹ค fd constraints๋ฅผ ํ…Œ์ŠคํŠธํ•˜๋ ค๋ฉด ๋น„์šฉ์ด ๋งŽ์ด ๋“ค ์ˆ˜ ์žˆ๋‹ค.
    • ๋”ฐ๋ผ์„œ ์ œ์•ฝ ์กฐ๊ฑด์„ ํšจ์œจ์ ์œผ๋กœ ํ…Œ์ŠคํŠธ ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋””๋น„๋ฅผ ์„ค๊ณ„ํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค
    • ํ•˜๋‚˜์˜ relation๋งŒ ๊ณ ๋ คํ•ด fd constraint๋ฅผ ํ…Œ์ŠคํŠธํ•  ์ˆ˜ ์žˆ๋‹ค๋ฉด ๋น„์šฉ์ด ์ ๊ฒŒ ๋“ ๋‹ค.
    • ๊ทธ๋Ÿฌ๋‚˜ decomposing ๊ณผ์ •์—์„œ ์นด๋ฅดํ…Œ์ง€์•ˆ ๊ณฑ์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š์œผ๋ฉด ํ…Œ์ŠคํŠธ๋ฅผ ํ•  ์ˆ˜ ์—†๊ฒŒ ๋˜๊ธฐ๋„ ํ•จ

functional dependency๋ฅผ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด join์„ ํ•ด์•ผ ํ•˜๋Š” ๋“ฑ, ์–ด๋ ต๊ฒŒ ๋งŒ๋“œ๋Š” decomposition์˜ ๊ฒฝ์šฐ, NOT dependency preserving ์ด๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด์„œ dept_advisor(s_ID, i_ID, department_name) ์ด ์žˆ๋‹ค๊ณ  ์น˜์ž.
์—ฌ๊ธฐ์— fd๋Š”
i_id -> dept_name
s_id, dept_name -> i_id

์ด ๊ฒฝ์šฐ instructor๊ฐ€ dept_advisor relation์— ์ฐธ์—ฌํ•  ๋•Œ๋งˆ๋‹ค department_name์„ ๊ณ„์† ๋ฐ˜๋ณตํ•ด์„œ ์ ์–ด์ค˜์•ผ ํ•œ๋‹ค.
์ด ์ค‘๋ณต์„ฑ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋ ค๋ฉด decomposing์„ ํ•ด์ค˜์•ผ ํ•˜๋Š”๋ฐ, ์ด ๊ฒฝ์šฐ ์–ด๋–ป๊ฒŒ ๋‚˜๋ˆ ๋„ s_id, dept_name -> i_id๋ฅผ ํฌํ•จํ•  ์ˆ˜ ์—†์œผ๋ฏ€๋กœ ์ด decomposition์€ not dependency preserving ํ•˜๋‹ค๊ณ  ๋งํ•  ์ˆ˜ ์žˆ๋‹ค.

1. Normal Forms

1. BCNF (Boyce-Codd Normal Form)

a -> b ์ผ ๋•Œ

  1. a -> b๊ฐ€ trivial ํ•˜๋‹ค
  2. a๊ฐ€ R์˜ superkey์ด๋‹ค.

F+์˜ ๋ชจ๋“  functional dependencies๊ฐ€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋Š” ๊ฒฝ์šฐ relation schema R์ด BCNF๋ฅผ ๋งŒ์กฑํ•œ๋‹ค๊ณ  ํ•  ์ˆ˜ ์žˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด in_dep(ID, name, salary, dept_name, building, budget)
์ด ์žˆ๊ณ 
dept_name -> building , budget ์ด๋ผ๋Š” fd๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ
hold๋ฅผ ํ•˜๊ธด ํ•˜๋Š”๋ฐ, dept_name์ด superkey๋Š” ์•„๋‹ˆ๋ฏ€๋กœ BCNF ๊ฐ€ ์•„๋‹ˆ๋‹ค.

๋งŒ์•ฝ Violation of BCNF๊ฐ€ ์ผ์–ด๋‚  ๊ฒฝ์šฐ, Decompose๋ฅผ ํ•ด์ค˜์•ผ ํ•œ๋‹ค. ์–ด๋–ป๊ฒŒ?

  1. a โˆช B
  2. R - (b-a)

์ด๋ ‡๊ฒŒ.

์œ„์˜ ์˜ˆ๋กœ ๋‹ค์‹œ ํ•ด๋ณด๋ฉด

a = dept_name
b= building, budget

์ด๋‹ˆ๊นŒ

a โˆช B = (dept_name, building, budget)
R - (b-a) = (ID, name, dept_name, salary)

๊ฐ€ ๋œ๋‹ค.

BCNF and Dependency Preservation

-> BCNF์™€ dependency preserving decomposition์„ ์–ธ์ œ๋‚˜ ๋™์‹œ์— ๋งŒ์กฑ ์‹œํ‚ฌ ์ˆ˜๋Š” ์—†๋‹ค

dept_advisor(s_ID, i_ID, department_name)
i_id -> dept_name
s_id, dept_name -> i_id

๊ฐ€ ์žˆ์„ ๋•Œ,
i_id๊ฐ€ superkey๊ฐ€ ์•„๋‹ˆ๋ฏ€๋กœ decomposition์„ ํ•ด์•ผํ•œ๋‹ค.

๊ทผ๋ฐ ์ด ์•„์ด๋“ค์€ 3๊ฐœ๊ฐ€ ๋‹ค ์“ฐ์˜€์œผ๋ฏ€๋กœ ์–ด๋–ป๊ฒŒ ์ชผ๊ฐœ๋„ dependency ์œ ์ง€๊ฐ€ ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค.
๋”ฐ๋ผ์„œ ์ด decomposition ์€ not be dependency preserving ์ด๋‹ค.

2. 3NF (Third Normal Form)

  • 3NF๋Š” ์กฐ๊ธˆ ๋” ์™„ํ™”๋œ ํ˜•ํƒœ์˜ normal form์ด๋‹ค.
  1. a -> b๊ฐ€ trivial ํ•˜๋‹ค
  2. a๊ฐ€ R์˜ superkey์ด๋‹ค.
  3. b-a ์— ์žˆ๋Š” attribute๊ฐ€ R์˜ candidate key์— ํฌํ•จ์ด ๋œ๋‹ค.

์ด ์…‹ ์ค‘ ํ•˜๋‚˜ ๋งŒ์กฑ์‹œํ‚ค๋ฉด 3NF!

dept_advisor(s_ID, i_ID, department_name)
i_id -> dept_name
s_id, dept_name -> i_id

๋‹ค์‹œ ์ด๊ฑธ ๋ณด์ž.
s_id, dept_name์€ superkey์ด๋‹ค.
i_id๋Š” superkey๋Š” ์•„๋‹ˆ์ง€๋งŒ,
{dept_name} - {i_id} = {dept_name} ์ด๊ณ  dept_name์€ candidate key์— ํฌํ•จ๋˜๋ฏ€๋กœ
3NF๋Š” ๋งŒ์กฑํ•˜๊ฒŒ ๋œ๋‹ค.

Redundancy in 3NF

  • repetition of information
  • need to use null values

Comparison of BCNF and 3NF

  • 3NF๋Š” ์–ธ์ œ๋‚˜ lossless ํ•˜๊ณ  dependency preservingํ•œ 3NF design์„ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค.
  • ๊ทธ๋Ÿฌ๋‚˜ ๋ฐ์ดํ„ฐ ๊ฐ„์˜ ์˜๋ฏธ์žˆ๋Š” ๊ด€๊ณ„ ์ค‘ ์ผ๋ถ€๋ฅผ ๋‚˜ํƒ€๋‚ด๋ ค๋ฉด null ๊ฐ’์„ ์‚ฌ์šฉํ•ด์•ผ ํ•  ์ˆ˜๋„ ์žˆ๊ณ , ์ •๋ณด์˜ repetition์ด ์ผ์–ด๋‚˜๊ธฐ๋„ ํ•œ๋‹ค.

Goals of Normalization

  • R ์ด๋ผ๋Š” relation schema์™€ F ๋ผ๋Š” Functional dependencies๊ฐ€ ์žˆ์„ ๋•Œ, ์ด R์ด "good" form์ธ์ง€ ํŒ๋ณ„ํ•˜๊ณ , ์•„๋‹ˆ๋ผ๋ฉด relation์„ decomposeํ•œ๋‹ค.
  • ์ด ๋•Œ ๊ฐ relation schema๋Š” good form์ด์–ด์•ผ ํ•˜๋ฉฐ, lossless decomposition์ด์–ด์•ผ ํ•˜๊ณ , dependency preserving ํ•ด์•ผ ํ•œ๋‹ค.

3. Higher Normal Form

4NF(Fourth Normal Form)

2. Funtional Dependency Theory

1. Closure of a set of functional dependency

  • F๋กœ๋ถ€ํ„ฐ ์ถ”๋ก ๋  ์ˆ˜ ์žˆ๋Š” ๋ชจ๋“  functional dependencies๋ฅผ closure๋ผ๊ณ  ํ•œ๋‹ค.

Armstrong's Axioms

  1. Reflexive rule : b โŠ† a ์ด๋ฉด a->b
  2. Augmentation rule : a->b์ด๋ฉด ra -> rb
  3. Transitivity rule : a->b์ด๊ณ  b->c์ด๋ฉด a->c
Sound : ๋„์ถœํ•ด๋‚ธ ๋ฌธ์žฅ์ด ์ „๋ถ€ true์ธ ๊ฒฝ์šฐ(๋ฐ˜๋ก€X ์ „๋ถ€๋‹ค ์ฐพ์€ ๊ฑด ์•„๋‹ ์ˆ˜ ์žˆ์Œ)
Complete : true์ธ ๋ฌธ์žฅ์€ ์ „๋ถ€ ๋„์ถœํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ (์ „๋ถ€๋‹ค ์ฐพ์•˜์ง€๋งŒ ์•„๋‹Œ ๊ฒƒ๋„ ์„ž์—ฌ์žˆ์„ ์ˆ˜ ์žˆ์Œ)

Addition rules

  1. Union Rule : a->b , a->r ์ด๋ฉด a->br
  2. Decomposition rule : a->br ์ด๋ฉด a->b ๊ทธ๋ฆฌ๊ณ  a->r
  3. Pseudotransitivity rule : a->b์ด๊ณ  rb->q ์ด๋ฉด ar -> q ์ด๋‹ค.
    ์–˜๋„ค๋Š” ์•”์ŠคํŠธ๋กฑ ์–ด์ฉŒ๊ตฌ์—์„œ ์ถ”๋ก ํ•  ์ˆ˜ ์žˆ์Œ

F+ ๋ฅผ ๊ตฌํ•˜๋Š” ๋ฐฉ๋ฒ•

F์—์„œ ์‹œ์ž‘ํ•ด์„œ reflexivity, augmentation rules, combined using transitivy ๊ณผ์ •์„ ๊ฑฐ์ณ F+์— ์ถ”๊ฐ€ํ•ด๋‚˜๊ฐ„๋‹ค.

2. Closure of Attribute Sets

Attribute sets์˜ closure ๊ตฌํ•˜๊ธฐ

result := a;
while (changes to result) do
    for each b->r in F do
      begin
           if b โŠ† result then result := result โˆช r
      end

Usees of Attribute Closure

  1. Testing for superkey
    -> a๊ฐ€ superkey๋ผ๋ฉด a+๋Š” R ์˜ ๋ชจ๋“  attributes๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์–ด์•ผ ํ•œ๋‹ค.
  2. Testing functional dependencies
    -> fd a->b๊ฐ€ holdํ•œ์ง€ ๋ณด๋ ค๋ฉด b โŠ† a+๋ฅผ ๋งŒ์กฑํ•˜๋Š”์ง€ ํ™•์ธํ•ด๋ณด๋ฉด ๋œ๋‹ค.
    -> ๋งค์šฐ ์‰ฝ๊ณ  ๋น ๋ฅด๊ณ  ์œ ์šฉํ•œ ๋ฐฉ๋ฒ•.
  3. computing closure of F
    -> rโŠ†R์ด ์žˆ์„ ๋•Œ closure r+๋ฅผ ์ฐพ๊ณ  S โŠ† r+์— ๋Œ€ํ•ด r->S๋ฅผ output์œผ๋กœ ๋‚ด๋ณด๋‚ธ๋‹ค.

3. Canonical Cover

  • relation schema์— functional dependency F๊ฐ€ ์žˆ๋‹ค๊ณ  ํ•˜์ž. ์‚ฌ์šฉ์ž๊ฐ€ relation ์„ ์—…๋ฐ์ดํŠธ ํ•  ๋•Œ๋งˆ๋‹ค ๋””๋น„ ์‹œ์Šคํ…œ์€ ์ด ์‚ฌํ•ญ์ด F์˜ ๋ชจ๋“  dependency๋ฅผ ์ถฉ์กฑํ•˜๋Š”์ง€ ํ™•์ธํ•ด์•ผ ํ•œ๋‹ค.
  • ๋งŒ์•ฝ violateํ•œ๋‹ค๋ฉด update๋Š” roll back๋˜์–ด์•ผ ํ•œ๋‹ค.
  • ์šฐ๋ฆฌ๋Š” ์ฃผ์–ด์ง„ set์™€ ๊ฐ™์€ closure๋ฅผ ๊ฐ€์ง„, ๋” ๋‹จ์ˆœํ™” ๋œ functional dependency๋ฅผ ๊ฒ€์‚ฌํ•จ์œผ๋กœ์„œ ๋“œ๋Š” ๋น„์šฉ์„ ์ค„์ผ ์ˆ˜ ์žˆ๋‹ค.
  • ์ด ๋‹จ์ˆœํ™” ๋œ functional dependency ๋ฅผ canonical cover๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค

Extraneous Attributes

: ์—†์–ด๋„ ๋ฌด๋ฐฉํ•œ functional dependency์˜ attribute
-> ์ด๊ฑธ ๋‹ค ์—†์• ์•ผ canonical cover๋ฅผ ์ฐพ์„ ์ˆ˜ ์žˆ์Œ

  1. remove left side -> stronger
    AB -> C์—์„œ A->C๋กœ ์ค„์ด๋ฉด ์ข€ ๋” ๊ฐ•๋ ฅํ•ด์ง. A๋งŒ ์žˆ์–ด๋„ C๋ฅผ ์•Œ ์ˆ˜ ์žˆ์Œ
  • A โˆˆ a ์ด๊ณ  F ๊ฐ€ ๋…ผ๋ฆฌ์ ์œผ๋กœ (F - {a-b}) โˆช {(a - A)->b}๋ฅผ ์ถ”๋ก ํ•  ์ˆ˜ ์žˆ์„ ๊ฒฝ์šฐ A๋Š” extraneous ํ•˜๋‹ค.
  1. remove right side -> weaker
  • A โˆˆ b ์ด๊ณ  F ๊ฐ€ ๋…ผ๋ฆฌ์ ์œผ๋กœ (F - {a-b}) โˆช {(a->(b-A)}๋ฅผ ์ถ”๋ก ํ•  ์ˆ˜ ์žˆ์„ ๊ฒฝ์šฐ B๋Š” extraneous ํ•˜๋‹ค.
    AB -> CD์—์„œ AB->C๋กœ ์ค„์ด๋ฉด ์•ฝํ•ด์ง. AB๊ฐ€ ์žˆ์–ด๋„ D๋ฅผ ์•Œ ์ˆ˜ ์—†์Œ

Testing Extraneous

  1. A โˆˆ b ์ผ ๋•Œ extraneous ์ธ๊ฐ€

    • F'= (F - {a-b}) โˆช {(a - A)->b}
    • F' ์•ˆ์˜ a+๊ฐ€ A๋ฅผ ํฌํ•จํ•˜๋Š”์ง€ ํ™•์ธํ•ด๋ณด๊ณ  ๊ทธ๋ ‡๋‹ค๋ฉด A ๋Š” extraneous ํ•˜๋‹ค.
  2. A โˆˆ a ์ผ ๋•Œ extraneous ์ธ๊ฐ€

    • r = a - {A} ๋ผ๊ณ  ํ•˜์ž. r->B๊ฐ€ F๋กœ๋ถ€ํ„ฐ ์ถ”๋ก  ๊ฐ€๋Šฅํ•œ์ง€ ์ฒดํฌํ•œ๋‹ค.
    • r+ ๋ฅผ ๊ณ„์‚ฐํ•ด์„œ ์ด๊ฒŒ b์˜ ๋ชจ๋“  attribute๋ฅผ ํฌํ•จํ•œ๋‹ค๋ฉด A๋Š” extraneous ํ•˜๋‹ค.

    ์˜ˆ๋ฅผ ๋“ค์–ด๋ณด์ž

    F={AB->CD, A->E, E->C}
    C๋ฅผ Check ํ•ด๋ด…์‹œ๋‹ค.

    F' = {AB->D, A->E, E->C}
    ์ด๊ณ  ์ด CLOUSER๋Š” ABCDE์ด๋ฏ€๋กœ CD๋ฅผ ํฌํ•จํ•œ๋‹ค.
    ๋”ฐ๋ผ์„œ C๋Š” EXTRANEOUS ํ•˜๋‹ค.

    ์ฆ‰, C๊ฐ€ ์—†์–ด๋„ ๋‹ค ์œ ์ถ”๊ฐ€ ๊ฐ€๋Šฅํ•ด์„œ ํ•„์š” ์—†๋Š” ๊ฒƒ.

Canonical Cover

F์˜ canonical cover๋Š” Fc์ด๋‹ค.

  • F๋Š” Fc์— ์žˆ๋Š” ๋ชจ๋“  dependency๋ฅผ ์ถ”๋ก ํ•ด๋‚ผ ์ˆ˜ ์žˆ๋‹ค
  • Fc๋Š” F์— ์žˆ๋Š” ๋ชจ๋“  dependency๋ฅผ ์ถ”๋ก ํ•ด ๋‚ผ ์ˆ˜ ์žˆ๋”ฐ.
  • Fc์—๋Š” extraneous attribute๊ฐ€ ์žˆ์œผ๋ฉด ์•ˆ๋œ๋‹ค.
  • Fc์˜ functional dependency์˜ ์™ผ์ชฝ side๋Š” uniqueํ•ด์•ผ ํ•œ๋‹ค.
    a1-> b1 , a2->b2 ์ผ ๋•Œ a1 = a2 ์ด๋ฉด ์•ˆ๋จ.

canonical cover๋ฅผ ๊ตฌํ•ด๋ณด์ž

  1. F์— ์žˆ๋Š” dependency๋ฅผ union rule์„ ํ™œ์šฉํ•ด a1->b1, a1->b2 ๋ฅผ a1->b1b2 ๊ผด๋กœ ๋ฐ”๊ฟ”์ค€๋‹ค.
  2. a->b ์— ์žˆ๋Š” extraneous attribute๋ฅผ ์ฐพ์•„ ์—†์• ์ค€๋‹ค.
  3. ๋ฐ˜๋ณตํ•œ๋‹ค.

4. Dependency Preservation

  • ํ•˜๋‚˜์˜ relation ์•ˆ์—์„œ FD๊ฐ€ ํ™•์ธ ๊ฐ€๋Šฅํ•˜๋ฉด DEPENDENCY Preserving ํ•œ ๊ฒƒ.

  • *(F1 U F2 U F3 ...U Fn) + = F+

  • ์œ„์˜ ์ •์˜๋Œ€๋กœ dp๋ฅผ ํ…Œ์ŠคํŠธ ํ•˜๋ ค๋ฉด ์ง€์ˆ˜ํ•จ์ˆ˜์  ์‹œ๊ฐ„์ด ์†Œ์š”๋œ๋‹ค.
    (๋งŒ์•ฝ preserveํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด violation of functional dependency ๋ฅผ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด join์„ ๊ณ„์† ํ•ด์•ผํ•จ)

  • ๊ทธ๋Ÿฌ๋‚˜ restrinction์˜ ๋ชจ๋“  functional dependency๋Š” ์˜ค์ง ํ•˜๋‚˜์˜ relation schema์˜ attribute๋ฅผ ํฌํ•จํ•˜๊ณ  ์žˆ์œผ๋ฏ€๋กœ ํ•˜๋‚˜์˜ relation์„ ํ™•์ธํ•จ์œผ๋กœ์„œ dependency check๋ฅผ ํ•  ์ˆ˜ ์žˆ๋‹ค. (๋‹คํ•ญ์‹œ๊ฐ„์— ๊ฐ€๋Šฅ)

Testing for Dependency Preservation

result = a
repeat 
    for each Ri in the decomposition
        t = (result โˆฉ Ri)+ โˆฉ Ri
        result = result U t
until (result does not change)

๋งŒ์•ฝ result๊ฐ€ b์˜ ๋ชจ๋“  attribute๋ฅผ ๊ฐ€์ง€๊ณ  ใ…ฃใ…‡ใ…†๋‹ค๋ฉด functional dependency a->b๋Š” preservedํ•œ ๊ฒƒ.

3. Algorithm for Decomposition Using Functional Dependencies

2. Testing for BCNF

a->b๊ฐ€ violation of BCNF๋ฅผ ์•ผ๊ธฐํ•˜๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š”

  1. a+ ๊ณ„์‚ฐ
  2. ์ด a+๊ฐ€ R์˜ ๋ชจ๋“  attribute๋ฅผ ํฌํ•จํ•˜๋Š”์ง€, ์ฆ‰ R์˜ superkey์ธ์ง€ ํ™•์ธ

superkey๋ผ๋ฉด BCNF๋ฅผ ๋งŒ์กฑํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

Testing decomposition for BCNF

  1. ๊ฐ๊ฐ์˜ relation์— ๋Œ€ํ•ด์„œ fd๋ฅผ ์ฐพ์•„๋ด„
  2. ๊ฐ leftside์˜ attribute์˜ closure๊ฐ€ decomposition relation์˜ ๋ชจ๋“  attribute๋ฅผ ๊ฐ–๊ณ  ์žˆ๋Š”์ง€ ํ™•์ธ.
result := {R};
done := fasle;
compute F+;
while(not done) do
    if(BCNF๊ฐ€ ์•„๋‹Œ schema Ri๊ฐ€ result์— ์žˆ์„ ๊ฒฝ์šฐ)
        then begin
            nontribial functional dependency, Ri๋ฅผ hold, F+์— ์†ํ•˜์ง€ ์•Š์€ a->b, a โˆฉ b = โˆฎ์ผ ๋•Œ
            result := (result - Ri) โˆช (Ri - b) โˆช (a,b);
        end
    end done := true;

4. Third Normal Form

  • BCNF๋Š” dependency preserving์„ ์œ ์ง€ํ•˜์ง€ ๋ชปํ•œ๋‹ค.

  • efficient checking for FD violation on updates is important

    ๋”ฐ๋ผ์„œ weaker normal form ์ธ 3NF ์‚ฌ์šฉ

    • ์กฐ๊ธˆ์˜ ์ค‘๋ณต ํ—ˆ์šฉ

    • join ์—†์ด fd ํ™•์ธ ๊ฐ€๋Šฅ

    • ํ•ญ์ƒ lossless-join,, dependency-preserving decomposition

    • ๋Œ€์ถฉ NP hard ๋ฌธ์ œ์ž„.

5. Design Goal

๋ชฉํ‘œ๋Š” BCNF, Lossless join, Dependency preservation
๋งŒ์กฑ ๋ชปํ•œ๋‹ค๋ฉด ๋‘˜ ์ค‘ ํ•˜๋‚˜ ํฌ๊ธฐ
dependency preservation , BCNF
๋Œ€์‹  3NF ์“ด๋‹ค.

sql์—์„œ๋Š” ๊ณ ๋ คํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์„ค๊ณ„ํ•  ๋•Œ ๊ณ ๋ คํ•ด์•ผ ํ•จ.

4. Multivalued Dependencies

-> a ์— ๋”ฐ๋ผ b์˜ ๊ฐ’์ด ์ •ํ•ด์ง€๊ธด ํ•˜๋Š”๋ฐ, b๊ฐ€ multivalue์ธ ๊ฒฝ์šฐ๋ฅผ multivalued dependency๋ผ๊ณ  ํ•จ
์ด๋ฅผ

a->->b

๋กœ ํ‘œ๊ธฐํ•จ.

Use of Multivalued Dependency

multialed dependency๋Š” ๋‘๊ฐ€์ง€ ๋ฐฉ๋ฒ•์œผ๋กœ ์“ด๋‹ค.

  1. relation์—์„œ ์ฃผ์–ด์ง„ fdp, mdp ํ•˜์— legalํ•œ์ง€ ๊ฒฐ์ •ํ•œ๋‹ค
  2. legal relation ํ•˜์—์„œ constraints๋ฅผ ์ง€์ •ํ•œ๋‹ค.

mdp ์˜ ์ •์˜์— ๋”ฐ๋ฅด๋ฉด ์šฐ๋ฆฌ๋Š”
a->b์ด๋ฉด a->->b
๋ผ๋Š” ๊ทœ์น™์„ ๋„์ถœํ•  ์ˆ˜ ์žˆ๋‹ค. ์ฆ‰ ๋ชจ๋“  fdp๋Š” mdp์ด๋‹ค.

4NF

๋‹ค์Œ๊ณผ ๊ฐ™์€ ์กฐ๊ฑด ์ค‘ ํ•˜๋‚˜ ์ด์ƒ์„ ๋งŒ์กฑํ•˜๋ฉด ๋จ

  • a->->b is trivial
  • a is superke for schema R

4NF์ด๋ฉด BCNF์ด๊ธฐ๋„ ํ•จ.

First Normal Form

  • ๋ชจ๋“  attributes์˜ domain ์ด atomicํ•ด์•ผ ํ•จ.

Overall DB Design Process

  1. ER Diagram์„ table๋กœ ๋ณ€ํ™˜ํ•  ๋•Œ schema R์ด ์ƒ์„ฑ๋  ์ˆ˜ ์žˆ๋‹ค.
  2. R์€ ๋ชจ๋“  attribute๋ฅผ ํฌํ•จํ•˜๋Š” single relation์˜ nomalization์˜ ๊ฒฐ๊ณผ์ผ ์ˆ˜ ์žˆ๋”ฐ.
  3. R๋Š” ์šฐ๋ฆฌ๊ฐ€ test/conver normalformํ•˜๋Š” ad hoc design์˜ relation์˜ ๊ฒฐ๊ณผ์ผ ์ˆ˜ ใ…ฃใ…‡ใ…†๋”ฐ

๋ญ๋ผ๋Š”๊ฑฐใ…‘ใ…‡

ER model and Normalization

Denormalization for Performance

performance ๋•Œ๋ฌธ์— non-normalized schema๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์„ ์ˆ˜ ์žˆ์Œ.

๋Œ€์•ˆ 1. ๊ฑ deormalized relation ์‚ฌ์šฉ

  1. faster lookup ๊ฐ€๋Šฅ
  2. extra space and execution time for updates ํ•„์š”
  3. extra coding work for programmer and possibility of error in extra code

๋Œ€์•ˆ 2. view ์‚ฌ์šฉ

-> ์žฅ์ ๊ณผ ๋‹จ์  ์œ„์™€ ๊ฐ™์Œ. ๊ทธ๋Ÿฌ๋‚˜ ์ถ”๊ฐ€ ์ฝ”๋”ฉ ์ž‘์—…๊ณผ ์—๋Ÿฌ ๋ฐœ์ƒ์€ ํ”ผํ•  ์ˆ˜ ์žˆ์Œ