[Oracle] minus 和 not exists比較
SQL> select count(*) from test;
COUNT(*)
----------
28835328
Elapsed: 00:00:09.48
SQL> select count(*) from test1;
COUNT(*)
----------
28833280
Elapsed: 00:00:09.20
SQL> select id from test minus select id from test1;
2048 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 145651196
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 28M| 329M| | 424K (52)| 01:24:50 |
| 1 | MINUS | | | | | | |
| 2 | SORT UNIQUE | | 28M| 164M| 331M| 208K (2)| 00:41:40 |
| 3 | TABLE ACCESS FULL| TEST | 28M| 164M| | 113K (1)| 00:22:46 |
| 4 | SORT UNIQUE | | 28M| 164M| 331M| 215K (2)| 00:43:10 |
| 5 | TABLE ACCESS FULL| TEST1 | 28M| 164M| | 121K (1)| 00:24:17 |
-------------------------------------------------------------------------------------
Statistics
----------------------------------------------------------
666 recursive calls
5 db block gets
858690 consistent gets
942852 physical reads
0 redo size
40164 bytes sent via SQL*Net to client
2020 bytes received via SQL*Net from client
138 SQL*Net roundtrips to/from client
0 sorts (memory)
2 sorts (disk)
2048 rows processed
SQL> select id from test where not exists (select id from test1 where test.id=test1.id)
2 ;
2048 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 505731057
------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 288K| 3379K| | 181K (1)| 00:36:19 |
|* 1 | HASH JOIN RIGHT ANTI | | 288K| 3379K| 494M| 181K (1)| 00:36:19 |
| 2 | INDEX FAST FULL SCAN| TEST1_PK | 28M| 164M| | 18055 (2)| 00:03:37 |
| 3 | TABLE ACCESS FULL | TEST | 28M| 164M| | 113K (1)| 00:22:46 |
------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("TEST"."ID"="TEST1"."ID")
Statistics
----------------------------------------------------------
724 recursive calls
1 db block gets
483516 consistent gets
503636 physical reads
0 redo size
40164 bytes sent via SQL*Net to client
2020 bytes received via SQL*Net from client
138 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
2048 rows processed
SQL> create table tt6 as select id from test minus select id from test1;
Table created.
Elapsed: 00:01:09.79
SQL> create table tt7 as select id from test where not exists (select id from test1 where test.id=test1.id);
Table created.
Elapsed: 00:01:02.35
看執行計劃少了很多,實際執行的時候,時間減少不大。
COUNT(*)
----------
28835328
Elapsed: 00:00:09.48
SQL> select count(*) from test1;
COUNT(*)
----------
28833280
Elapsed: 00:00:09.20
SQL> select id from test minus select id from test1;
2048 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 145651196
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 28M| 329M| | 424K (52)| 01:24:50 |
| 1 | MINUS | | | | | | |
| 2 | SORT UNIQUE | | 28M| 164M| 331M| 208K (2)| 00:41:40 |
| 3 | TABLE ACCESS FULL| TEST | 28M| 164M| | 113K (1)| 00:22:46 |
| 4 | SORT UNIQUE | | 28M| 164M| 331M| 215K (2)| 00:43:10 |
| 5 | TABLE ACCESS FULL| TEST1 | 28M| 164M| | 121K (1)| 00:24:17 |
-------------------------------------------------------------------------------------
Statistics
----------------------------------------------------------
666 recursive calls
5 db block gets
858690 consistent gets
942852 physical reads
0 redo size
40164 bytes sent via SQL*Net to client
2020 bytes received via SQL*Net from client
138 SQL*Net roundtrips to/from client
0 sorts (memory)
2 sorts (disk)
2048 rows processed
SQL> select id from test where not exists (select id from test1 where test.id=test1.id)
2 ;
2048 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 505731057
------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 288K| 3379K| | 181K (1)| 00:36:19 |
|* 1 | HASH JOIN RIGHT ANTI | | 288K| 3379K| 494M| 181K (1)| 00:36:19 |
| 2 | INDEX FAST FULL SCAN| TEST1_PK | 28M| 164M| | 18055 (2)| 00:03:37 |
| 3 | TABLE ACCESS FULL | TEST | 28M| 164M| | 113K (1)| 00:22:46 |
------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("TEST"."ID"="TEST1"."ID")
Statistics
----------------------------------------------------------
724 recursive calls
1 db block gets
483516 consistent gets
503636 physical reads
0 redo size
40164 bytes sent via SQL*Net to client
2020 bytes received via SQL*Net from client
138 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
2048 rows processed
SQL> create table tt6 as select id from test minus select id from test1;
Table created.
Elapsed: 00:01:09.79
SQL> create table tt7 as select id from test where not exists (select id from test1 where test.id=test1.id);
Table created.
Elapsed: 00:01:02.35
看執行計劃少了很多,實際執行的時候,時間減少不大。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24237320/viewspace-2134080/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- ORACLE 中IN和EXISTS比較Oracle
- 透過sql trace比較常規 not in 、minus、not exists效率SQL
- 通過sql trace比較常規 not in 、minus、not exists效率SQL
- (轉)ORACLE 中IN和EXISTS比較Oracle
- not in 和 not exists 比較和用法
- [Oracle] exists 和 not existsOracle
- Oracle date 型別比較和String比較Oracle型別
- oracle中關於in和exists,not in 和 not existsOracle
- ORACLE和MSSQL中行鎖比較OracleSQL
- oracle中的exists和not exists和in用法詳解Oracle
- sqlldr和oracle_datapump效能比較SQLOracle
- oracle中的exists 和not exists 用法詳解Oracle
- js 深比較和淺比較JS
- MYSQL和ORACLE時區設定比較MySqlOracle
- 利用ORACLE的MINUS函式和OVER函式,直接通過檢視實現兩個記錄集的比較。(轉載)Oracle函式
- oracle中字串的大小比較,字串與數字的比較和運算Oracle字串
- oracle 比較日期相等Oracle
- oracle sql日期比較:OracleSQL
- 查詢oracle比較慢的session和sqlOracleSessionSQL
- ERP軟體比較:SAP和Oracle ---itpubOracle
- Oracle dbms_stats包和analyze 的比較Oracle
- oracle中in和exists的區別Oracle
- Oracle的expdp/impdp工具和exp/imp工具比較Oracle
- ORACLE11.2.0.3和MYSQL5.6 DDL比較OracleMySql
- 查詢oracle比較慢的session和SQL[轉]OracleSessionSQL
- Oracle 中 replace函式和translate函式比較Oracle函式
- TCP和UDP比較TCPUDP
- Java和JavaSciprt比較Java
- Redis 和 Memcached 比較Redis
- MongoDB和Redis比較。MongoDBRedis
- MongoDB和MySQL比較MongoDBMySql
- ETL和EAI比較AI
- 【SQL】Oracle sql語句 minus函式執行效率與join對比SQLOracle函式
- (轉)ORACLE 中IN和EXISTS的區別Oracle
- Oracle中exists和in的效能差異Oracle
- ORACLE的Copy命令和create table,insert into的比較Oracle
- Oracle Decode()函式和CASE語句的比較Oracle函式
- Go和Python比較的話,哪個比較好?GoPython