SQL 執行順序 你懂的
SELECT * FROM employees e LEFT JOIN departments d ON e.department_id = d.department_id
AND d.DEPARTMENT_ID > 100
很顯然and條件先於join執行
SELECT * FROM employees e LEFT JOIN departments d ON e.department_id = d.department_id
WHERE d.DEPARTMENT_ID > 100
SELECT * FROM employees e LEFT JOIN departments d ON e.department_id =
d.department_id WHERE d.DEPARTMENT_ID > 100
Plan hash value: 2599337293
----------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads |
----------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 2 |00:00:00.01 | 8 | 1 |
| 1 | NESTED LOOPS | | 1 | | 2 |00:00:00.01 | 8 | 1 |
| 2 | NESTED LOOPS | | 1 | 1 | 2 |00:00:00.01 | 6 | 1 |
| 3 | TABLE ACCESS BY INDEX ROWID | EMPLOYEES | 1 | 2 | 2 |00:00:00.01 | 4 | 1 |
|* 4 | INDEX RANGE SCAN | EMP_DEPARTMENT_IX | 1 | 2 | 2 |00:00:00.01 | 2 | 1 |
|* 5 | INDEX UNIQUE SCAN | DEPT_ID_PK | 2 | 1 | 2 |00:00:00.01 | 2 | 0 |
| 6 | TABLE ACCESS BY INDEX ROWID | DEPARTMENTS | 2 | 1 | 2 |00:00:00.01 | 2 | 0 |
----------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - access("E"."DEPARTMENT_ID">100)
5 - access("E"."DEPARTMENT_ID"="D"."DEPARTMENT_ID")
filter("D"."DEPARTMENT_ID">100)
26 rows selected.
SELECT * FROM employees e LEFT JOIN departments d ON e.department_id = d.department_id
AND d.DEPARTMENT_ID > 10 WHERE d.MANAGER_ID > 200
SELECT * FROM employees e LEFT JOIN departments d ON e.department_id =
d.department_id AND d.DEPARTMENT_ID > 10 WHERE d.MANAGER_ID > 200
Plan hash value: 3971452728
-------------------------------------------------------------------------------------------------------------
| Id | Operation | Name |Starts | E-Rows | A-Rows | A-Time | Buffers|
-------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 6 | 00:00:00.01 | 9 |
| 1 | NESTED LOOPS | | 1 | | 6 | 00:00:00.01 | 9 |
| 2 | NESTED LOOPS | | 1 | 9 | 6 | 00:00:00.01 | 7 |
|* 3 | TABLE ACCESS BY INDEX ROWID | DEPARTMENTS | 1 | 1 | 4 | 00:00:00.01 | 4 |
|* 4 | INDEX RANGE SCAN | DEPT_ID_PK | 1 | 26 | 26 | 00:00:00.01 | 2 |
|* 5 | INDEX RANGE SCAN | EMP_DEPARTMENT_IX | 4 | 10 | 6 | 00:00:00.01 | 3 |
| 6 | TABLE ACCESS BY INDEX ROWID | EMPLOYEES | 6 | 9 | 6 | 00:00:00.01 | 2 |
-------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - filter("D"."MANAGER_ID">200)
4 - access("D"."DEPARTMENT_ID">10)
5 - access("E"."DEPARTMENT_ID"="D"."DEPARTMENT_ID")
filter("E"."DEPARTMENT_ID">10)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29990276/viewspace-1867351/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Sql執行順序SQL
- 你是否真的懂 [程式的執行順序] 多程式 / 程式池
- 你瞭解一條sql的執行順序嗎SQL
- SQL 語句的執行順序SQL
- sql mysql 執行順序 (4)MySql
- SQL語句執行順序SQL
- SQL Server SQL語句執行順序SQLServer
- SQL語句各子句的執行順序SQL
- 可看執行順序的xplan.package.sqlPackageSQL
- sql select語法執行順序SQL
- sql中的or與and的執行順序問題SQL
- SQL 查詢語句的執行順序解析SQL
- Hive SQL語句的正確執行順序HiveSQL
- SQL語句中的AND和OR執行順序問題SQL
- JavaScript的執行順序JavaScript
- mysql 中sql語句關鍵字的書寫順序與執行順序MySql
- SQL語句中SELECT語句的執行順序SQL
- SQL中rownum和order by的執行順序的問題SQL
- T-sql語句查詢執行順序SQL
- SQL Select語句邏輯執行順序SQL
- oracle實用sql(15)--檢視SQL執行計劃的順序OracleSQL
- JavaScript執行順序分析JavaScript
- 任務執行順序
- for語句執行順序
- laravel Event執行順序Laravel
- mySQL 執行語句執行順序MySql
- sql語句執行順序與效能優化(1)SQL優化
- Oracle 優化器與sql查詢執行順序Oracle優化SQL
- SQL Server中SELECT語句執行順序解析SQLServer
- MySQL 查詢處理 SQL查詢執行順序MySql
- 關於 Promise 的執行順序Promise
- Spring Aop的執行順序Spring
- CSS規則的執行順序CSS
- Java類的基本執行順序Java
- pipeline的執行順序
- mysql 語句的執行順序MySql
- 一個 MySQL sql 語句執行順序帶來的 bugMySql
- js執行順序Event LoopJSOOP