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)
oracle 11gr2 在vmware虚拟机中安装步骤
debian 下 安装 oracle 11g xe r2
oracle导入导出expdp impdp详解
oracle 10g expdp导出报错ora-4031的解决方法
本文永久更新链接地址:
,