Oracle優化——如何檢視語句的準確的執行計劃(explain plan可能不是真實的)
參見 Oracle效能優化求生指南。
建虛擬索引
HR@ prod> create index test_ix1 on employees4 ( employee_id ) nosegment;
HR@ prod> alter session set "_use_nosegment_indexes" = true ;
HR@ prod> set autotrace on
HR@ prod> select /*oooooooooooo*/ * from employees4 where employee_id = 100 ;
EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- ---------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
100 Steven King SKING 515.123.4567 17-JUN-03
AD_PRES 24000 90
Execution Plan
----------------------------------------------------------
Plan hash value: 499133838
------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 133 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| EMPLOYEES4 | 1 | 133 | 2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | TEST_IX1 | 1 | | 1 (0)| 00:00:01 |
------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("EMPLOYEE_ID"=100)
Note
-----
- dynamic sampling used for this statement (level=2)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
5 consistent gets
0 physical reads
0 redo size
1299 bytes sent via SQL*Net to client
523 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
檢視真正的執行計劃,需要知道SQL_ID和CHILD_NUBMER。
HR@ prod> conn / as sysdba
Connected.
SYS@ prod> select sql_id , child_number from v$sql where sql_text like 'select /*oooooooooooo*/%' ;
SQL_ID CHILD_NUMBER
------------- ------------
gtx1pw85bgqz0 0
SYS@ prod> select * from table(dbms_xplan.display_cursor('gtx1pw85bgqz0' , 0 )) ;
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------
SQL_ID gtx1pw85bgqz0, child number 0
-------------------------------------
select /*oooooooooooo*/ * from employees4 where employee_id = 100
Plan hash value: 2568047056
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 3 (100)| |
|* 1 | TABLE ACCESS FULL| EMPLOYEES4 | 1 | 133 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("EMPLOYEE_ID"=100)
Note
-----
- dynamic sampling used for this statement (level=2)
22 rows selected.
實際中並沒有索引可以用,Oracle走的是全表掃描。
相關文章
- 【Explain Plan】檢視SQL的執行計劃AISQL
- 使用EXPLAIN PLAN來檢視執行計劃AI
- Oracle執行計劃Explain Plan 如何使用OracleAI
- Oracle如何檢視真實執行計劃(一)Oracle
- Oracle 執行計劃(Explain Plan) 說明OracleAI
- Oracle 執行計劃(Explain Plan) 說明OracleAI
- TOAD中檢視執行計劃(Explain Plan)AI
- 【檢視】使用V$SQL_PLAN檢視獲取曾經執行過的SQL語句執行計劃SQL
- 檢視執行計劃方法總結之一:explain plan命令AI
- 使用 EXPLAIN PLAN 獲取SQL語句執行計劃 (R0.1)AISQL
- 配置oracle 解釋執行計劃--explain planOracleAI
- 如何在oracle10g上檢視sql的執行計劃(不實際執行語句)OracleSQL
- autotrace 和explain plan for可能導致執行計劃錯誤AI
- 【執行計劃】格式化EXPLAIN PLAN的輸出結果AI
- 【最佳化】explain plan for 方式存取執行計劃AI
- 檢視ORACLE的實際執行計劃Oracle
- 【SQL_PLAN】Oracle 透過檢視sql_plan 格式化執行計劃SQLOracle
- ORACLE執行計劃的檢視Oracle
- 通過分析SQL語句的執行計劃優化SQL語句SQL優化
- oracle執行計劃的使用(EXPLAIN)OracleAI
- oracle如何檢視執行計劃Oracle
- 在Oracle中,如何得到真實的執行計劃?Oracle
- oracle explain plan for獲取執行計劃並不可靠.OracleAI
- Oracle檢視執行計劃的命令Oracle
- oracle檢視執行計劃的方法Oracle
- Oracle 檢視SQL的執行計劃OracleSQL
- sql中使用函式導致explain plan for和set autotrace得到執行計劃不準確SQL函式AI
- 如何檢視SQL的執行計劃SQL
- 如何獲取真實的執行計劃
- 通過分析SQL語句的執行計劃優化SQL 二SQL優化
- oracle 使用explain plan分析查詢語句OracleAI
- 檢視一個正在執行的sql的執行計劃(explain for connection processlist_id)SQLAI
- Explain Extended檢視MySQL的優化AIMySql優化
- 怎樣得到準確的執行計劃
- 檢視語句執行的時間
- 分析執行計劃優化SQLSQL語句處理的過程(轉)優化SQL
- 通過分析SQL語句的執行計劃優化SQL(總結)SQL優化
- 【Oracle】如何檢視sql 執行計劃的歷史變更OracleSQL