外键消除表连接
来源:互联网 发布:mysql大小写敏感开关 编辑:程序博客网 时间:2024/06/10 19:24
很简单的一个语句
select * from emp where exists ( select 1 from dept where emp.deptno=dept.deptno);Execution Plan----------------------------------------------------------Plan hash value: 3274513678------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 14 | 574 | 3 (0)| 00:00:01 || 1 | NESTED LOOPS SEMI | | 14 | 574 | 3 (0)| 00:00:01 || 2 | TABLE ACCESS FULL| EMP | 14 | 532 | 3 (0)| 00:00:01 ||* 3 | INDEX UNIQUE SCAN| PK_DEPT | 4 | 12 | 0 (0)| 00:00:01 |------------------------------------------------------------------------------Predicate Information (identified by operation id):--------------------------------------------------- 3 - access("EMP"."DEPTNO"="DEPT"."DEPTNO")
在查询过程中用的nested loop semi表连接
通过对表结构更改添加外键再查看其执行计划
SQL> alter table emp add constraint fk_edeptno_dept foreign key (deptno) references dept(deptno);SQL> select * from emp where exists ( select 1 from dept where emp.deptno=dept.deptno);Execution Plan----------------------------------------------------------Plan hash value: 3956160932--------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |--------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 14 | 532 | 3 (0)| 00:00:01 ||* 1 | TABLE ACCESS FULL| EMP | 14 | 532 | 3 (0)| 00:00:01 |--------------------------------------------------------------------------Predicate Information (identified by operation id):--------------------------------------------------- 1 - filter("EMP"."DEPTNO" IS NOT NULL)
对比
3 - access("EMP"."DEPTNO"="DEPT"."DEPTNO")
1 - filter("EMP"."DEPTNO" IS NOT NULL)
执行计划改变,减少表连接损耗!- 外键消除表连接
- 外连接消除、嵌套连接消除与连接消除
- SQL优化--逻辑优化--外连接、嵌套连接与连接消除
- visio消除直线连接圆弧
- 数据库消除连接泄露问题
- MySQL查询优化器--逻辑查询优化技术(五)--外连接的消除(一)
- MySQL查询优化器--逻辑查询优化技术(五)--外连接的消除(二)
- 水晶报表登录,消除连接框
- 如何消除网页退回键
- 消除链表中的循环
- 消除弱表中的循环
- 子查询 结合 内连接 来消除重复纪录
- 批量消除网页连接上的“虚线框”
- .net连接ORACLE数据库,为什么数据库进程无法消除?
- DreamWeaver批量消除网页连接上的“虚线框”
- DreamWeaver批量消除网页连接上的“虚线框”
- 消除SecureCRT连接Ubuntu时,报refused的错误
- T-SQL 表连接(内连接,外连接,交叉连接)
- C#基于SOCKET通信开发的Telnet模拟工具
- @CookieValue注解 拿到cookie
- how to fix ssh timeout problems
- 虚数的意义
- poj 1787 DP
- 外键消除表连接
- myeclipse6.6+maven跑springside4.1的demo
- linux设备驱动开发详解--第八章 Linux 设备驱动中的阻塞与非阻塞 I/O
- eclipse 配置maven web项目
- windows svn(TortoiseSVN)命令操作
- coreseek增加自定义中文分词
- Important !! Clustering Factor Calculation Improvement
- Ext做的第一个小东西登陆框(引入的css文件与本来页面的css文件冲突了,搞了半天才搞定)
- Apache HttpClient4.2.5 模拟post、登录并访问验证授权数据