使用 gather_plan_statistics hint 產生執行計劃

首先sqlplus登陸當前用戶

2、執行  運行 sql語句 ,在語句中加入     /*+ gather_plan_statistics */

例子: 執行  sql 語句  select   /*+ gather_plan_statistics */  count(employee_id) from hr.employees where department_id=50;

得到結果  :

COUNT(1)

----------

45

3、執行   查看計劃    select * from table(dbms_xplan.display_cursor(NULL,NULL,'ALLSTATS'));

得到結果:

PLAN_TABLE_OUTPUT

--------------------------------------------------------------------------------

SQL_ID  4dxpaqxz24a4q, child number 0

-------------------------------------

select   /*+ gather_plan_statistics */  count(employee_id) from

hr.employees where department_id=50

Plan hash value: 2271004725

--------------------------------------------------------------------------------

| Id  | Operation         | Name              | Starts | E-Rows | A-Rows |   A-Time   | Buffers |

--------------------------------------------------------------------------------

|   0 | SELECT STATEMENT  |                   |      1 |        |      1 |00:00:00.01 |       1 | PLAN_TABLE_OUTPUT

----------------------------------------------------------------------------------------------------------------------------------------------------------------

|   1 |  SORT AGGREGATE   |                   |      1 |      1 |      1 |00:00:00.01 |       1 |

|*  2 |   INDEX RANGE SCAN| EMP_DEPARTMENT_IX |      1 |     45 |     45 |00:00:00.01 |       1 |

-------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):

---------------------------------------------------

   2 - access("DEPARTMENT_ID"=50)

20 rows selected.

SQL>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章