[20180713]关于hash join 测试中一个疑问.txt
[20180713]关于hash join 测试中一个疑问.txt
--//上个星期做的测试,链接: http://blog.itpub.net/267265/viewspace-2157424/
--//前几天在家里12c上重复测试,才发现自己没注意细节问题.
1.环境:
SCOTT@test01p> @ ver1
PORT_STRING VERSION BANNER CON_ID
------------------------------ -------------- -------------------------------------------------------------------------------- ----------
IBMPC/WIN_NT64-9.1.0 12.1.0.1.0 Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production 0
create table t1 as select level id ,'t1'||to_char(level) name from dual connect by level<=4;
create table t2 as select level+1 id ,'t2'||to_char(level) name from dual connect by level<=4;
insert into t1 values (null,'t1null');
insert into t2 values (null,'t2null');
commit ;
--//分析略.
insert into t2 select rownum+4 ,'t2'||to_char(rownum+4) from dual connect by level<=10000;
commit;
SCOTT@test01p> select rowid,t2.* from t2 where id<=4 or id is null;
ROWID ID NAME
------------------ ---------- --------------------
AAAaT5AAJAAAADLAAA 2 t21
AAAaT5AAJAAAADLAAB 3 t22
AAAaT5AAJAAAADLAAC 4 t23
AAAaT5AAJAAAADOAAA t2null
--//我自己一直以为执行insert into t2 values (null,'t2null');应该插入的数据块与id=2的数据块一样,实际情况不同.
SCOTT@test01p> @ rowid AAAaT5AAJAAAADLAAA
OBJECT FILE BLOCK ROW ROWID_DBA DBA TEXT
---------- ---------- ---------- ---------- -------------------- -------------------- ----------------------------------------
107769 9 203 0 0x24000CB 9,203 alter system dump datafile 9 block 203 ;
SCOTT@test01p> @ rowid AAAaT5AAJAAAADOAAA
OBJECT FILE BLOCK ROW ROWID_DBA DBA TEXT
---------- ---------- ---------- ---------- -------------------- -------------------- ----------------------------------------
107769 9 206 0 0x24000CE 9,206 alter system dump datafile 9 block 206 ;
--//实际上ctas插入的第一块紧接着表段HEADER_BLOCK.
SCOTT@test01p> select SEGMENT_NAME,SEGMENT_TYPE,HEADER_FILE,HEADER_BLOCK from dba_segments where owner=user and segment_name='T2';
SEGMENT_NAME SEGMENT_TYPE HEADER_FILE HEADER_BLOCK
-------------------- -------------------- ----------- ------------
T2 TABLE 9 202
2.这样就很好解析我前面遇到的情况:
SCOTT@test01p> alter session set statistics_level=all;
Session altered.
SCOTT@test01p> select * from t1 where id not in (select id from t2 ) and id is not null;
no rows selected
SCOTT@test01p> @ dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 86bz316n141w9, child number 0
-------------------------------------
select * from t1 where id not in (select id from t2 ) and id is not null
Plan hash value: 1275484728
------------------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers | OMem | 1Mem | Used-Mem |
------------------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | | 14 (100)| | 0 |00:00:00.01 | 14 | | | |
|* 1 | HASH JOIN ANTI NA | | 1 | 1 | 12 | 14 (0)| 00:00:01 | 0 |00:00:00.01 | 14 | 1888K| 1888K| 1090K (0)|
|* 2 | TABLE ACCESS FULL| T1 | 1 | 4 | 32 | 4 (0)| 00:00:01 | 4 |00:00:00.01 | 7 | | | |
| 3 | TABLE ACCESS FULL| T2 | 1 | 10005 | 40020 | 10 (0)| 00:00:01 | 956 |00:00:00.01 | 7 | | | |
------------------------------------------------------------------------------------------------------------------------------------------------
--//表T2做全表扫描buffers=7.而实际全表扫描逻辑读31.而且实际读T2记录数是956.
SCOTT@test01p> select count(*) from t2 ;
COUNT(*)
----------
10005
SCOTT@test01p> @ dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 34jwra7jk76u5, child number 0
-------------------------------------
select count(*) from t2
Plan hash value: 3321871023
-------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers |
-------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 10 (100)| | 1 |00:00:00.01 | 31 |
| 1 | SORT AGGREGATE | | 1 | 1 | | | 1 |00:00:00.01 | 31 |
| 2 | TABLE ACCESS FULL| T2 | 1 | 10005 | 10 (0)| 00:00:01 | 10005 |00:00:00.01 | 31 |
-------------------------------------------------------------------------------------------------------------
SCOTT@test01p> select count(*) from t2 where DBMS_ROWID.ROWID_BLOCK_NUMBER(rowid) between 203 and 205;
COUNT(*)
----------
955
--//这样扫描dba=9,203到9,205的记录数是955,加上dba=9.206第1条记录是id is NULL,因为存在Null 记录,查询就停止扫描T2.
--//而如果交换表连接顺序:
SCOTT@test01p> select /*+ SWAP_JOIN_INPUTS(@"SEL$5DA710D3" "T2"@"SEL$2") */ * from t1 where id not in (select id from t2 ) ;
no rows selected
SCOTT@test01p> @ dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID aqy7dusnfb5gm, child number 0
-------------------------------------
select /*+ SWAP_JOIN_INPUTS(@"SEL$5DA710D3" "T2"@"SEL$2") */ * from t1
where id not in (select id from t2 )
Plan hash value: 2739594415
-----------------------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers | OMem | 1Mem | Used-Mem |
-----------------------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | | 14 (100)| | 0 |00:00:00.01 | 7 | | | |
|* 1 | HASH JOIN RIGHT ANTI NA| | 1 | 2 | 24 | 14 (0)| 00:00:01 | 0 |00:00:00.01 | 7 | 1753K| 1753K| 1482K (0)|
| 2 | TABLE ACCESS FULL | T2 | 1 | 10005 | 40020 | 10 (0)| 00:00:01 | 956 |00:00:00.01 | 7 | | | |
| 3 | TABLE ACCESS FULL | T1 | 0 | 5 | 40 | 4 (0)| 00:00:01 | 0 |00:00:00.01 | 0 | | | |
-----------------------------------------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$5DA710D3
2 - SEL$5DA710D3 / T2@SEL$2
3 - SEL$5DA710D3 / T1@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("ID"="ID")
--//这样T2表扫描到id is null时就停止.而T1表根本不做全表扫描操作.starts=0.
[20180713]关于hash join 测试中一个疑问.txt的更多相关文章
- [20180904]工作中一个错误.txt
[20180904]工作中一个错误.txt --//昨天看我提交一份修改建议,发现自己写的sql语句存在错误.--//链接:http://blog.itpub.net/267265/viewspace ...
- mysql 8.0.18 hash join测试(内外网首文)
CREATE TABLE COLUMNS_hj as select * from information_schema.`COLUMNS`; INSERT INTO COLUMNS_hj SELECT ...
- [20180705]关于hash join 2.txt
[20180705]关于hash join 2.txt --//昨天优化sql语句,执行计划hash join right sna,加入一个约束设置XX字段not null,逻辑读从上万下降到50.- ...
- 8.深入TiDB:解析Hash Join实现原理
本文基于 TiDB release-5.1进行分析,需要用到 Go 1.16以后的版本 我的博客地址:https://www.luozhiyun.com/archives/631 所谓 Hash Jo ...
- 数据库 Hash Join的定义,原理,算法,成本,模式和位图
Hash Join只能用于相等连接,且只能在CBO优化器模式下.相对于nested loop join,hash join更适合处理大型结果集 Hash Join的执行计划第1个是hash ...
- 浅谈SQL Server中的三种物理连接操作(HASH JOIN MERGE JOIN NESTED LOOP)
简介 在SQL Server中,我们所常见的表与表之间的Inner Join,Outer Join都会被执行引擎根据所选的列,数据上是否有索引,所选数据的选择性转化为Loop Join,Merge J ...
- ClsoSee(v2) Alpha测试中!这是一个临时的帮助页面...
Clso See 测试中,最新的更新信息会显示在这里,欢迎您随时关注新版本动态. 您可以单击这里让程序打开本地帮助文件(新说明.txt) 等程序完成后,会制作专门的帮助页面. 因为采用了键盘Hook技 ...
- 浅谈SQL Server中的三种物理连接操作(Nested Loop Join、Merge Join、Hash Join)
简介 在SQL Server中,我们所常见的表与表之间的Inner Join,Outer Join都会被执行引擎根据所选的列,数据上是否有索引,所选数据的选择性转化为Loop Join,Merge J ...
- Bullet:关于ORACLE中的HASH JOIN的参数变化
Oracle在7.3引入了hash join. 但是在Oracle 10g及其以后的Oracle数据库版本中,优化器,实际是CBO,也是因为HASH JOIN仅适用于CBO,在解析目标SQL时是否考虑 ...
随机推荐
- LeetCode--No.006 ZigZag Conversion
6. ZigZag Conversion Total Accepted: 98584 Total Submissions: 398018 Difficulty: Easy The string &qu ...
- 关于Python的import机制原理
很多人用过python,不假思索地在脚本前面加上import module_name,但是关于import的原理和机制,恐怕没有多少人真正的理解.本文整理了Python的import机制,一方面自己总 ...
- selenium的chromedriver对应的chrome版本
chromedriver下载地址:http://chromedriver.storage.googleapis.com/index.html chromedriver版本 支持的Chrome版本 v2 ...
- C#单元测试分享ppt
单元测试(unit testing),是指对软件中的最小可测试单元进行检查和验证.对于单元测试中单元的含义,一般来说,要根据实际情况去判定其具体含义,如C语言中单元指一个函数,Java里单元指一个类, ...
- [转]idea导入eclipse的web项目
https://www.cnblogs.com/xiaoBlog2016/archive/2017/05/08/6825014.html 一.导入自己的web项目 步骤:File->New-&g ...
- 新手易犯的典型缺陷--C#
这段时间花了点时间整理了几个新手易犯的典型缺陷(专门针对C#的),但是个人的力量毕竟有限缺陷的覆盖面比较窄,有些缺陷的描述也不够准确,这里先贴出来看看能不能集思广益,收集整理出更多的典型缺陷.目标就是 ...
- iframe可通过postMessage解决跨域、跨窗口消息传递
https://www.cnblogs.com/dorothyorsusie/p/6178599.html //iframe传参给父级页面 function give_info(){ console. ...
- SpringMvc @ResponseBody字符串中文乱码原因及解决方案
今天突然发现一个问题,后来在网上也找到了很多解决思路,自己也查找到了问题所在,记录一下. @RequestMapping(value = "/demo1") @ResponseBo ...
- 学习实践之DEMO《nodejs模拟POST登陆》
一个简单的PHP接收参数页面 <?php header("content-type:text/html;charset=utf-8"); if($_POST[username ...
- openssl rsautl和openssl pkeyutl(文件的非对称加密)
openssl系列文章:http://www.cnblogs.com/f-ck-need-u/p/7048359.html rsautl是rsa的工具,相当于rsa.dgst的部分功能集合,可用于生成 ...