Oracle的表連線方法(七)
Oracle表連線方法有四種:
● 排序合併連線(Sort Merge Join)
● 巢狀迴圈連線(Nested Loops Join)
● 雜湊連線(Hash Join)
● 笛卡爾積(Cartesian Product)
如果where條件有not exists、not in或<>all運算子+子查詢,則Oracle會將其處理為反連線,,執行計劃中對應的關鍵字為anti。
SQL> select department_id,department_name from departments d where not exists (select 1 from employees e where d.department_id = e.department_id and e.salary > 2500);
16 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 3822487693
--------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 17 | 391 | 6 (17)| 00:00:01 |
| 1 | MERGE JOIN ANTI | | 17 | 391 | 6 (17)| 00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| DEPARTMENTS | 27 | 432 | 2 (0)| 00:00:01 |
| 3 | INDEX FULL SCAN | DEPT_ID_PK | 27 | | 1 (0)| 00:00:01 |
|* 4 | SORT UNIQUE | | 105 | 735 | 4 (25)| 00:00:01 |
|* 5 | TABLE ACCESS FULL | EMPLOYEES | 105 | 735 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------
SQL> select department_id,department_name from departments d where department_id not in (select department_id from employees e where d.department_id = e.department_id and e.salary > 2500);
16 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 3822487693
--------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 17 | 391 | 6 (17)| 00:00:01 |
| 1 | MERGE JOIN ANTI | | 17 | 391 | 6 (17)| 00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| DEPARTMENTS | 27 | 432 | 2 (0)| 00:00:01 |
| 3 | INDEX FULL SCAN | DEPT_ID_PK | 27 | | 1 (0)| 00:00:01 |
|* 4 | SORT UNIQUE | | 105 | 735 | 4 (25)| 00:00:01 |
|* 5 | TABLE ACCESS FULL | EMPLOYEES | 105 | 735 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------
SQL> select department_id,department_name from departments d where department_id<>all(select department_id from employees e where d.department_id = e.department_id and e.salary > 2500);
16 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 3822487693
--------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 17 | 391 | 6 (17)| 00:00:01 |
| 1 | MERGE JOIN ANTI | | 17 | 391 | 6 (17)| 00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| DEPARTMENTS | 27 | 432 | 2 (0)| 00:00:01 |
| 3 | INDEX FULL SCAN | DEPT_ID_PK | 27 | | 1 (0)| 00:00:01 |
|* 4 | SORT UNIQUE | | 105 | 735 | 4 (25)| 00:00:01 |
|* 5 | TABLE ACCESS FULL | EMPLOYEES | 105 | 735 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28536251/viewspace-2140549/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle的表連線方法(五)Oracle
- Oracle的表連線方法(六)Oracle
- Oracle的表連線方法(三)雜湊連線Oracle
- Oracle的表連線方法(一)排序合併連線Oracle排序
- Oracle的表連線方法(二)巢狀迴圈連線Oracle巢狀
- Oracle的表連線方法(四)笛卡爾積Oracle
- 【SQL】表連線七種方式SQL
- 表連線方法
- Oracle 表連線Oracle
- Oracle字串連線的方法Oracle字串
- ORACLE 表連線方式Oracle
- oracle表連線方式Oracle
- Oracle的三種表連線方式Oracle
- 【SQL】SQL表連線方法方式介紹(Oracle/Postgresql)SQLOracle
- Oracle 表連線方式詳解(外連結、內連線、自連線)Oracle
- oracle 各種表間連線Oracle
- Oracle表連線操作——Hash Join(雜湊連線)下Oracle
- Oracle表連線操作——Hash Join(雜湊連線)上Oracle
- JDBC 連線oracle三種方法JDBCOracle
- ORACLE表連線方式的分析與優化Oracle優化
- Oracle 19c中連線RMAN客戶端的連線方法Oracle客戶端
- Oracle 表連線方式分析(精讀)Oracle
- Oracle表連線操作——Merge Sort Join(合併排序連線)Oracle排序
- 不安裝Oracle客戶連線Oracle 8的方法(轉)Oracle
- 【SQL】表連線 --半連線SQL
- Oracle的左連線和右連線Oracle
- ORACLE表連線方式及常見用法(二)Oracle
- hive表連線和oracle測試對比HiveOracle
- Oracle(+)連線與Join連線Oracle
- Oracle左連線,右連線Oracle
- oracle bbed的連線Oracle
- oracle中的連線Oracle
- 表連線cost
- 表連線概念
- Java連線oracle資料庫的兩種常用方法JavaOracle資料庫
- 兩表連線三:合併連線
- Oracle優化器內部處理的表連線方式Oracle優化
- 【SQL】Oracle的內連線、左外連線、右外連線及全外連線SQLOracle