Skip to content

Commit

Permalink
Update 2023-09-04-join-algorithms.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Cheng authored Sep 4, 2023
1 parent c4f6ad5 commit e1ba418
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions _posts/2023-09-04-join-algorithms.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ ClickHouse目前(2023年3月的版本)有6种JOIN连接算法:


### Hash Join
Hash join算法是通过哈希表查表的连接运算算法。

![hash.png](https://raw.githubusercontent.com/Alex-Cheng/alex-cheng.github.io/fbbb2a85c19e1866c0fd70749c5ef6a6b6b74f1b/_posts/images/hash_4131734f7e.png)

Expand All @@ -70,6 +71,7 @@ ClickHouse目前(2023年3月的版本)有6种JOIN连接算法:


### Parallel Hash
Parallel hash join算法是在Hash join算法基础上引入了“分桶-多哈希表”的方式增加并行度而形成的连接算法。

![parallel_hash.png](https://raw.githubusercontent.com/Alex-Cheng/alex-cheng.github.io/fbbb2a85c19e1866c0fd70749c5ef6a6b6b74f1b/_posts/images/parallel_hash_6e944127fa.png)

Expand All @@ -92,11 +94,11 @@ ClickHouse目前(2023年3月的版本)有6种JOIN连接算法:


### Grace Hash
Grace hash join算法是在Hash join算法中加上“分而治之”的策略。

![grace_hash_1.png](https://raw.githubusercontent.com/Alex-Cheng/alex-cheng.github.io/fbbb2a85c19e1866c0fd70749c5ef6a6b6b74f1b/_posts/images/grace_hash_1_97a605582f.png)



工作原理:

1. 右侧表中的所有数据都被读取(通过 2 个线程并行,因为 max_threads = 2)并按照分区哈希函数进行分桶,把属于第一个桶的数据填充到内存中的哈希表中,其他桶的数据临时存放在外存中,按桶区分(注意不是内存);
Expand Down Expand Up @@ -181,9 +183,6 @@ Full sorting merge join算法利用了两个有序表之间可以直接匹配的
> 假设表T的排序键是A、B、C,Join Key A、B就是属于这种情况。




### Partial Merge Join

Partial merge join算法与Full sorting merge join算法类似,不同的是它不会全局排序左表,只会排序右表并按数据块存储在外存中,并建立min-max索引(该索引记录了每个数据块的最小Join Key和最大Join Key)。扫描左表执行JOIN连接运算。
Expand Down

0 comments on commit e1ba418

Please sign in to comment.