DBAtlas · Database operations atlas

Evolve unaccepted SQL plan baseline plans

OraclePerformance

Command

-- 1) Plans waiting for acceptance:
SELECT sql_handle, plan_name, origin, enabled, accepted, fixed,
       TO_CHAR(created,'YYYY-MM-DD HH24:MI') AS created
FROM   dba_sql_plan_baselines
WHERE  accepted = 'NO'
ORDER  BY created DESC;

-- 2) Evolve task: test-executes the candidate plan against the accepted plan
VAR tname VARCHAR2(128)
VAR ename VARCHAR2(128)
BEGIN
  :tname := DBMS_SPM.CREATE_EVOLVE_TASK(
              sql_handle => '<sql_handle>',
              time_limit => 600,
              task_name  => 'EVOLVE_<sql_handle>');
  :ename := DBMS_SPM.EXECUTE_EVOLVE_TASK(task_name => :tname);
END;
/

SET LONG 1000000 LONGCHUNKSIZE 1000000 LINESIZE 200 PAGESIZE 0
SELECT DBMS_SPM.REPORT_EVOLVE_TASK(
         task_name => :tname, execution_name => :ename,
         type => 'TEXT', level => 'TYPICAL', section => 'ALL')
FROM   dual;

-- 3) If the report has recommendations (plans proven better), accept them:
SET SERVEROUTPUT ON
DECLARE
  n PLS_INTEGER;
BEGIN
  n := DBMS_SPM.IMPLEMENT_EVOLVE_TASK(task_name => :tname);
  DBMS_OUTPUT.PUT_LINE(n || ' plan(s) accepted');
END;
/
EXEC DBMS_SPM.DROP_EVOLVE_TASK(task_name => :tname);

What it does

When a baseline exists, new plans found by the optimizer are stored with ACCEPTED=NO. The evolve task test-executes these candidates against the accepted plan and accepts only those that are clearly better.

When to use it

For baselined SQL when a new index or new statistics may have produced a better plan; to decide manually without waiting for the automatic SYS_AUTO_SPM_EVOLVE_TASK (12c+).

Caution

Requires Enterprise Edition. Evolve actually executes the SQL (only the query part for DML); set time_limit for heavy SQL and avoid peak hours. Requires ADMINISTER SQL MANAGEMENT OBJECT and ADVISOR. SQL parsed as SYS cannot be evolved (ORA-16963); run it as the application user.

Open in DBAtlas →

Related