1. 程式人生 > >oracle 資料庫中幾種連線方式執行過程(nested loop、hash join、sort order join)

oracle 資料庫中幾種連線方式執行過程(nested loop、hash join、sort order join)

簡單介紹了一下oracle 各種連線方式的執行過程,虛擬碼內容來源於pro oracle sql。 nested loop: select empno, ename, dname, loc
from emp, dept
where emp.deptno = dept.deptno for each row in (select empno, ename, deptno from emp) loop
  for (select dname, loc from dept where deptno =   outer.deptno) loop
    If match then pass the row on to the next step
    If inner join and no match then discard the row
    If outer join and no match set inner column values to null
    and pass the row on to the next step
  end loop
end loop

sort-merge join : select empno, ename, dname, loc
from emp, dept
where emp.deptno = dept.deptno select empno, ename, deptno from emp order by deptno
select dname, loc, deptno from dept order by deptno
compare the rowsets and return rows where deptno in both lists match
for an outer join, compare the rowsets and return all rows from the first list

setting column values for the other table to null

hash-join : select empno, ename, dname, loc
from emp, dept
where emp.deptno = dept.deptno determine the smaller row set, or in the case of an outer join,
use the outer joined table
select dname, loc, deptno from dept
hash the deptno column and build a hash table

select empno, ename, deptno from emp
hash the deptno column and probe the hash table
if match made, check bitmap to confirm row match
if no match made, discard the row

如需轉載,請註明出處:http://blog.csdn.net/renfengjun/article/details/18599161