Skip to content

Commit 15f26c0

Browse files
committed
join algorithm
1 parent 2f61691 commit 15f26c0

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

_posts/2024-11-27-join_algorithms.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
title: "조인 알고리듬의 구현"
3+
excerpt: "Implementation of Join Algorithms"
4+
categories:
5+
- data
6+
tags:
7+
- data
8+
- cs
9+
last_modified_at: 2024-11-27T08:00:00-08:00
10+
---
11+
12+
# 단일 머신 조인 알고리즘
13+
14+
## Nested Loop Join
15+
16+
```sudo
17+
for each tuple r in R do begin
18+
for each tuple s in S do begin
19+
if r and s satisfy the join condition
20+
output the tuple <r, s>
21+
end
22+
end
23+
```
24+
- 인덱스를 필요로 하지 않는다.
25+
- 동등 조인이 아닌 경우에도 사용 가능하다.
26+
- 시간 복잡도는 $O(n^2)$이다.
27+
28+
## Sort-Merge Join
29+
30+
```sudo
31+
while not at the end of either relation do begin
32+
if r and s match on the join attribute
33+
output the tuple <r, s>
34+
if r < s
35+
advance to the next tuple in R
36+
else advance to the next tuple in S
37+
end
38+
```
39+
- 조인 컬럼으로 정렬되어 있어야 한다.
40+
- 정렬되어 있다면 시간 복잡도는 $O(n)$이다.
41+
- 투 포인터 알고리즘과 유사하다.
42+
- 동등 조인만 가능하다.
43+
44+
## Hash Join
45+
46+
```sudo
47+
for each tuple s in S do begin
48+
insert s into hash table H
49+
end
50+
for each tuple r in R do begin
51+
if there is a tuple s in H that matches hash(r) then
52+
output the tuple <r, s>
53+
end
54+
```
55+
- 동등 조인만 가능하다.
56+
- S를 build input이라 하고 R을 probe input이라 한다.
57+
- 크기가 작은 테이블을 build input으로 사용하는 것이 좋다.
58+
- 해시 테이블은 메모리보다 작아야 하기 때문이다.
59+
- 시간 복잡도는 $O(n)$이다.
60+
61+
# Apache Spark의 조인 알고리즘
62+
63+
# 참고
64+
- Database System Concepts, 7th Edition. *Abraham Silberschatz, Henry F. Korth, S. Sudarshan. McGraw-Hill Education. 2019.*
65+
-

0 commit comments

Comments
 (0)