使用 gather_plan_statistics hint 產生執行計劃

首先sqlplus登錄當前用戶
二、執行 運行 sql語句 ,在語句中加入 /*+ gather_plan_statistics */
例子: 執行 sql 語句 select /*+ gather_plan_statistics */ count(employee_id) from hr.employees where department_id=50;
獲得結果 :
COUNT(1)

45
三、執行 查看計劃 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>sql

相關文章
相關標籤/搜索