久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

數據庫中表連接方式有哪些

146次閱讀
沒有評論

共計 1843 個字符,預計需要花費 5 分鐘才能閱讀完成。

這篇文章將為大家詳細講解有關數據庫中表連接方式有哪些,丸趣 TV 小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

1 nested loop join

循環嵌套連接:行源 1 的每一條記錄,依次去匹配行源 2 的每條記錄,將符合連接條件的記錄放在結果集中,直到行源 1 的所有記錄都完成這個操作。循環嵌套連接是最基本也是最古老的表連接方式。

2 sort merge join

排序合并連接:行源 1 和行源 2 的數據分別排序,然后將兩個排序的源表合并,符合連接條件的記錄放到結果集中。由于排序需要內存空間,sort merge join 對內存有比較大的消耗,如果內存空間 (8i 為 sort_area_size,9i 及以上使用 PGA) 不足,則會使用臨時表空間,這樣會降低排序合并連接的效率。排序合并連接是最古老的表連接方式之一。

 

附上 tom 哥哥的解釋:

You Asked 
Tom,

What is the difference between Sort Merge and Hash Joins. Don t they both do a one
FULL scan each on the joining tables and join them?

I know Sort Merge is used in the case of ALL ROWS and Nested Loops in the case of
FIRST ROWS hints. How about Has Join? When is it used?

Would really appreciate if you could explain it with a couple of examples.

Thanks in advance. 

and we said…
Well, a sort merge of A and B is sort of like this:

   read A and sort by join key to temp_a
   read B and sort by join key to temp_b

   read a record from temp_a
   read a record from temp_b
   while NOT eof on temp_a and temp_b
   loop
     if (temp_a.key = temp_b.key) then output joined record
     elsif (temp_a.key = temp_b.key) read a record from temp_a
     elsif (temp_a.key = temp_b.key) read a record from temp_b )
   end loop

(its more complex then that, the above logic assumed the join key was unique — we really
need to join every match in temp_a to every match in temp_b but you get the picture)

The hash join is conceptually like:

   create a hash table on one of A or B (say A) on the join key creating temp_a.

   while NOT eof on B
     read a record in b
     hash the join key and look up into temp_a by that hash key for matching 
     records
     output the matches
   end loop

So, a hash join can sometimes be much more efficient (one hash, not two sorts)

Hash joins are used any time a sort merge might be used in most cases. If you don t see
hash joins going on, perhaps you have hash_join_enabled turned off…

3  hash join

哈希連接:將行源 1 計算成一張基于連接鍵的 hash 表,行源 2 的每條記錄依次掃描這張 hash 表,找到匹配的記錄放到結果集。計算 hash 表需要內存空間,hash join 同樣對于內存有比較大的消耗,如果內存空間 (8i 為 hash_area_size,9i 及以上使用 PGA) 不足,則會使用臨時表空間,這樣會降低哈希連接的效率。

關于“數據庫中表連接方式有哪些”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-07-19發表,共計1843字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 金堂县| 互助| 浪卡子县| 新邵县| 韶山市| 东辽县| 镇平县| 郁南县| 安平县| 拜泉县| 都匀市| 稻城县| 菏泽市| 青浦区| 苍南县| 枝江市| 南雄市| 若尔盖县| 达日县| 治县。| 德钦县| 惠东县| 施秉县| 望江县| 滦南县| 珠海市| 吴忠市| 凉城县| 肃宁县| 油尖旺区| 铅山县| 抚远县| 白沙| 东光县| 夹江县| 黑水县| 阿尔山市| 临漳县| 四子王旗| 景德镇市| 读书|