资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

数据库中表连接方式有哪些-创新互联

这篇文章将为大家详细讲解有关数据库中表连接方式有哪些,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

创新互联公司专注于中大型企业的网站设计、成都网站设计和网站改版、网站营销服务,追求商业策划与数据分析、创意艺术与技术开发的融合,累计客户上千,服务满意度达97%。帮助广大客户顺利对接上互联网浪潮,准确优选出符合自己需要的互联网运用,我们将一直专注品牌网站建设和互联网程序开发,在前进的路上,与客户一起成长!

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)不足,则会使用临时表空间,这样会降低哈希连接的效率。

数据库中表连接方式有哪些

关于“数据库中表连接方式有哪些”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。


文章标题:数据库中表连接方式有哪些-创新互联
网页地址:http://cdkjz.cn/article/ihjoi.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220