Build Hash Table流程
- 1、初始化
row buffer
- 2、從
build input table
中讀一行 - 3、若讀完
build input table
所有row,返回狀態READING_ROW_FROM_PROBE_item
- 4、否則,向
hash map
中寫入一條row - 5、如果
hash map
寫入成功,返回2,繼續執行 - 6、若
hash map
滿了,則寫chunk file
- 1、初始化
chunk file
- 2、將剩余的row寫入
chunk file
- 3、返回狀態
READING_ROW_FROM_PROBE_item
流程圖如下:
- 1、初始化
Write Rows to chunks流程
- 1、從
input
表(build 或者 probe)讀row - 2、寫入
chunk file
- 1、構造
join key
- 2、計算
hash key
并選擇chunk file
- 3、寫入相應的
chunk file
中
流程圖如下:
- 1、構造
單線程hash join 步驟
step1:初始化
- build table init
- memory buffer init
- create hash map
- probe table init
- state 設為
Reading_Row_From_Probe_Iterator
step2:HashJoinIteratorRead,根據state做調整
-
(1)、state為
Reading Row from probe iterator
- 1、從
probe table
read一行row - 2、如果所有
probe input row
都讀完了- 如果非
spill to disk
,對build input
剩余的row構造hash map
,重新對probe
表做init,回到1繼續 - 如果為
spill to disk
,goto(2)
- 如果非
- 3、如果
build input
有chunk file
,將probe input
表寫入chunk file
- 4、從
hash map
里查找probe input
row的查詢結果 - 5、goto(4)
- 1、從
-
(2)、state為
Loading next chunk pair
- 找到下一對
chunk pair
做hash join
- 找到下一對
-
(3)、state為
Reading row from probe input file
,讀一個probe chunk
的row做hash join
- 1、從
probe chunk
讀一行row - 2、在
hash table
里查詢匹配 - 3、goto(4)
- 1、從
-
(4)、state為
Reading from hash table
,讀取hash table
中匹配記錄- 1、將查到的
row buffer
寫入build input
表的record[0]
中 - 2、若讀取完
hash table
中記錄,goto(1)或者(3)
- 1、將查到的
狀態流程圖: