用LEFT JOIN優化標量子查詢
《Oracle查詢優化改寫》讀書筆記
以下示例語句執行計劃
按書中方法,以LEFT JOIN改寫
注意到,LEFT JOIN的COST更高,並沒有起到優化效果。
原因分析:示例1中,以遊標方式(filter("B"."CUST_ID"=:B1) )過濾了CUSTOMER2的資料來源;而在示例2中,沒有過濾,全表搜尋了CUSTOMER2。
以下示例語句執行計劃
點選(此處)摺疊或開啟
- select a.cust_id,
-
(select b.cust_id from customers2 b where b.cust_id = a.cust_id) b_cust_id,
(select b.cust_first_name from customers2 b where b.cust_id = a.cust_id) b_cust_first_name,
(select b.cust_last_name from customers2 b where b.cust_id = a.cust_id) b_cust_last_name
from customers a -
-
Plan hash value: 3094712696
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1626K| 9527K| 951 (1)| 00:00:12 |
|* 1 | TABLE ACCESS FULL | CUSTOMERS2 | 19230 | 244K| 3 (0)| 00:00:01 |
|* 2 | TABLE ACCESS FULL | CUSTOMERS2 | 19230 | 469K| 3 (0)| 00:00:01 |
|* 3 | TABLE ACCESS FULL | CUSTOMERS2 | 19230 | 657K| 3 (0)| 00:00:01 |
| 4 | INDEX FAST FULL SCAN| CUSTOMERS_PK | 1626K| 9527K| 951 (1)| 00:00:12 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("B"."CUST_ID"=:B1)
2 - filter("B"."CUST_ID"=:B1)
3 - filter("B"."CUST_ID"=:B1)
Note
-----
- dynamic sampling used for this statement (level=2)
點選(此處)摺疊或開啟
-
select a.cust_id,
-
b.cust_id,
-
b.cust_first_name,
-
b.cust_last_name
-
from customers a
- left join customers2 b on a.cust_id = b.cust_id
-
Plan hash value: 555753586
----------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1626K| 82M| | 19127 (1)| 00:03:50 |
|* 1 | HASH JOIN OUTER | | 1626K| 82M| 27M| 19127 (1)| 00:03:50 |
| 2 | INDEX FAST FULL SCAN| CUSTOMERS_PK | 1626K| 9527K| | 951 (1)| 00:00:12 |
| 3 | TABLE ACCESS FULL | CUSTOMERS2 | 1922K| 86M| | 11412 (1)| 00:02:17 |
----------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("A"."CUST_ID"="B"."CUST_ID"(+))
Note
-----
- dynamic sampling used for this statement (level=2)
原因分析:示例1中,以遊標方式(filter("B"."CUST_ID"=:B1) )過濾了CUSTOMER2的資料來源;而在示例2中,沒有過濾,全表搜尋了CUSTOMER2。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22621861/viewspace-2076465/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MYSQL count標量子查詢改left joinMySql
- 標量子查詢優化(用group by 代替distinct)優化
- oracle update left join查詢Oracle
- join 查詢優化優化
- 連線查詢簡析 join 、 left join 、 right join
- 用WITH…AS改寫標量子查詢
- SQL中聯表查詢操作(LEFT JOIN, RIGHT JOIN, INNER JOIN)SQL
- 標量子查詢
- mysql left join 優化學習MySql優化
- 效能為王:SQL標量子查詢的優化案例分析SQL優化
- NOT IN、NOT EXISTS的相關子查詢改用LEFT JOIN--sql2000效能優化SQL優化
- 標量子查詢(二)
- 標量子查詢(一)
- MySql的join(連線)查詢 (三表 left join 寫法)MySql
- 三表關聯查詢-多次LEFT JOIN...ON
- mysql update join優化update in查詢效率MySql優化
- sql 連線查詢例項(left join)三表連線查詢SQL
- mysql常用連線查詢join,left,right,crossMySqlROS
- Oracle優化案例-用left join代替反連線 not in not exists(十)Oracle優化
- mysql的left join和inner join的效率對比,以及如何優化MySql優化
- 都是標量子查詢惹的禍
- MYSQL 怎麼 LEFT JOIN 多表聯查MySql
- MYSQL學習筆記25: 多表查詢(子查詢)[標量子查詢,列子查詢]MySql筆記
- 淺談查詢優化器中的JOIN演算法優化演算法
- GreatSQL 最佳化技巧:將 MINUS 改寫為標量子查詢SQL
- mysql中多個left join子查詢寫法以及別名用法MySql
- mysql + left joinMySql
- mysql left join轉inner joinMySql
- Oracle常用抓取SQL-標量子查詢等OracleSQL
- 帶彙總的標量子查詢改寫
- MySQL LEFT JOIN/ INNER JOIN/RIGHT JOINMySql
- 查詢優化優化
- mysql 標量子查詢和現金盤程式製作非法子查詢MySql
- SQL Server Left joinSQLServer
- LEFT JOIN 和JOIN 多表連線
- sql:left join和join區別SQL
- sql中的join、left join、right joinSQL
- 一個left join SQL 簡單優化分析SQL優化