如何能在執行計劃中看到Starts
SQL> explain plan for
2
2 SELECT *
3 FROM scott.emp
4 WHERE NOT EXISTS (SELECT 0
5 FROM scott.dept
6 WHERE dept.dname = 'SALES' AND dept.deptno = emp.deptno)
7 AND NOT EXISTS (SELECT 0
8 FROM scott.bonus
9 WHERE bonus.ename = emp.ename);
Explained
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 734347697
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 9 | 522 | 9 (12)| 00:00:01 |
|* 1 | HASH JOIN ANTI | | 9 | 522 | 9 (12)| 00:00:01 |
|* 2 | HASH JOIN ANTI | | 9 | 459 | 7 (15)| 00:00:01 |
| 3 | TABLE ACCESS FULL| EMP | 14 | 532 | 3 (0)| 00:00:01 |
|* 4 | TABLE ACCESS FULL| DEPT | 1 | 13 | 3 (0)| 00:00:01 |
| 5 | TABLE ACCESS FULL | BONUS | 1 | 7 | 2 (0)| 00:00:01 |
-----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("BONUS"."ENAME"="EMP"."ENAME")
2 - access("DEPT"."DEPTNO"="EMP"."DEPTNO")
4 - filter("DEPT"."DNAME"='SALES')
使用advanced也不顯示
SQL> explain plan for select * from scott.emp;
Explained
SQL> SELECT * FROM table(dbms_xplan.display(NULL,NULL,'advanced'));
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 3956160932
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 532 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| EMP | 14 | 532 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / EMP@SEL$1
Outline Data
-------------
/*+
BEGIN_OUTLINE_DATA
FULL(@"SEL$1" "EMP"@"SEL$1")
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
OUTLINE_LEAF(@"SEL$1")
ALL_ROWS
DB_VERSION('11.2.0.1')
OPTIMIZER_FEATURES_ENABLE('11.2.0.1')
IGNORE_OPTIM_EMBEDDED_HINTS
END_OUTLINE_DATA
*/
Column Projection Information (identified by operation id):
-----------------------------------------------------------
1 - "EMP"."EMPNO"[NUMBER,22], "EMP"."ENAME"[VARCHAR2,10],
"EMP"."JOB"[VARCHAR2,9], "EMP"."MGR"[NUMBER,22],
"EMP"."HIREDATE"[DATE,7], "EMP"."SAL"[NUMBER,22],
"EMP"."COMM"[NUMBER,22], "EMP"."DEPTNO"[NUMBER,22]
要得到starts要麼在SQLPLUS中將statistics_level設定all,並真實執行sql語句
因為display_cursor是從動態效能檢視v$session,v$sql,v$sql_plan和v$sql_plan_statistics_all中獲取直接計劃的使用explain plan for不行
因為它只生成執行計劃並沒真正地執行而且執行計劃是儲存在plan_table表中
並使用display來顯示
要麼在要執行的sql語句中statistics_level 仍然保留'typical' ,
然後用這個HINT/*+gather_plan_statistics */
SQL> alter session set statistics_level=all;
會話已更改。
SQL> select count(*) from scott.emp;
COUNT(*)
----------
14
SQL> select * from table(dbms_xplan.display_cursor(null,null,'allstats'));
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
SQL_ID abj9tmfcs15bm, child number 0
-------------------------------------
select count(*) from scott.emp
Plan hash value: 2937609675
-------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 1 |00:00:00.01 | 1 |
| 1 | SORT AGGREGATE | | 1 | 1 | 1 |00:00:00.01 | 1 |
| 2 | INDEX FULL SCAN| PK_EMP | 1 | 14 | 14 |00:00:00.01 | 1 |
-------------------------------------------------------------------------------------
已選擇14行。
SQL>
SQL> alter session set statistics_level='typical';
會話已更改。
SQL> select /*+gather_plan_statistics */ count(*) from scott.emp;
COUNT(*)
----------
14
SQL> select * from table(dbms_xplan.display_cursor(null,null,'allstats'));
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
SQL_ID 2vku9s3sb55tz, child number 0
-------------------------------------
select /*+gather_plan_statistics */ count(*) from scott.emp
Plan hash value: 2937609675
--------------------------------------------------------------------------------
-----
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 1 |00:00:00.01 | 1 |
| 1 | SORT AGGREGATE | | 1 | 1 | 1 |00:00:00.01 | 1 |
| 2 | INDEX FULL SCAN| PK_EMP | 1 | 14 | 14 |00:00:00.01 | 1 |
-------------------------------------------------------------------------------------
已選擇14行。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26015009/viewspace-765106/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 從Hash Join的執行計劃的細節中能看到點啥
- 如何看懂執行計劃!
- MySql中執行計劃如何來的——Optimizer TraceMySql
- 在Oracle中,如何得到真實的執行計劃?Oracle
- 執行計劃-1:獲取執行計劃
- SqlServer的執行計劃如何分析?SQLServer
- 【SPM】Oracle如何固定執行計劃Oracle
- oracle如何檢視執行計劃Oracle
- 看懂Oracle中的執行計劃Oracle
- oracle中開啟執行計劃Oracle
- oracle中執行計劃中的cardinalityOracle
- 執行計劃
- sql執行計劃變更和刪除快取中執行計劃的方法SQL快取
- 如何檢視SQL的執行計劃SQL
- Oracle執行計劃Explain Plan 如何使用OracleAI
- 不能在simulator執行
- SQLSERVER中得到執行計劃的方式SQLServer
- (4) MySQL中EXPLAIN執行計劃分析MySqlAI
- MySQL中in(常量列表)的執行計劃MySql
- 分析執行計劃優化SQLORACLE的執行計劃(轉)優化SQLOracle
- oracle sqlprofile 固定執行計劃,並遷移執行計劃OracleSQL
- 【sql調優之執行計劃】獲取執行計劃SQL
- SYBASE執行計劃
- MySQL 執行計劃MySql
- MySQL執行計劃MySql
- sql 執行計劃SQL
- ORACLE執行計劃Oracle
- 如何獲取真實的執行計劃
- 執行計劃中Row 數量為0
- 執行計劃中cost, card的含義
- 【執行計劃】Oracle獲取執行計劃的幾種方法Oracle
- 【Oracle】-【索引-HINT,執行計劃】-帶HINT的索引執行計劃Oracle索引
- 分析執行計劃最佳化SQLORACLE的執行計劃(轉)SQLOracle
- 如何清除某條SQL在庫快取中的執行計劃SQL快取
- 計算表掃描中執行計劃的COST
- 知識篇 | ORACLE 如何執行計劃繫結Oracle
- Oracle如何手動重新整理執行計劃Oracle
- Oracle10g如何獲取執行計劃Oracle