sql中使用函式導致explain plan for和set autotrace得到執行計劃不準確
平臺:Oracle 9.2.0.8.0 - 64bit
發現sql消耗I/O很大
SELECT B.WO_NO, B.NO, B.CUST_PART_NO,B.SKU_NO, D.NAMEE,A.NAMEE
FROM IMB.STATION D,IMB.R_WIP B,
(SELECT A.WIP_ID ,E.NAMEE
FROM IMB.R_WIP_LOG A ,IMB.STATION B,IMB.LINE E
WHERE A.LINE_ID=E.ID
AND A.STATION_TIME>=TO_DATE(:"SYS_B_00",:"SYS_B_01")
AND A.STATION_TIME<=TO_DATE(:"SYS_B_02",:"SYS_B_03")
AND A.STATION_ID=B.ID
AND B.NAMEE =:"SYS_B_04"
AND A.LINE_ID=E.ID
AND E.CODE =:"SYS_B_05"
and a.DEL_FLAG=:"SYS_B_06"
)A,IMB.PRODUCT C
WHERE D.CODE=B.CUR_STATION_CODE
AND B.CUR_STATION_CODE= :"SYS_B_07"
AND B.ID=A.WIP_ID
AND B.DEL_FLAG=:"SYS_B_08"
AND B.PRODUCT_ID=C.ID
AND C.CATEGORY_KEY =:"SYS_B_09"
AND EB_WEB.Get_Dsdnb_Configfast(B.CUST_PART_NO) /*函式*/= :"SYS_B_10"
透過explain plan for和set autotrace on得到的執行計劃均為下面:
------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost |
------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 158 | 7 |
| 1 | FILTER | | | | |
| 2 | MERGE JOIN CARTESIAN | | 1 | 158 | 7 |
| 3 | NESTED LOOPS | | 1 | 141 | 6 |
| 4 | NESTED LOOPS | | 1 | 123 | 5 |
| 5 | NESTED LOOPS | | 1 | 111 | 4 |
| 6 | NESTED LOOPS | | 1 | 44 | 3 |
| 7 | TABLE ACCESS BY INDEX ROWID| LINE | 1 | 20 | 1 |
| 8 | INDEX RANGE SCAN | IX_LINE_CODE | 1 | | 1 |
| 9 | TABLE ACCESS BY INDEX ROWID| R_WIP_LOG | 1 | 24 | 2 |
| 10 | INDEX RANGE SCAN | IX_R_WIP_LOG_STATION_TIME | 3 | | 2 |
| 11 | TABLE ACCESS BY INDEX ROWID | R_WIP | 1 | 67 | 1 |
| 12 | INDEX UNIQUE SCAN | IDX_R_WIP_ID | 1 | | 1 |
| 13 | TABLE ACCESS BY INDEX ROWID | PRODUCT | 1 | 12 | 1 |
| 14 | INDEX UNIQUE SCAN | PRODUCT_ID | 1 | | |
| 15 | TABLE ACCESS BY INDEX ROWID | STATION | 1 | 18 | 1 |
| 16 | INDEX UNIQUE SCAN | STATION_ID | 1 | | |
| 17 | BUFFER SORT | | 1 | 17 | 6 |
| 18 | TABLE ACCESS BY INDEX ROWID | STATION | 1 | 17 | 1 |
| 19 | INDEX RANGE SCAN | IX_STATION_CODE | 1 | | |
------------------------------------------------------------------------------------------------
按此執行計劃應該不至於產生高I/O消耗,做了次10046 trace(alter session set events '10046 trace name context forever';)發現執行計劃迥異,懷疑是SQL中用到函式EB_WEB.Get_Dsdnb_Configfast所導致:
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 2 7.25 9.49 126822 135314 0 27
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 4 7.25 9.50 126822 135314 0 27
Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: SYS
Rows Row Source Operation
------- ---------------------------------------------------
27 FILTER
27 NESTED LOOPS
27 NESTED LOOPS
75 HASH JOIN
1 TABLE ACCESS FULL STATION
1275 TABLE ACCESS BY INDEX ROWID R_WIP_LOG
1359 NESTED LOOPS
79 MERGE JOIN CARTESIAN
1 TABLE ACCESS BY INDEX ROWID STATION
1 INDEX RANGE SCAN IX_STATION_CODE (object id 31557)
79 BUFFER SORT
79 TABLE ACCESS FULL R_WIP
1279 INDEX RANGE SCAN IX_WIP_LOG_WIP_ID (object id 31496)
27 TABLE ACCESS BY INDEX ROWID LINE
75 INDEX UNIQUE SCAN LINE_ID (object id 31239)
27 TABLE ACCESS BY INDEX ROWID PRODUCT
27 INDEX UNIQUE SCAN PRODUCT_ID (object id 31308)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25583515/viewspace-712262/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- autotrace 和explain plan for可能導致執行計劃錯誤AI
- set autotrace on 產生不準確的執行計劃
- 檢視sql執行計劃--set autotraceSQL
- 【Explain Plan】檢視SQL的執行計劃AISQL
- Oracle執行計劃Explain Plan 如何使用OracleAI
- EXPLAIN PLAN FOR 和 SET AUTOTRACE之間的差別AI
- 統計資訊不準確導致執行計劃走了笛卡爾積
- 使用EXPLAIN PLAN來檢視執行計劃AI
- 檢視sql執行計劃--set autotrace [final]SQL
- 怎樣得到準確的執行計劃
- 開啟執行計劃set autotrace on
- 使用 EXPLAIN PLAN 獲取SQL語句執行計劃 (R0.1)AISQL
- ORACLE analyse table方式收集表統計資訊導致SQL執行計劃不準確而效能下降OracleSQL
- Oracle 執行計劃(Explain Plan) 說明OracleAI
- Oracle 執行計劃(Explain Plan) 說明OracleAI
- 使用set autotrace on 檢視資料庫執行計劃資料庫
- TOAD中檢視執行計劃(Explain Plan)AI
- 配置oracle 解釋執行計劃--explain planOracleAI
- EXPLAIN PLAN and SQL*PLUS AUTOTRACE may not generate actual plansAISQL
- 一次ORACLE SQL謂詞跨界導致的執行計劃不準OracleSQL
- 【最佳化】explain plan for 方式存取執行計劃AI
- Oracle優化——如何檢視語句的準確的執行計劃(explain plan可能不是真實的)Oracle優化AI
- oracle explain plan for獲取執行計劃並不可靠.OracleAI
- oracle執行計劃的使用(EXPLAIN)OracleAI
- 檢視執行計劃方法總結之一:explain plan命令AI
- 【執行計劃】格式化EXPLAIN PLAN的輸出結果AI
- 在MySQL中使用explain查詢SQL的執行計劃MySqlAI
- (4) MySQL中EXPLAIN執行計劃分析MySqlAI
- explain執行計劃分析AI
- mysql執行計劃explainMySqlAI
- mysql explain 執行計劃MySqlAI
- MySQL——通過EXPLAIN分析SQL的執行計劃MySqlAI
- SQLSERVER中得到執行計劃的方式SQLServer
- 統計資訊不正確導致執行計劃的錯誤選擇
- Sql最佳化(十八) 調優工具(1)set autotrace和excute plan tableSQL
- autotrace explain plan 相關引數解釋AI
- 獲取執行計劃之Autotrace
- sql中使用函式導致cost高SQL函式