时间:2021-07-01 10:21:17 帮助过:24人阅读

当hash table能全部放到内存中,此种情况最好。如果内存中放不下hash table,优化器将hash table分区,超出内存范围的分区将被写到临时表空间中。
我们分两种情况讨论hash join的实现
hash table 全部在内存里
hash table是Oracle根据join key利用一个hash函数将小表分割成多个bucket。hash table建立完成后,Oracle去扫描大表,并且采用相同的hash算法,将读入的数据也分割成多个bucket。bucket与bucket之间进行join运算,返回结果。直到大表读完为止。
2. hash table 不能全部放到内存中
使用算法,将小表先分区(partition),使得一个partition能加载到内存中。将大表也做相同的分 区。表的分区与分区之间按照1的实现方式取出数据。做完一个分区后,再将另一个分区加载进内存,继续相同的操作,直到数据全部处理完。
SQL> insert into big_emp select * from big_emp;
SQL> insert into big_emp select * from big_emp;#重复执行多次
SQL> /
458752 rows created.
SQL> create table dept_new as select * from dept;
Table created.
SQL> set autot traceonly
SQL> select * from big_emp a,dept_new b where a.deptno=b.deptno;
917504 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 1925493178
-------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 917K| 54M| 1490 (2)| 00:00:18 |
|* 1 | HASH JOIN | | 917K| 54M| 1490 (2)| 00:00:18 |
| 2 | TABLE ACCESS FULL| DEPT_NEW | 4 | 120 | 3 (0)| 00:00:01 |
| 3 | TABLE ACCESS FULL| BIG_EMP | 917K| 28M| 1482 (1)| 00:00:18 |
-------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("A"."DEPTNO"="B"."DEPTNO")
Note
-----
- dynamic sampling used for this statement (level=2)
Statistics
----------------------------------------------------------
4 recursive calls
1 db block gets
66338 consistent gets
0 physical reads
0 redo size
62512398 bytes sent via SQL*Net to client
673349 bytes received via SQL*Net from client
61168 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
917504 rows processedSort Merge Joins
本文出自 “叮咚” 博客,请务必保留此出处http://lqding.blog.51cto.com/9123978/1686257
Oracle 学习之性能优化(七)join的实现方式
标签:hash join nestloop join sortmerge join