⑴ 执行原理 例如: select t1.*,t2.* from t1,t2 where t1.col1=t2.col2; 访问机制如下: for i in (select * from t1) loop for j in (select * from t2 where col2=i.col1) loop display results; end loop; end loop; 类似一个嵌套循环 嵌套循环执行时,先是外层循环进入内层循环,并在内层循环终止之后 接着执行外层循环再由外层循环进入内层循环中,当外层循环全部终止时,程序结束
⑴ 执行原理 例如: select t1.*,t2.* from t1,t2 where t1.id=t2.id; 访问机制如下: 访问t1,并order by t1_1.id,这里的id代表连接字段 访问t2,并order by t2_1.id join t1_1.id = t2_1.id,依次交替 比对 归并,但无所谓驱动
⑵ 使用场景 虽说,hash join就是用来替代sj的,但如果你的服务器的CPU资源和MEM资源都很紧张的时候,建议用SORT MERGE JOIN 因为hash join比sort merge join需要的资源更多。特别是cpu 10g sql tuning 文档上写道: On the other hand, sort-merge joins can perform better than hash joins if both of the following conditions are met: The row sources are already sorted. A sort operation does not have to be done. 所以,sj大概就用在没有索引,并且数据已经排序的情况