Oracle not exists的等价写法

php中文网
发布: 2016-06-07 16:46:02
原创
1720人浏览过

not exists可以改为left join + is null,可以看到改写前后执行计划一样,消耗资源一样,说明完全等价。

not exists可以改为left join + is null,可以看到改写前后执行计划一样,消耗资源一样,说明完全等价。

SQL> drop table test purge;

SQL> drop table test1 purge;
SQL> create table test as select * from dba_objects;
SQL> create table test1 as select * from dba_objects;
SQL> delete from test1 where rownum SQL> commit;

SQL> select count(1) from test t where not exists(
    select 1 from test1 t1 where t1.object_id=t.object_id
    );
  COUNT(1)
----------
        11
SQL> select count(1) from test t,test1 t1 where t.object_id=t1.object_id(+)
    and t1.object_id is null;
  COUNT(1)
----------
        11
SQL> select * from test t where not exists(
    select 1 from test1 t1 where t1.object_id=t.object_id
    )
    minus
    select t.* from test t,test1 t1 where t.object_id=t1.object_id(+)
    and t1.object_id is null;
未选定行

SQL> select t.* from test t,test1 t1 where t.object_id=t1.object_id(+)
    and t1.object_id is null
    minus
    select * from test t where not exists(
    select 1 from test1 t1 where t1.object_id=t.object_id
    );
未选定行

SQL> set autotrace traceonly
SQL> select t.* from test t where not exists(
    select 1 from test1 t1 where t1.object_id=t.object_id
    );
已选择11行。
执行计划
----------------------------------------------------------
Plan hash value: 2726816538
--------------------------------------------------------------------------------------
| Id  | Operation            | Name  | Rows  | Bytes |TempSpc| Cost (%CPU)| Time    |
--------------------------------------------------------------------------------------
|  0 | SELECT STATEMENT    |      | 72877 |    15M|      |  1109  (1)| 00:00:16 |
|*  1 |  HASH JOIN RIGHT ANTI|      | 72877 |    15M|  1520K|  1109  (1)| 00:00:16 |
|  2 |  TABLE ACCESS FULL  | TEST1 | 61874 |  785K|      |  196  (1)| 00:00:03 |
|  3 |  TABLE ACCESS FULL  | TEST  | 72877 |    14M|      |  197  (2)| 00:00:03 |
--------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
  1 - access("T1"."OBJECT_ID"="T"."OBJECT_ID")
Note
-----
  - dynamic sampling used for this statement (level=2)
统计信息
----------------------------------------------------------
          7  recursive calls
          0  db block gets
      1142  consistent gets
          0  physical reads
          0  redo size
      1577  bytes sent via SQL*Net to client
        337  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
        11  rows processed
SQL> select t.* from test t,test1 t1 where t.object_id=t1.object_id(+)
  2  and t1.object_id is null;
已选择11行。
执行计划
----------------------------------------------------------
Plan hash value: 2726816538
--------------------------------------------------------------------------------------
| Id  | Operation            | Name  | Rows  | Bytes |TempSpc| Cost (%CPU)| Time    |
--------------------------------------------------------------------------------------
|  0 | SELECT STATEMENT    |      | 72877 |    15M|      |  1109  (1)| 00:00:16 |
|*  1 |  HASH JOIN RIGHT ANTI|      | 72877 |    15M|  1520K|  1109  (1)| 00:00:16 |
|  2 |  TABLE ACCESS FULL  | TEST1 | 61874 |  785K|      |  196  (1)| 00:00:03 |
|  3 |  TABLE ACCESS FULL  | TEST  | 72877 |    14M|      |  197  (2)| 00:00:03 |
--------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
  1 - access("T"."OBJECT_ID"="T1"."OBJECT_ID")
Note
-----
  - dynamic sampling used for this statement (level=2)
统计信息
----------------------------------------------------------
          7  recursive calls
          0  db block gets
      1142  consistent gets
          0  physical reads
          0  redo size
      1577  bytes sent via SQL*Net to client
        337  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
        11  rows processed

Oracle 单实例 从32位 迁移到 64位 方法 

在CentOS 6.4下安装Oracle 11gR2(x64)

crmeb电商系统
crmeb电商系统

CRMEB 是基于Thinkphp5基础开发的以会员为中心的电商系统,开源版微信公众号商城和小程序商城数据同步,带积分、优惠券、秒杀、砍价、分销等功能,更是一套方便二次开发的商城框架(后台封装了独有快速创建表单功能,无需写表单页面、快速创建数据搜索和数据列表页、导出表格、系统权限配置控制每一个控制器方法、系统参数配置、数据字典、组合数据等)

crmeb电商系统 0
查看详情 crmeb电商系统

Oracle 11gR2 在VMWare虚拟机中安装步骤

Debian 下 安装 Oracle 11g XE R2

Oracle导入导出expdp IMPDP详解

Oracle 10g expdp导出报错ORA-4031的解决方法

本文永久更新链接地址:

linux

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号