sort merge join,hash join,netsloop join
Join Operations
? SORT-MERGE JOIN
– Sorts tables on the join key and then merges them together
– Sorts are expensive ? NESTED LOOPS
– Retrieves a row from one table and finds the corresponding rows in the other table
– Usually best for small numbers of rows ? HASH JOIN
– Build hash table in memory for smaller row source
– Hash larger row source
– Probe in-memory hash table for matches
– Hash joins are only considered by the CBO SORT-MERGE JOIN
根据关联列排序2个表,然后再进行merge操作
当然排序是很昂贵的
无驱动表概念 支持不等值连接 嵌套循环:
Oracle从较小结果集(驱动表/外部表)中读取一行,然后和较大结果集(被探查表/内部表)中的所有数据逐条进行比较(嵌套循环可以用于非等值连接),
如果符合规则,就放入结果集中,然后取较小结果集的下一条数据继续进行循环,直到结束。嵌套循环只适合输出少量结果集或者是用于快速输出结果集。 HASH JOIN
HASH JOIN 选择小表做驱动表,小表指的不是表的行数,而是指的是 行数*列宽度
HASH JOIN只能用于等值连接 把小的结果集(驱动表)来创建hash table 然后 HASH 大的结果集 探测内存里的Hash表来匹配: 实验SQL:
SELECT a.cur_code,b.int_sub_code,b.plan_int_sub_code, a.acct_bran_code , sum(a.payable_int_amt) as amt
FROM comr_intdist a,savc_buscode b
WHERE a.acct_flag = '1'
AND a.bus_code = b.bus_code
and a.LAST_MODI_DATE = '2013-12-31'
AND ((a.term = b.term
AND rtrim(a.sub_code) =rtrim(b.sub_code))
or
a.bus_code=77 )
GROUP BY a.cur_code,b.int_sub_code, b.plan_int_sub_code,a.acct_bran_code
; SORT-MERGE JOIN: Execution Plan
----------------------------------------------------------
Plan hash value: 3181909998 ----------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 8117 | 539K| | 20129 (2)| 00:04:02 |
| 1 | HASH GROUP BY | | 8117 | 539K| | 20129 (2)| 00:04:02 |
| 2 | MERGE JOIN | | 8117 | 539K| | 20127 (2)| 00:04:02 |
| 3 | SORT JOIN | | 409 | 10634 | | 6 (17)| 00:00:01 |
| 4 | TABLE ACCESS FULL | SAVC_BUSCODE | 409 | 10634 | | 5 (0)| 00:00:01 |
|* 5 | FILTER | | | | | | |
|* 6 | SORT JOIN | | 1136K| 45M| 139M| 20077 (2)| 00:04:01 |
|* 7 | TABLE ACCESS FULL| COMR_INTDIST | 1136K| 45M| | 7704 (2)| 00:01:33 |
---------------------------------------------------------------------------------------------- Predicate Information (identified by operation id):
--------------------------------------------------- 5 - filter("A"."TERM"="B"."TERM" AND RTRIM("A"."SUB_CODE")=RTRIM("B"."SUB_CODE")
OR "A"."BUS_CODE"=77)
6 - access("A"."BUS_CODE"="B"."BUS_CODE")
filter("A"."BUS_CODE"="B"."BUS_CODE")
7 - filter("A"."ACCT_FLAG"='1' AND "A"."LAST_MODI_DATE"=TO_DATE(' 2013-12-31
00:00:00', 'syyyy-mm-dd hh24:mi:ss')) Statistics
----------------------------------------------------------
1 recursive calls
2 db block gets
27016 consistent gets
27000 physical reads
0 redo size
30923 bytes sent via SQL*Net to client
1147 bytes received via SQL*Net from client
59 SQL*Net roundtrips to/from client
2 sorts (memory)
0 sorts (disk)
860 rows processed 查看表的访问次数;
Plan hash value: 3181909998 ------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads | OMem | 1Mem | Used-Mem |
------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 860 |00:00:07.55 | 27018 | 26880 | | | |
| 1 | HASH GROUP BY | | 1 | 8117 | 860 |00:00:07.55 | 27018 | 26880 | 835K| 835K| 1454K (0)|
| 2 | MERGE JOIN | | 1 | 8117 | 1131K|00:00:07.01 | 27018 | 26880 | | | |
| 3 | SORT JOIN | | 1 | 409 | 409 |00:00:00.01 | 21 | 0 | 55296 | 55296 |49152 (0)|
| 4 | TABLE ACCESS FULL | SAVC_BUSCODE | 1 | 409 | 409 |00:00:00.01 | 21 | 0 | | | |
|* 5 | FILTER | | 409 | | 1131K|00:00:06.65 | 26997 | 26880 | | | |
|* 6 | SORT JOIN | | 409 | 1136K| 5241K|00:00:04.55 | 26997 | 26880 | 66M| 2830K| 59M (0)|
|* 7 | TABLE ACCESS FULL| COMR_INTDIST | 1 | 1136K| 1138K|00:00:01.04 | 26997 | 26880 | | | |
------------------------------------------------------------------------------------------------------------------------------------ Predicate Information (identified by operation id):
--------------------------------------------------- 5 - filter((("A"."TERM"="B"."TERM" AND RTRIM("A"."SUB_CODE")=RTRIM("B"."SUB_CODE")) OR "A"."BUS_CODE"=77))
6 - access("A"."BUS_CODE"="B"."BUS_CODE")
filter("A"."BUS_CODE"="B"."BUS_CODE")
7 - filter(("A"."ACCT_FLAG"='1' AND "A"."LAST_MODI_DATE"=TO_DATE(' 2013-12-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))) 34 rows selected. 嵌套循环: Execution Plan
----------------------------------------------------------
Plan hash value: 2053094138 ---------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 8117 | 539K| 2283K (1)| 07:36:37 |
| 1 | HASH GROUP BY | | 8117 | 539K| 2283K (1)| 07:36:37 |
| 2 | NESTED LOOPS | | | | | |
| 3 | NESTED LOOPS | | 8117 | 539K| 2283K (1)| 07:36:37 |
|* 4 | TABLE ACCESS FULL | COMR_INTDIST | 1136K| 45M| 7704 (2)| 00:01:33 |
|* 5 | INDEX RANGE SCAN | SAVC_BUSCODE_IDX1 | 5 | | 1 (0)| 00:00:01 |
|* 6 | TABLE ACCESS BY INDEX ROWID| SAVC_BUSCODE | 1 | 26 | 2 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id):
--------------------------------------------------- 4 - filter("A"."ACCT_FLAG"='1' AND "A"."LAST_MODI_DATE"=TO_DATE(' 2013-12-31 00:00:00',
'syyyy-mm-dd hh24:mi:ss'))
5 - access("A"."BUS_CODE"="B"."BUS_CODE")
6 - filter("A"."TERM"="B"."TERM" AND RTRIM("A"."SUB_CODE")=RTRIM("B"."SUB_CODE") OR
"A"."BUS_CODE"=77) Plan hash value: 2053094138 -------------------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads | OMem | 1Mem | Used-Mem |
-------------------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 860 |00:00:16.87 | 290K| 26880 | | | |
| 1 | HASH GROUP BY | | 1 | 8117 | 860 |00:00:16.87 | 290K| 26880 | 835K| 835K| 1456K (0)|
| 2 | NESTED LOOPS | | 1 | | 1131K|00:00:15.90 | 290K| 26880 | | | |
| 3 | NESTED LOOPS | | 1 | 8117 | 5241K|00:00:06.74 | 27132 | 26880 | | | |
|* 4 | TABLE ACCESS FULL | COMR_INTDIST | 1 | 1136K| 1138K|00:00:00.88 | 26997 | 26880 | | | |
|* 5 | INDEX RANGE SCAN | SAVC_BUSCODE_IDX1 | 1138K| 5 | 5241K|00:00:03.59 | 135 | 0 | | | |
|* 6 | TABLE ACCESS BY INDEX ROWID| SAVC_BUSCODE | 5241K| 1 | 1131K|00:00:06.08 | 262K| 0 | | | |
------------------------------------------------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id):
--------------------------------------------------- 4 - filter(("A"."ACCT_FLAG"='1' AND "A"."LAST_MODI_DATE"=TO_DATE(' 2013-12-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss')))
5 - access("A"."BUS_CODE"="B"."BUS_CODE")
6 - filter((("A"."TERM"="B"."TERM" AND RTRIM("A"."SUB_CODE")=RTRIM("B"."SUB_CODE")) OR "A"."BUS_CODE"=77)) 32 rows selected. HASH JOIN:
Execution Plan
----------------------------------------------------------
Plan hash value: 4188551662 ------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 8117 | 539K| 7768 (3)| 00:01:34 |
| 1 | HASH GROUP BY | | 8117 | 539K| 7768 (3)| 00:01:34 |
|* 2 | HASH JOIN | | 8117 | 539K| 7767 (3)| 00:01:34 |
| 3 | TABLE ACCESS FULL| SAVC_BUSCODE | 409 | 10634 | 5 (0)| 00:00:01 |
|* 4 | TABLE ACCESS FULL| COMR_INTDIST | 1136K| 45M| 7704 (2)| 00:01:33 |
------------------------------------------------------------------------------------ Predicate Information (identified by operation id):
--------------------------------------------------- 2 - access("A"."BUS_CODE"="B"."BUS_CODE")
filter("A"."TERM"="B"."TERM" AND
RTRIM("A"."SUB_CODE")=RTRIM("B"."SUB_CODE") OR "A"."BUS_CODE"=77)
4 - filter("A"."ACCT_FLAG"='1' AND "A"."LAST_MODI_DATE"=TO_DATE('
2013-12-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) Statistics
----------------------------------------------------------
1 recursive calls
2 db block gets
27016 consistent gets
26880 physical reads
0 redo size
37887 bytes sent via SQL*Net to client
1147 bytes received via SQL*Net from client
59 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
860 rows processed Plan hash value: 4188551662 ----------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads | OMem | 1Mem | Used-Mem |
----------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 860 |00:00:05.11 | 27018 | 26880 | | | |
| 1 | HASH GROUP BY | | 1 | 8117 | 860 |00:00:05.11 | 27018 | 26880 | 835K| 835K| 1456K (0)|
|* 2 | HASH JOIN | | 1 | 8117 | 1131K|00:00:04.26 | 27018 | 26880 | 947K| 947K| 1257K (0)|
| 3 | TABLE ACCESS FULL| SAVC_BUSCODE | 1 | 409 | 409 |00:00:00.01 | 21 | 0 | | | |
|* 4 | TABLE ACCESS FULL| COMR_INTDIST | 1 | 1136K| 1138K|00:00:00.69 | 26997 | 26880 | | | |
---------------------------------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id):
--------------------------------------------------- 2 - access("A"."BUS_CODE"="B"."BUS_CODE")
filter((("A"."TERM"="B"."TERM" AND RTRIM("A"."SUB_CODE")=RTRIM("B"."SUB_CODE")) OR "A"."BUS_CODE"=77))
4 - filter(("A"."ACCT_FLAG"='1' AND "A"."LAST_MODI_DATE"=TO_DATE(' 2013-12-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))) 30 rows selected.
sort merge join,hash join,netsloop join的更多相关文章
- Sort merge join、Nested loops、Hash join(三种连接类型)
目前为止,典型的连接类型有3种: Sort merge join(SMJ排序-合并连接):首先生产driving table需要的数据,然后对这些数据按照连接操作关联列进行排序:然后生产probed ...
- Nested Loop,Sort Merge Join,Hash Join
三种连接工作方式比较: Nested loops 工作方式是从一张表中读取数据,访问另一张表(通常是索引)来做匹配,nested loops适用的场合是当一个关联表比较小的时候,效率会更高. Merg ...
- Nested Loops,Hash Join 和 Sort Merge Join. 三种不同连接的不同:
原文:https://blog.csdn.net/tianlesoftware/article/details/5826546 Nested Loops,Hash Join 和 Sort Merge ...
- Nested loops、Hash join、Sort merge join(三种连接类型原理、使用要点)
nested loop 嵌套循环(原理):oracle从较小结果集(驱动表.也可以被称为outer)中读取一行,然后和较大结果集(被侦查表,也可以叫做inner)中的所有数据逐条进行比较(也是等值连接 ...
- NESTED LOOPS & HASH JOIN & SORT MERGE JOIN
表连接方式及使用场合 NESTED LOOP 对于被连接的数据子集较小的情况,nested loop连接是个较好的选择.nested loop就是扫描一个表,每读到一条记录,就根据索引去另一个表里面查 ...
- Oracle 三种连接方式 NESTED LOOP HASH JOIN SORT MERGE JOIN
NESTED LOOP: 对于被连接的数据子集较小的情况,嵌套循环连接是个较好的选择.在嵌套循环中,内表被外表驱动,外表返回的每一行都要在内表中检索找到与它匹配的行,因此整个查询返回的结果集不能太大( ...
- Oracle 表的连接方式(1)-----Nested loop join和 Sort merge join
关系数据库技术的精髓就是通过关系表进行规范化的数据存储,并通过各种表连接技术和各种类型的索引技术来进行信息的检索和处理. 表的三种关联方式: nested loop:从A表抽一条记录,遍历B表查找匹配 ...
- sort merge join导致temp被爆菊
SQL_ID cqsz37256v36j, child number 1 ------------------------------------- INSERT /*+append*/ INTO T ...
- Merge join、Hash join、Nested loop join对比分析
简介 我们所常见的表与表之间的Inner Join,Outer Join都会被执行引擎根据所选的列,数据上是否有索引,所选数据的选择性转化为Loop Join,Merge Join,Hash Join ...
随机推荐
- Android(java)学习笔记192:SQLite数据库(表)的创建 以及 SQLite数据库的升级
一.数据库的创建 1.文件的创建 //引用,如果文件不存在是不会创建的 File file = new File("haha.txt"): //输出流写数据 ...
- ajax大数据排队导出+进度条
描述 :我们现在有很多数据,分表存放,现在需要有精度条的导出.最后面有完整源码. 效果图:
- 实现RecycleView动态使列表item可以点击或不可点击切换
效果 这里讲的是第二个button跳转的Activity,这里和上一篇不同之处在于可以item点击.item子控件点击 继承BaseAdapter 同样也要继承BaseAdapter public c ...
- SharePoint Attachement操作代码
下载文件 如果下载其它类别的文件: SPSecurity.RunWithElevatedPrivileges(].ToString(); swi ...
- LA 4329(树状数组)
题目描述: N <tex2html_verbatim_mark>(3N20000) <tex2html_verbatim_mark>ping pong players live ...
- 苹果手机 iframe 无法滚动bug
原来在html5下,iframe 只有 src 属性scroling='no' 解决办法:在iframe外加一层第div,设置样式-webkit-overflow-scrolling:touch;ov ...
- 深入探讨C#中Socket一次性搞定消息发送
转载自:http://tech.chinaunix.net/a2010/0909/1101/000001101396.shtml [IT168 技术文档]最近浏览了几篇有关Socket发送消息 ...
- UITabBar的隐藏
方式一: // 重写导航控制器的push方法 - (void)pushViewController:(UIViewController *)viewController animated:(BOOL) ...
- mysql主要应用场景 转载
前言 据说目前MySQL用户已经达千万级别了,其中不乏企业级用户.可以说是目前最为流行的开源数据库管理系统软件了.任何产品都不可能是万能的,也不可能适用于所有的应用场景.那么MySQL到底在什么场景下 ...
- jquery文本折叠
/** * Created by dongdong on 2015/4/28. */(function($){ var defaults = { height:40, //文本收起后的高度 speed ...