데이터베이스설계

[데이터베이스설계] 2-5 Cartesian, Join operation

젼젼39 2024. 11. 14. 00:14
Cartesian 카티션 곱 => 릴레이션R X 릴레이션S
- 카티션 곱 연산을 사용하면 두 relation의 정보를 결합할 수 있음 (결과도 relation)
- 겹치는 attribute는 그 앞에 원래 relation의 이름을 붙여 구분함
      -> instructor.ID, teaches.ID
 
집합 r, s           // (1, a) à binary tuples | (g, h, i) -> ternary tuple | (1, x, g, h, i) -> 5-tuple
r = { 1, 2, 3, 4 } 이고 s = { a, b, c } 라면 r x s = { (1, a), (1, b), …  }         12개의 binary tuples
r = { (1, x), (2, y) } 이고 s = { (a, b, c), (d, e, f), (g, h, i) } 라면 r x s = { (1, x, a, b, c), (1, x, d, e, f), … }
Join
Operation

Join 연산 => r θ s = σ instructor.id = teaches.id (instructor x teaches)
 
- 카티션 곱은 각각의 relation의 모든 튜플들을 곱함 -> 대부분의 행에 의미없는 짝들이 있음
--> 카티션 곱 한 뒤에 select해서 의미있는 짝만 찾자는 게 join 연산
 
- join 연산을 사용하면 select σ 연산과 카티션 곱 연산을 단일 연산으로 결합할 수 있음
 
- 세타 조인 = θ 를 스키마 R union S attribute에 대한 조건이라고 했을 때,
  r θ s = σ θ ( r x s )
  instructor instructor.id = teaches.id teaches = σ instructor.id = teaches.id ( instructor x teaches )
  select *
  from instructor, teaches
  where instructor.id = teachers.id
 
- 동등 조인 equi join = 비교연산자가 = 인 경우 // instructor instructor.id = teaches.id teaches
 
- 자연조인 = 동등조인 중 중복속성 중 하나가 제거된 것 // instructor teaches