Oracle优化——基线自动捕捉(optimizer_capture_sql_plan_baselines,默认值为FALSE)

参见 Oracle性能优化求生指南。

SYS@ prod> select count(*) from dba_sql_plan_baselines ;

  COUNT(*)
----------
         2

SYS@ prod> show parameter spfile

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string      /u01/app/oracle/product/11.2.0
                                                 /dbhome_1/dbs/spfileprod.ora

这个参数用来控制优化器是否会自己捕捉基线(在SQL第一次执行之后自动捕捉)
SYS@ prod> alter system set optimizer_capture_sql_plan_baselines = true ;

System altered.

查看当前的SQL_HANDLE
SYS@ prod> select sql_handle from dba_sql_plan_baselines ;

SQL_HANDLE
------------------------------
SYS_SQL_0cf31d9f7b33b119
SYS_SQL_a8f88a44571be8dd
SYS_SQL_a8f88a44571be8dd
SYS_SQL_b61b88104ed13c53

注意,如果一个SQL只是偶尔执行了一个,优化可能不会马上把它加入到基线中,所以多执行几次
SYS@ prod> select count(*) from hr.employees ;

  COUNT(*)
----------
       107

… …
SYS@ prod> select count(*) from hr.employees ;

  COUNT(*)
----------
       107

SYS@ prod> select count(*) from hr.employees ;

  COUNT(*)
----------
       107

SYS@ prod> select sql_handle from dba_sql_plan_baselines ;

SQL_HANDLE
------------------------------
SYS_SQL_0cf31d9f7b33b119
SYS_SQL_a8f88a44571be8dd
SYS_SQL_a8f88a44571be8dd
SYS_SQL_a99903edfad71a5e
SYS_SQL_b61b88104ed13c53
SYS_SQL_ec276c73273b181f

6 rows selected.

关于这条SQL的基线已经被捕捉到了
SYS@ prod> select * from table( dbms_xplan.display_sql_plan_baseline('SYS_SQL_a99903edfad71a5e' , null , 'basic' ) ) ;

PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------
SQL handle: SYS_SQL_a99903edfad71a5e
SQL text: select count(*) from hr.employees
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Plan name: SQL_PLAN_am683xrxdf6ky0892e805         Plan id: 143845381
Enabled: YES     Fixed: NO      Accepted: YES     Origin: AUTO-CAPTURE
--------------------------------------------------------------------------------

Plan hash value: 3580537945

-----------------------------------------
| Id  | Operation        | Name         |
-----------------------------------------
|   0 | SELECT STATEMENT |              |
|   1 |  SORT AGGREGATE  |              |
|   2 |   INDEX FULL SCAN| EMP_EMAIL_UK |
-----------------------------------------

20 rows selected.


你可能感兴趣的:(数据库技术)