SlideShare a Scribd company logo
1 of 12
Download to read offline
Evolving Execution Plans - example
Evolving Execution Plans
1. Check what SQL Plan Baselines that exists in the database:
SELECT SQL_HANDLE, SQL_TEXT, PLAN_NAME, ORIGIN,ENABLED, ACCEPTED
FROM DBA_SQL_PLAN_BASELINES;
no rows selected
SQL> show parameter OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES
NAME TYPE VALUE
------------------------------------ ----------- ----------
optimizer_capture_sql_plan_baselines boolean FALSE
2. Turn on capture:
SQL> alter system set OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES=true;
3. The SQL statement that we are going to work with in this example:
select /* bsln */ d.department_id, count(e.employee_id)
from hr.employees e, hr.departments d
where e.department_id=d.department_id
and d.department_id=(select department_id from hr.employees where employee_id=180)
group by d.department_id;
DEPARTMENT_ID COUNT(E.EMPLOYEE_ID)
------------- --------------------
50 46
Execute the statement again, so it is captured by the SQL plan management. (This only captures repeatable statements, remember?)
Check and confirm the statement was captured:
col sql_handle for A20
col sql_text for A20 word_wrapped
col plan_name for A30
col origin for A12
col enabled for A3
Evolving Execution Plans - example
col accepted for A3
col fixed for A3
set linesize 150
SELECT SQL_HANDLE, SQL_TEXT, PLAN_NAME,
ORIGIN, ENABLED, ACCEPTED, FIXED
FROM DBA_SQL_PLAN_BASELINES
WHERE lower(SQL_TEXT) LIKE '%bsln%';
SQL_HANDLE SQL_TEXT PLAN_NAME ORIGIN ENA ACC FIX
-------------------- -------------------- ------------------------------ ------------ --- ---
SQL_d32392b2e4557ee0 select /* bsln */ SQL_PLAN_d68wkqbk5azr09158ac75 AUTO-CAPTURE YES YES NO
d.department_id,
count(e.employee_id)
from hr.employees e,
hr.
Get the execution plan:
SQL> @xplan aubf20ky0r3p1 1
SQL_ID CHILD_NUMBER PLAN_HASH_VALUE ELAPSED CPU EXEC LIO PIO NUM_ROWS
--------------- -------------- --------------- ---------- ---------- ---------- ---------- ---------- ----------
aubf20ky0r3p1 0 4023081993 .027 .022 1 216 0 1
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------------------------------------
SQL_ID aubf20ky0r3p1, child number 0
-------------------------------------
select /* bsln */ d.department_id, count(e.employee_id) from
hr.employees e, hr.departments d where e.department_id=d.department_id
and d.department_id=(select department_id from hr.employees where
employee_id=180) group by d.department_id
Plan hash value: 4023081993
----------------------------------------------------------------------------------------
| Id | Operation | Name | E-Rows | Cost (%CPU)| E-Time |
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | 5 (100)| |
| 1 | HASH GROUP BY | | 7 | 5 (20)| 00:00:01 |
|* 2 | TABLE ACCESS FULL | EMPLOYEES | 10 | 3 (0)| 00:00:01 |
Evolving Execution Plans - example
| 3 | TABLE ACCESS BY INDEX ROWID| EMPLOYEES | 1 | 1 (0)| 00:00:01 |
|* 4 | INDEX UNIQUE SCAN | EMP_EMP_ID_PK | 1 | 0 (0)| |
----------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$F7859CDE
2 - SEL$F7859CDE / E@SEL$1
3 - SEL$2 / EMPLOYEES@SEL$2
4 - SEL$2 / EMPLOYEES@SEL$2
Outline Data
-------------
/*+
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('18.1.0')
DB_VERSION('18.1.0')
ALL_ROWS
OUTLINE_LEAF(@"SEL$2")
OUTLINE_LEAF(@"SEL$F7859CDE")
ELIMINATE_JOIN(@"SEL$1" "D"@"SEL$1")
OUTLINE(@"SEL$1")
FULL(@"SEL$F7859CDE" "E"@"SEL$1")
USE_HASH_AGGREGATION(@"SEL$F7859CDE")
PUSH_SUBQ(@"SEL$2")
INDEX_RS_ASC(@"SEL$2" "EMPLOYEES"@"SEL$2" ("EMPLOYEES"."EMPLOYEE_ID"))
END_OUTLINE_DATA
*/
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter(("E"."DEPARTMENT_ID" IS NOT NULL AND "E"."DEPARTMENT_ID"=))
4 - access("EMPLOYEE_ID"=180)
Note
-----
- Warning: basic plan statistics not available. These are only collected when:
* hint 'gather_plan_statistics' is used for the statement or
* parameter 'statistics_level' is set to 'ALL', at session or system level
Evolving Execution Plans - example
4. Let's create an index:
create index hr.emp_dept_ix on hr.employees(employee_id,department_id);
Run the SQL statement again:
select /* bsln */ d.department_id, count(e.employee_id)
from hr.employees e, hr.departments d
where e.department_id=d.department_id
and d.department_id=(select department_id from hr.employees where employee_id=180)
group by d.department_id;
Check the baselines:
SQL> SELECT SQL_HANDLE, SQL_TEXT, PLAN_NAME,
2 ORIGIN, ENABLED, ACCEPTED, FIXED
3 FROM DBA_SQL_PLAN_BASELINES
4 WHERE lower(SQL_TEXT) LIKE '%bsln%';
SQL_HANDLE SQL_TEXT PLAN_NAME ORIGIN ENA ACC FIX
-------------------- -------------------- ------------------------------ ------------ --- --- ---
SQL_d32392b2e4557ee0 select /* bsln */ SQL_PLAN_d68wkqbk5azr09158ac75 AUTO-CAPTURE YES YES NO
d.department_id,
count(e.employee_id)
from hr.employees e,
hr.
SQL_d32392b2e4557ee0 select /* bsln */ SQL_PLAN_d68wkqbk5azr09ecdb1d7 AUTO-CAPTURE YES NO NO
d.department_id,
count(e.employee_id)
from hr.employees e,
hr.
There are 2 execution plans now.
The SQL_HANDLE is the same, but the plan name is different: SQL_PLAN_d68wkqbk5azr09158ac75, SQL_PLAN_d68wkqbk5azr09ecdb1d7
Evolving Execution Plans - example
Notice that SQL_PLAN_d68wkqbk5azr09ecdb1d7 is enabled, but not accepted.
Let's evolve the second plan:
a. create the evolve task:
set serveroutput on
declare
l_return varchar2(30000);
begin
l_return := dbms_spm.create_evolve_task(sql_handle
=>'SQL_d32392b2e4557ee0');
dbms_output.put_line('Task Name: ' || l_return);
end;
/
Task Name: TASK_21
PL/SQL procedure successfully completed.
b. execute the evolve task:
set serveroutput on
declare
l_return varchar2(30000);
begin
l_return :=dbms_spm.execute_evolve_task(task_name
=>'TASK_21');
dbms_output.put_line('Execution Name: ' || l_return);
end;
/
Execution Name: EXEC_271
PL/SQL procedure successfully completed.
c. report on the evolve task
set long 1000000
set pagesize 1000
set longchunksize 100
Evolving Execution Plans - example
set linesize 200
select dbms_spm.report_evolve_task(task_name=>'TASK_21',execution_name=>'EXEC_271') as report
from dual;
REPORT
----------------------------------------------------------------------------------------------------
GENERAL INFORMATION SECTION
---------------------------------------------------------------------------------------------
Task Information:
---------------------------------------------
Task Name : TASK_21
Task Owner : SYS
Execution Name : EXEC_271
Execution Type : SPM EVOLVE
Scope : COMPREHENSIVE
Status : COMPLETED
Started : 11/28/2018 08:42:59
Finished : 11/28/2018 08:43:00
Last Updated : 11/28/2018 08:43:00
Global Time Limit : 2147483646
Per-Plan Time Limit : UNUSED
Number of Errors : 0
---------------------------------------------------------------------------------------------
SUMMARY SECTION
---------------------------------------------------------------------------------------------
Number of plans processed : 2
Number of findings : 2
Number of recommendations : 2
Number of errors : 0
---------------------------------------------------------------------------------------------
DETAILS SECTION
---------------------------------------------------------------------------------------------
Object ID : 2
Test Plan Name : SQL_PLAN_d68wkqbk5azr09ecdb1d7
Base Plan Name : SQL_PLAN_d68wkqbk5azr09158ac75
SQL Handle : SQL_d32392b2e4557ee0
Parsing Schema : SYS
Test Plan Creator : SYS
SQL Text : select /* bsln */ d.department_id, count(e.employee_id)
from hr.employees e, hr.departments d where
Evolving Execution Plans - example
e.department_id=d.department_id and d.department_id=(select
department_id from hr.employees where employee_id=180)
group by d.department_id
Execution Statistics:
-----------------------------
Base Plan Test Plan
---------------------------- ----------------------------
Elapsed Time (s): .000024 .000021
CPU Time (s): .000029 .000015
Buffer Gets: 0 0
Optimizer Cost: 5 3
Disk Reads: 0 0
Direct Writes: 0 0
Rows Processed: 0 0
Executions: 10 10
FINDINGS SECTION
---------------------------------------------------------------------------------------------
Findings (1):
-----------------------------
1. The plan was verified in 0.07500 seconds. It passed the benefit criterion
because its verified performance was 4.48035 times better than that of the
baseline plan.
Recommendation:
-----------------------------
Consider accepting the plan. Execute
dbms_spm.accept_sql_plan_baseline(task_name => 'TASK_21', object_id => 2,
task_owner => 'SYS');
EXPLAIN PLANS SECTION
---------------------------------------------------------------------------------------------
Baseline Plan
-----------------------------
Plan Id : 101
Plan Hash Value : 2438507637
------------------------------------------------------------------------------------------
Evolving Execution Plans - example
| Id | Operation | Name | Rows | Bytes | Cost | Time |
------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 7 | 21 | 5 | 00:00:01 |
| 1 | HASH GROUP BY | | 7 | 21 | 5 | 00:00:01 |
| * 2 | TABLE ACCESS FULL | EMPLOYEES | 10 | 30 | 3 | 00:00:01 |
| 3 | TABLE ACCESS BY INDEX ROWID | EMPLOYEES | 1 | 7 | 1 | 00:00:01 |
| * 4 | INDEX UNIQUE SCAN | EMP_EMP_ID_PK | 1 | | 0 | 00:00:01 |
------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
------------------------------------------
* 2 - filter("E"."DEPARTMENT_ID" IS NOT NULL AND "E"."DEPARTMENT_ID"= (SELECT /*+ PUSH_SUBQ INDEX_RS
_ASC ("EMPLOYEES" "EMP_EMP_ID_PK") */ "DEPARTMENT_ID" FROM "HR"."EMPLOYEES"
"EMPLOYEES" WHERE "EMPLOYEE_ID"=180))
* 4 - access("EMPLOYEE_ID"=180)
Test Plan
-----------------------------
Plan Id : 102
Plan Hash Value : 2664280535
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost | Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 7 | 21 | 3 | 00:00:01 |
| 1 | HASH GROUP BY | | 7 | 21 | 3 | 00:00:01 |
| * 2 | INDEX SKIP SCAN | EMP_DEPT_IX | 10 | 30 | 1 | 00:00:01 |
| * 3 | INDEX RANGE SCAN | EMP_DEPT_IX | 1 | 7 | 1 | 00:00:01 |
-----------------------------------------------------------------------------
Predicate Information (identified by operation id):
------------------------------------------
* 2 - access("E"."DEPARTMENT_ID"= (SELECT /*+ PUSH_SUBQ INDEX ("EMPLOYEES" "EMP_DEPT_IX") */ "DEPART
MENT_ID" FROM "HR"."EMPLOYEES" "EMPLOYEES" WHERE "EMPLOYEE_ID"=180))
* 2 - filter("E"."DEPARTMENT_ID" IS NOT NULL AND "E"."DEPARTMENT_ID"= (SELECT /*+ PUSH_SUBQ INDEX ("
EMPLOYEES" "EMP_DEPT_IX") */ "DEPARTMENT_ID" FROM "HR"."EMPLOYEES" "EMPLOYEES"
WHERE "EMPLOYEE_ID"=180))
* 3 - access("EMPLOYEE_ID"=180)
---------------------------------------------------------------------------------------------
Object ID : 3
Test Plan Name : SQL_PLAN_d68wkqbk5azr09ecdb1d7
Evolving Execution Plans - example
Base Plan Name : SQL_PLAN_d68wkqbk5azr09158ac75
SQL Handle : SQL_d32392b2e4557ee0
Parsing Schema : SYS
Test Plan Creator : SYS
SQL Text : select /* bsln */ d.department_id, count(e.employee_id)
from hr.employees e, hr.departments d where
e.department_id=d.department_id and d.department_id=(select
department_id from hr.employees where employee_id=180)
group by d.department_id
Execution Statistics:
-----------------------------
Base Plan Test Plan
---------------------------- ----------------------------
Elapsed Time (s): .00002 .000018
CPU Time (s): .00003 .000023
Buffer Gets: 0 0
Optimizer Cost: 5 3
Disk Reads: 0 0
Direct Writes: 0 0
Rows Processed: 0 0
Executions: 10 10
FINDINGS SECTION
---------------------------------------------------------------------------------------------
Findings (1):
-----------------------------
1. The plan was verified in 0.04000 seconds. It passed the benefit criterion
because its verified performance was 4.46286 times better than that of the
baseline plan.
Recommendation:
-----------------------------
Consider accepting the plan. Execute
dbms_spm.accept_sql_plan_baseline(task_name => 'TASK_21', object_id => 3,
task_owner => 'SYS');
EXPLAIN PLANS SECTION
---------------------------------------------------------------------------------------------
Evolving Execution Plans - example
Baseline Plan
-----------------------------
Plan Id : 103
Plan Hash Value : 2438507637
------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost | Time |
------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 7 | 21 | 5 | 00:00:01 |
| 1 | HASH GROUP BY | | 7 | 21 | 5 | 00:00:01 |
| * 2 | TABLE ACCESS FULL | EMPLOYEES | 10 | 30 | 3 | 00:00:01 |
| 3 | TABLE ACCESS BY INDEX ROWID | EMPLOYEES | 1 | 7 | 1 | 00:00:01 |
| * 4 | INDEX UNIQUE SCAN | EMP_EMP_ID_PK | 1 | | 0 | 00:00:01 |
------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
------------------------------------------
* 2 - filter("E"."DEPARTMENT_ID" IS NOT NULL AND "E"."DEPARTMENT_ID"= (SELECT /*+ PUSH_SUBQ INDEX_RS
_ASC ("EMPLOYEES" "EMP_EMP_ID_PK") */ "DEPARTMENT_ID" FROM "HR"."EMPLOYEES"
"EMPLOYEES" WHERE "EMPLOYEE_ID"=180))
* 4 - access("EMPLOYEE_ID"=180)
Test Plan
-----------------------------
Plan Id : 104
Plan Hash Value : 2664280535
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost | Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 7 | 21 | 3 | 00:00:01 |
| 1 | HASH GROUP BY | | 7 | 21 | 3 | 00:00:01 |
| * 2 | INDEX SKIP SCAN | EMP_DEPT_IX | 10 | 30 | 1 | 00:00:01 |
| * 3 | INDEX RANGE SCAN | EMP_DEPT_IX | 1 | 7 | 1 | 00:00:01 |
-----------------------------------------------------------------------------
Predicate Information (identified by operation id):
------------------------------------------
* 2 - access("E"."DEPARTMENT_ID"= (SELECT /*+ PUSH_SUBQ INDEX ("EMPLOYEES" "EMP_DEPT_IX") */ "DEPART
MENT_ID" FROM "HR"."EMPLOYEES" "EMPLOYEES" WHERE "EMPLOYEE_ID"=180))
* 2 - filter("E"."DEPARTMENT_ID" IS NOT NULL AND "E"."DEPARTMENT_ID"= (SELECT /*+ PUSH_SUBQ INDEX ("
EMPLOYEES" "EMP_DEPT_IX") */ "DEPARTMENT_ID" FROM "HR"."EMPLOYEES" "EMPLOYEES"
Evolving Execution Plans - example
WHERE "EMPLOYEE_ID"=180))
* 3 - access("EMPLOYEE_ID"=180)
...
---------------------------------------------------------------------------------------------
d. implement the evolve task
set serveroutput on
declare
l_return number;
begin
l_return:=dbms_spm.implement_evolve_task
(task_name => 'TASK_21');
dbms_output.put_line('Accepted Plans: ' || l_return);
end;
/
Accepted Plans: 2
PL/SQL procedure successfully completed.
Verify that both plans are accepted now:
SQL> SELECT SQL_HANDLE, SQL_TEXT, PLAN_NAME,
2 ORIGIN, ENABLED, ACCEPTED, FIXED
3 FROM DBA_SQL_PLAN_BASELINES
4 WHERE lower(SQL_TEXT) LIKE '%bsln%';
SQL_HANDLE SQL_TEXT PLAN_NAME ORIGIN ENA ACC FIX
-------------------- -------------------- ------------------------------ ------------ --- --- ---
SQL_d32392b2e4557ee0 select /* bsln */ SQL_PLAN_d68wkqbk5azr09158ac75 AUTO-CAPTURE YES YES NO
d.department_id,
count(e.employee_id)
from hr.employees e,
hr.
SQL_d32392b2e4557ee0 select /* bsln */ SQL_PLAN_d68wkqbk5azr09ecdb1d7 AUTO-CAPTURE YES YES NO
d.department_id,
Evolving Execution Plans - example
count(e.employee_id)
from hr.employees e,
hr.

More Related Content

Similar to EvolveExecutionPlans.pdf

SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?Andrej Pashchenko
 
Exadata - Smart Scan Testing
Exadata - Smart Scan TestingExadata - Smart Scan Testing
Exadata - Smart Scan TestingMonowar Mukul
 
Oracle Query Tuning Tips - Get it Right the First Time
Oracle Query Tuning Tips - Get it Right the First TimeOracle Query Tuning Tips - Get it Right the First Time
Oracle Query Tuning Tips - Get it Right the First TimeDean Richards
 
Randolf Geist – IT-Tage 2015 – Oracle Parallel Execution – Analyse und Troubl...
Randolf Geist – IT-Tage 2015 – Oracle Parallel Execution – Analyse und Troubl...Randolf Geist – IT-Tage 2015 – Oracle Parallel Execution – Analyse und Troubl...
Randolf Geist – IT-Tage 2015 – Oracle Parallel Execution – Analyse und Troubl...Informatik Aktuell
 
Managing Statistics for Optimal Query Performance
Managing Statistics for Optimal Query PerformanceManaging Statistics for Optimal Query Performance
Managing Statistics for Optimal Query PerformanceKaren Morton
 
Dimensional performance benchmarking of SQL
Dimensional performance benchmarking of SQLDimensional performance benchmarking of SQL
Dimensional performance benchmarking of SQLBrendan Furey
 
How Can I tune it When I Can't Change the Code?
How Can I tune it When I Can't Change the Code?How Can I tune it When I Can't Change the Code?
How Can I tune it When I Can't Change the Code?Sage Computing Services
 
Oracle Database 12c Application Development
Oracle Database 12c Application DevelopmentOracle Database 12c Application Development
Oracle Database 12c Application DevelopmentSaurabh K. Gupta
 
Informix Warehouse Accelerator (IWA) features in version 12.1
Informix Warehouse Accelerator (IWA) features in version 12.1Informix Warehouse Accelerator (IWA) features in version 12.1
Informix Warehouse Accelerator (IWA) features in version 12.1Keshav Murthy
 
Oracle Diagnostics : Explain Plans (Simple)
Oracle Diagnostics : Explain Plans (Simple)Oracle Diagnostics : Explain Plans (Simple)
Oracle Diagnostics : Explain Plans (Simple)Hemant K Chitale
 
New Tuning Features in Oracle 11g - How to make your database as boring as po...
New Tuning Features in Oracle 11g - How to make your database as boring as po...New Tuning Features in Oracle 11g - How to make your database as boring as po...
New Tuning Features in Oracle 11g - How to make your database as boring as po...Sage Computing Services
 
Oracle Database Performance Tuning Basics
Oracle Database Performance Tuning BasicsOracle Database Performance Tuning Basics
Oracle Database Performance Tuning Basicsnitin anjankar
 
Adapting to Adaptive Plans on 12c
Adapting to Adaptive Plans on 12cAdapting to Adaptive Plans on 12c
Adapting to Adaptive Plans on 12cMauro Pagano
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012Roland Bouman
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012Roland Bouman
 

Similar to EvolveExecutionPlans.pdf (20)

SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?
 
Exadata - Smart Scan Testing
Exadata - Smart Scan TestingExadata - Smart Scan Testing
Exadata - Smart Scan Testing
 
Oracle Query Tuning Tips - Get it Right the First Time
Oracle Query Tuning Tips - Get it Right the First TimeOracle Query Tuning Tips - Get it Right the First Time
Oracle Query Tuning Tips - Get it Right the First Time
 
Randolf Geist – IT-Tage 2015 – Oracle Parallel Execution – Analyse und Troubl...
Randolf Geist – IT-Tage 2015 – Oracle Parallel Execution – Analyse und Troubl...Randolf Geist – IT-Tage 2015 – Oracle Parallel Execution – Analyse und Troubl...
Randolf Geist – IT-Tage 2015 – Oracle Parallel Execution – Analyse und Troubl...
 
Managing Statistics for Optimal Query Performance
Managing Statistics for Optimal Query PerformanceManaging Statistics for Optimal Query Performance
Managing Statistics for Optimal Query Performance
 
Dimensional performance benchmarking of SQL
Dimensional performance benchmarking of SQLDimensional performance benchmarking of SQL
Dimensional performance benchmarking of SQL
 
How Can I tune it When I Can't Change the Code?
How Can I tune it When I Can't Change the Code?How Can I tune it When I Can't Change the Code?
How Can I tune it When I Can't Change the Code?
 
Oracle Database 12c Application Development
Oracle Database 12c Application DevelopmentOracle Database 12c Application Development
Oracle Database 12c Application Development
 
PoC Oracle Exadata - Retour d'expérience
PoC Oracle Exadata - Retour d'expériencePoC Oracle Exadata - Retour d'expérience
PoC Oracle Exadata - Retour d'expérience
 
Informix Warehouse Accelerator (IWA) features in version 12.1
Informix Warehouse Accelerator (IWA) features in version 12.1Informix Warehouse Accelerator (IWA) features in version 12.1
Informix Warehouse Accelerator (IWA) features in version 12.1
 
SAV
SAVSAV
SAV
 
Oracle Diagnostics : Explain Plans (Simple)
Oracle Diagnostics : Explain Plans (Simple)Oracle Diagnostics : Explain Plans (Simple)
Oracle Diagnostics : Explain Plans (Simple)
 
New Tuning Features in Oracle 11g - How to make your database as boring as po...
New Tuning Features in Oracle 11g - How to make your database as boring as po...New Tuning Features in Oracle 11g - How to make your database as boring as po...
New Tuning Features in Oracle 11g - How to make your database as boring as po...
 
Do You Know The 11g Plan?
Do You Know The 11g Plan?Do You Know The 11g Plan?
Do You Know The 11g Plan?
 
Oracle Database Performance Tuning Basics
Oracle Database Performance Tuning BasicsOracle Database Performance Tuning Basics
Oracle Database Performance Tuning Basics
 
Adapting to Adaptive Plans on 12c
Adapting to Adaptive Plans on 12cAdapting to Adaptive Plans on 12c
Adapting to Adaptive Plans on 12c
 
Rmoug ashmaster
Rmoug ashmasterRmoug ashmaster
Rmoug ashmaster
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
 
Aspects of 10 Tuning
Aspects of 10 TuningAspects of 10 Tuning
Aspects of 10 Tuning
 

Recently uploaded

CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 

Recently uploaded (20)

ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 

EvolveExecutionPlans.pdf

  • 1. Evolving Execution Plans - example Evolving Execution Plans 1. Check what SQL Plan Baselines that exists in the database: SELECT SQL_HANDLE, SQL_TEXT, PLAN_NAME, ORIGIN,ENABLED, ACCEPTED FROM DBA_SQL_PLAN_BASELINES; no rows selected SQL> show parameter OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES NAME TYPE VALUE ------------------------------------ ----------- ---------- optimizer_capture_sql_plan_baselines boolean FALSE 2. Turn on capture: SQL> alter system set OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES=true; 3. The SQL statement that we are going to work with in this example: select /* bsln */ d.department_id, count(e.employee_id) from hr.employees e, hr.departments d where e.department_id=d.department_id and d.department_id=(select department_id from hr.employees where employee_id=180) group by d.department_id; DEPARTMENT_ID COUNT(E.EMPLOYEE_ID) ------------- -------------------- 50 46 Execute the statement again, so it is captured by the SQL plan management. (This only captures repeatable statements, remember?) Check and confirm the statement was captured: col sql_handle for A20 col sql_text for A20 word_wrapped col plan_name for A30 col origin for A12 col enabled for A3
  • 2. Evolving Execution Plans - example col accepted for A3 col fixed for A3 set linesize 150 SELECT SQL_HANDLE, SQL_TEXT, PLAN_NAME, ORIGIN, ENABLED, ACCEPTED, FIXED FROM DBA_SQL_PLAN_BASELINES WHERE lower(SQL_TEXT) LIKE '%bsln%'; SQL_HANDLE SQL_TEXT PLAN_NAME ORIGIN ENA ACC FIX -------------------- -------------------- ------------------------------ ------------ --- --- SQL_d32392b2e4557ee0 select /* bsln */ SQL_PLAN_d68wkqbk5azr09158ac75 AUTO-CAPTURE YES YES NO d.department_id, count(e.employee_id) from hr.employees e, hr. Get the execution plan: SQL> @xplan aubf20ky0r3p1 1 SQL_ID CHILD_NUMBER PLAN_HASH_VALUE ELAPSED CPU EXEC LIO PIO NUM_ROWS --------------- -------------- --------------- ---------- ---------- ---------- ---------- ---------- ---------- aubf20ky0r3p1 0 4023081993 .027 .022 1 216 0 1 PLAN_TABLE_OUTPUT ---------------------------------------------------------------------------------------------------------------------------------- SQL_ID aubf20ky0r3p1, child number 0 ------------------------------------- select /* bsln */ d.department_id, count(e.employee_id) from hr.employees e, hr.departments d where e.department_id=d.department_id and d.department_id=(select department_id from hr.employees where employee_id=180) group by d.department_id Plan hash value: 4023081993 ---------------------------------------------------------------------------------------- | Id | Operation | Name | E-Rows | Cost (%CPU)| E-Time | ---------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | 5 (100)| | | 1 | HASH GROUP BY | | 7 | 5 (20)| 00:00:01 | |* 2 | TABLE ACCESS FULL | EMPLOYEES | 10 | 3 (0)| 00:00:01 |
  • 3. Evolving Execution Plans - example | 3 | TABLE ACCESS BY INDEX ROWID| EMPLOYEES | 1 | 1 (0)| 00:00:01 | |* 4 | INDEX UNIQUE SCAN | EMP_EMP_ID_PK | 1 | 0 (0)| | ---------------------------------------------------------------------------------------- Query Block Name / Object Alias (identified by operation id): ------------------------------------------------------------- 1 - SEL$F7859CDE 2 - SEL$F7859CDE / E@SEL$1 3 - SEL$2 / EMPLOYEES@SEL$2 4 - SEL$2 / EMPLOYEES@SEL$2 Outline Data ------------- /*+ BEGIN_OUTLINE_DATA IGNORE_OPTIM_EMBEDDED_HINTS OPTIMIZER_FEATURES_ENABLE('18.1.0') DB_VERSION('18.1.0') ALL_ROWS OUTLINE_LEAF(@"SEL$2") OUTLINE_LEAF(@"SEL$F7859CDE") ELIMINATE_JOIN(@"SEL$1" "D"@"SEL$1") OUTLINE(@"SEL$1") FULL(@"SEL$F7859CDE" "E"@"SEL$1") USE_HASH_AGGREGATION(@"SEL$F7859CDE") PUSH_SUBQ(@"SEL$2") INDEX_RS_ASC(@"SEL$2" "EMPLOYEES"@"SEL$2" ("EMPLOYEES"."EMPLOYEE_ID")) END_OUTLINE_DATA */ Predicate Information (identified by operation id): --------------------------------------------------- 2 - filter(("E"."DEPARTMENT_ID" IS NOT NULL AND "E"."DEPARTMENT_ID"=)) 4 - access("EMPLOYEE_ID"=180) Note ----- - Warning: basic plan statistics not available. These are only collected when: * hint 'gather_plan_statistics' is used for the statement or * parameter 'statistics_level' is set to 'ALL', at session or system level
  • 4. Evolving Execution Plans - example 4. Let's create an index: create index hr.emp_dept_ix on hr.employees(employee_id,department_id); Run the SQL statement again: select /* bsln */ d.department_id, count(e.employee_id) from hr.employees e, hr.departments d where e.department_id=d.department_id and d.department_id=(select department_id from hr.employees where employee_id=180) group by d.department_id; Check the baselines: SQL> SELECT SQL_HANDLE, SQL_TEXT, PLAN_NAME, 2 ORIGIN, ENABLED, ACCEPTED, FIXED 3 FROM DBA_SQL_PLAN_BASELINES 4 WHERE lower(SQL_TEXT) LIKE '%bsln%'; SQL_HANDLE SQL_TEXT PLAN_NAME ORIGIN ENA ACC FIX -------------------- -------------------- ------------------------------ ------------ --- --- --- SQL_d32392b2e4557ee0 select /* bsln */ SQL_PLAN_d68wkqbk5azr09158ac75 AUTO-CAPTURE YES YES NO d.department_id, count(e.employee_id) from hr.employees e, hr. SQL_d32392b2e4557ee0 select /* bsln */ SQL_PLAN_d68wkqbk5azr09ecdb1d7 AUTO-CAPTURE YES NO NO d.department_id, count(e.employee_id) from hr.employees e, hr. There are 2 execution plans now. The SQL_HANDLE is the same, but the plan name is different: SQL_PLAN_d68wkqbk5azr09158ac75, SQL_PLAN_d68wkqbk5azr09ecdb1d7
  • 5. Evolving Execution Plans - example Notice that SQL_PLAN_d68wkqbk5azr09ecdb1d7 is enabled, but not accepted. Let's evolve the second plan: a. create the evolve task: set serveroutput on declare l_return varchar2(30000); begin l_return := dbms_spm.create_evolve_task(sql_handle =>'SQL_d32392b2e4557ee0'); dbms_output.put_line('Task Name: ' || l_return); end; / Task Name: TASK_21 PL/SQL procedure successfully completed. b. execute the evolve task: set serveroutput on declare l_return varchar2(30000); begin l_return :=dbms_spm.execute_evolve_task(task_name =>'TASK_21'); dbms_output.put_line('Execution Name: ' || l_return); end; / Execution Name: EXEC_271 PL/SQL procedure successfully completed. c. report on the evolve task set long 1000000 set pagesize 1000 set longchunksize 100
  • 6. Evolving Execution Plans - example set linesize 200 select dbms_spm.report_evolve_task(task_name=>'TASK_21',execution_name=>'EXEC_271') as report from dual; REPORT ---------------------------------------------------------------------------------------------------- GENERAL INFORMATION SECTION --------------------------------------------------------------------------------------------- Task Information: --------------------------------------------- Task Name : TASK_21 Task Owner : SYS Execution Name : EXEC_271 Execution Type : SPM EVOLVE Scope : COMPREHENSIVE Status : COMPLETED Started : 11/28/2018 08:42:59 Finished : 11/28/2018 08:43:00 Last Updated : 11/28/2018 08:43:00 Global Time Limit : 2147483646 Per-Plan Time Limit : UNUSED Number of Errors : 0 --------------------------------------------------------------------------------------------- SUMMARY SECTION --------------------------------------------------------------------------------------------- Number of plans processed : 2 Number of findings : 2 Number of recommendations : 2 Number of errors : 0 --------------------------------------------------------------------------------------------- DETAILS SECTION --------------------------------------------------------------------------------------------- Object ID : 2 Test Plan Name : SQL_PLAN_d68wkqbk5azr09ecdb1d7 Base Plan Name : SQL_PLAN_d68wkqbk5azr09158ac75 SQL Handle : SQL_d32392b2e4557ee0 Parsing Schema : SYS Test Plan Creator : SYS SQL Text : select /* bsln */ d.department_id, count(e.employee_id) from hr.employees e, hr.departments d where
  • 7. Evolving Execution Plans - example e.department_id=d.department_id and d.department_id=(select department_id from hr.employees where employee_id=180) group by d.department_id Execution Statistics: ----------------------------- Base Plan Test Plan ---------------------------- ---------------------------- Elapsed Time (s): .000024 .000021 CPU Time (s): .000029 .000015 Buffer Gets: 0 0 Optimizer Cost: 5 3 Disk Reads: 0 0 Direct Writes: 0 0 Rows Processed: 0 0 Executions: 10 10 FINDINGS SECTION --------------------------------------------------------------------------------------------- Findings (1): ----------------------------- 1. The plan was verified in 0.07500 seconds. It passed the benefit criterion because its verified performance was 4.48035 times better than that of the baseline plan. Recommendation: ----------------------------- Consider accepting the plan. Execute dbms_spm.accept_sql_plan_baseline(task_name => 'TASK_21', object_id => 2, task_owner => 'SYS'); EXPLAIN PLANS SECTION --------------------------------------------------------------------------------------------- Baseline Plan ----------------------------- Plan Id : 101 Plan Hash Value : 2438507637 ------------------------------------------------------------------------------------------
  • 8. Evolving Execution Plans - example | Id | Operation | Name | Rows | Bytes | Cost | Time | ------------------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 7 | 21 | 5 | 00:00:01 | | 1 | HASH GROUP BY | | 7 | 21 | 5 | 00:00:01 | | * 2 | TABLE ACCESS FULL | EMPLOYEES | 10 | 30 | 3 | 00:00:01 | | 3 | TABLE ACCESS BY INDEX ROWID | EMPLOYEES | 1 | 7 | 1 | 00:00:01 | | * 4 | INDEX UNIQUE SCAN | EMP_EMP_ID_PK | 1 | | 0 | 00:00:01 | ------------------------------------------------------------------------------------------ Predicate Information (identified by operation id): ------------------------------------------ * 2 - filter("E"."DEPARTMENT_ID" IS NOT NULL AND "E"."DEPARTMENT_ID"= (SELECT /*+ PUSH_SUBQ INDEX_RS _ASC ("EMPLOYEES" "EMP_EMP_ID_PK") */ "DEPARTMENT_ID" FROM "HR"."EMPLOYEES" "EMPLOYEES" WHERE "EMPLOYEE_ID"=180)) * 4 - access("EMPLOYEE_ID"=180) Test Plan ----------------------------- Plan Id : 102 Plan Hash Value : 2664280535 ----------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost | Time | ----------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 7 | 21 | 3 | 00:00:01 | | 1 | HASH GROUP BY | | 7 | 21 | 3 | 00:00:01 | | * 2 | INDEX SKIP SCAN | EMP_DEPT_IX | 10 | 30 | 1 | 00:00:01 | | * 3 | INDEX RANGE SCAN | EMP_DEPT_IX | 1 | 7 | 1 | 00:00:01 | ----------------------------------------------------------------------------- Predicate Information (identified by operation id): ------------------------------------------ * 2 - access("E"."DEPARTMENT_ID"= (SELECT /*+ PUSH_SUBQ INDEX ("EMPLOYEES" "EMP_DEPT_IX") */ "DEPART MENT_ID" FROM "HR"."EMPLOYEES" "EMPLOYEES" WHERE "EMPLOYEE_ID"=180)) * 2 - filter("E"."DEPARTMENT_ID" IS NOT NULL AND "E"."DEPARTMENT_ID"= (SELECT /*+ PUSH_SUBQ INDEX (" EMPLOYEES" "EMP_DEPT_IX") */ "DEPARTMENT_ID" FROM "HR"."EMPLOYEES" "EMPLOYEES" WHERE "EMPLOYEE_ID"=180)) * 3 - access("EMPLOYEE_ID"=180) --------------------------------------------------------------------------------------------- Object ID : 3 Test Plan Name : SQL_PLAN_d68wkqbk5azr09ecdb1d7
  • 9. Evolving Execution Plans - example Base Plan Name : SQL_PLAN_d68wkqbk5azr09158ac75 SQL Handle : SQL_d32392b2e4557ee0 Parsing Schema : SYS Test Plan Creator : SYS SQL Text : select /* bsln */ d.department_id, count(e.employee_id) from hr.employees e, hr.departments d where e.department_id=d.department_id and d.department_id=(select department_id from hr.employees where employee_id=180) group by d.department_id Execution Statistics: ----------------------------- Base Plan Test Plan ---------------------------- ---------------------------- Elapsed Time (s): .00002 .000018 CPU Time (s): .00003 .000023 Buffer Gets: 0 0 Optimizer Cost: 5 3 Disk Reads: 0 0 Direct Writes: 0 0 Rows Processed: 0 0 Executions: 10 10 FINDINGS SECTION --------------------------------------------------------------------------------------------- Findings (1): ----------------------------- 1. The plan was verified in 0.04000 seconds. It passed the benefit criterion because its verified performance was 4.46286 times better than that of the baseline plan. Recommendation: ----------------------------- Consider accepting the plan. Execute dbms_spm.accept_sql_plan_baseline(task_name => 'TASK_21', object_id => 3, task_owner => 'SYS'); EXPLAIN PLANS SECTION ---------------------------------------------------------------------------------------------
  • 10. Evolving Execution Plans - example Baseline Plan ----------------------------- Plan Id : 103 Plan Hash Value : 2438507637 ------------------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost | Time | ------------------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 7 | 21 | 5 | 00:00:01 | | 1 | HASH GROUP BY | | 7 | 21 | 5 | 00:00:01 | | * 2 | TABLE ACCESS FULL | EMPLOYEES | 10 | 30 | 3 | 00:00:01 | | 3 | TABLE ACCESS BY INDEX ROWID | EMPLOYEES | 1 | 7 | 1 | 00:00:01 | | * 4 | INDEX UNIQUE SCAN | EMP_EMP_ID_PK | 1 | | 0 | 00:00:01 | ------------------------------------------------------------------------------------------ Predicate Information (identified by operation id): ------------------------------------------ * 2 - filter("E"."DEPARTMENT_ID" IS NOT NULL AND "E"."DEPARTMENT_ID"= (SELECT /*+ PUSH_SUBQ INDEX_RS _ASC ("EMPLOYEES" "EMP_EMP_ID_PK") */ "DEPARTMENT_ID" FROM "HR"."EMPLOYEES" "EMPLOYEES" WHERE "EMPLOYEE_ID"=180)) * 4 - access("EMPLOYEE_ID"=180) Test Plan ----------------------------- Plan Id : 104 Plan Hash Value : 2664280535 ----------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost | Time | ----------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 7 | 21 | 3 | 00:00:01 | | 1 | HASH GROUP BY | | 7 | 21 | 3 | 00:00:01 | | * 2 | INDEX SKIP SCAN | EMP_DEPT_IX | 10 | 30 | 1 | 00:00:01 | | * 3 | INDEX RANGE SCAN | EMP_DEPT_IX | 1 | 7 | 1 | 00:00:01 | ----------------------------------------------------------------------------- Predicate Information (identified by operation id): ------------------------------------------ * 2 - access("E"."DEPARTMENT_ID"= (SELECT /*+ PUSH_SUBQ INDEX ("EMPLOYEES" "EMP_DEPT_IX") */ "DEPART MENT_ID" FROM "HR"."EMPLOYEES" "EMPLOYEES" WHERE "EMPLOYEE_ID"=180)) * 2 - filter("E"."DEPARTMENT_ID" IS NOT NULL AND "E"."DEPARTMENT_ID"= (SELECT /*+ PUSH_SUBQ INDEX (" EMPLOYEES" "EMP_DEPT_IX") */ "DEPARTMENT_ID" FROM "HR"."EMPLOYEES" "EMPLOYEES"
  • 11. Evolving Execution Plans - example WHERE "EMPLOYEE_ID"=180)) * 3 - access("EMPLOYEE_ID"=180) ... --------------------------------------------------------------------------------------------- d. implement the evolve task set serveroutput on declare l_return number; begin l_return:=dbms_spm.implement_evolve_task (task_name => 'TASK_21'); dbms_output.put_line('Accepted Plans: ' || l_return); end; / Accepted Plans: 2 PL/SQL procedure successfully completed. Verify that both plans are accepted now: SQL> SELECT SQL_HANDLE, SQL_TEXT, PLAN_NAME, 2 ORIGIN, ENABLED, ACCEPTED, FIXED 3 FROM DBA_SQL_PLAN_BASELINES 4 WHERE lower(SQL_TEXT) LIKE '%bsln%'; SQL_HANDLE SQL_TEXT PLAN_NAME ORIGIN ENA ACC FIX -------------------- -------------------- ------------------------------ ------------ --- --- --- SQL_d32392b2e4557ee0 select /* bsln */ SQL_PLAN_d68wkqbk5azr09158ac75 AUTO-CAPTURE YES YES NO d.department_id, count(e.employee_id) from hr.employees e, hr. SQL_d32392b2e4557ee0 select /* bsln */ SQL_PLAN_d68wkqbk5azr09ecdb1d7 AUTO-CAPTURE YES YES NO d.department_id,
  • 12. Evolving Execution Plans - example count(e.employee_id) from hr.employees e, hr.