SlideShare a Scribd company logo
1 of 45
Using SQL Plan Management (SPM) to
balance Plan Flexibility and Plan Stability
Carlos Sierra
Carlos Sierra
• SQLTXPLAIN + SQL Health-Check SQLHC +
• Consultant/Developer/DBA/Design/+
• Oracle Performance + SQL Tuning
• Oracle Database Health-Check
• Tools + Scripts
• Speaker
Enkitec (c) 2014 2
Topics
• Motivation
• SQL Plan Management (SPM)
– Mechanics
– Demos
Enkitec (c) 2014 3
Plan Flexibility
• Cost-based Optimizer (CBO)
– Introduced in Oracle 7
– Computes an Optimal Plan based on
• Heuristics
• Query Predicates
• Schema Object Statistics
• Several Others
Enkitec (c) 2014 4
Flexibility: Good or Evil?
• CBO Mission
– Compute an Optimal Plan for a given SQL and its Data
• Plans have many and complex Dependencies
• CBO Performance
– Successful most of the times
• Produces a sub-optimal Plan sometimes
Enkitec (c) 2014 5
DBA Recurrent Nightmare
• A business critical process experiences an
occasional slow down
– Same SQL usually runs quickly
– Developers claim they haven’t changed anything
– Users claim they do the same every time
– Business keeps reporting this: to YOU!
Enkitec (c) 2014 6
Why Plans Perform Inconsistently? (1)
• Concurrency with some other Process
• State of Buffer Cache
• RAC Node Affinity
• CPU Starvation
• Sudden Changes on Data Volume
• Inconsistent Performance through Database Link
Enkitec (c) 2014 7
Why Plans Perform Inconsistently? (2)
• Downgraded Parallel Execution
• Crossing Small-Table Threshold
• Resource Manager Directive
• Plan Flips
• Many Others…
Enkitec (c) 2014 8
Why a Plan Flips? (1)
• Bind Variable Peeking with Histograms
• Outdated Schema Object (SO) Statistics
• Missing SO Statistics
• Fresh SO Statistics
• New Empty Partitions
Enkitec (c) 2014 9
Why a Plan Flips? (2)
• Incomplete set of CBO Hints
– Either on SQL Text or SQL Profile
• Dropped, Invalid, Invisible or new Indexes
• Index or Table rebuild
• Two or more Plans with similar Cost
Enkitec (c) 2014 10
Why a Plan Flips? (3)
• Database Parameters Changes
• CBO System Statistics Changes
• Asynchronous SO Statistics Gathering
• Many Others…
Enkitec (c) 2014 11
How to Mitigate Plan Flipping?
• Solid CBO Statistics
• Default CBO Parameters
• Avoid Global Changes
Enkitec (c) 2014 12
Plan Flexibility Allies
• CBO Parameters
• CBO Statistics
• Dynamic Sampling
• Cardinality Feedback
• Cursor Sharing
• Adaptive Cursor Sharing (ACS)
Enkitec (c) 2014 13
Plan Stability Tools
• CBO Hints
• Stored Outlines
• SQL Profiles
• SQL Plan Management (SPM)
Enkitec (c) 2014 14
SQL Plan Management
• 11g+
• Multiple Persistent Optimal Execution Plans per
SQL
• Only “accepted” and “enabled” Plans are Executed
• New Plans are acknowledged but not Executed
• Goal: Plan Stability with controlled Flexibility
Enkitec (c) 2014 15
SQL Plan Baseline
• A set of Plans available to the CBO for a given SQL
– Identified by SQL Handle and Signature
• Hash function on SQL Text
• dbms_sqltune.sqltext_to_signature
– View dba_sql_plan_baselines
• enabled = YES
• accepted = YES
• reproduced = YES
Enkitec (c) 2014 16
Plan History
• Content of dba_sql_plan_baselines
• Includes SQL Plan Baseline
• Includes Pending Plans
– accepted = NO and last_verified is NULL
• Includes Rejected Plans
– accepted = NO and last_verified is not NULL
• Includes Disabled Plans
Enkitec (c) 2014 17
Methods to Create a Plan Baseline
1. Capture
2. Load
a. Cursor Cache (CUR)
b. SQL Tuning Set (STS)
c. Stored Outline
3. Migration
Enkitec (c) 2014 18
1. Capture
2. Load
a. CUR
b. STS
c. AWR
d. SPA
e. TRC
3. Migration
Capturing a SQL Plan Baseline (1)
• Set optimizer_use_sql_plan_baselines to TRUE
(default)
• Set optimizer_capture_sql_plan_baselines to TRUE
(default is FALSE)
– Set this parameter at SESSION level
• Execute SQL 2 times
• Set optimizer_capture_sql_plan_baselines to FALSE
Enkitec (c) 2014 19
Capturing a SQL Plan Baseline (2)
Enkitec (c) 2014 20
Loading SQL Plan Baseline from Cache
• dbms_spm.load_plans_from_cursor_cache
– Inputs
• sql_id
• plan_hash_value (opt)
– Outputs
• Number of Plans loaded
Enkitec (c) 2014 21
22
DBMS_SPM.LOAD_PLANS_FROM_CURSOR_CACHE (
sql_id IN VARCHAR2,
plan_hash_value IN NUMBER := NULL,
sql_text IN CLOB,
fixed IN VARCHAR2 := 'NO',
enabled IN VARCHAR2 := 'YES')
RETURN PLS_INTEGER;
DBMS_SPM.LOAD_PLANS_FROM_CURSOR_CACHE (
sql_id IN VARCHAR2,
plan_hash_value IN NUMBER := NULL,
sql_handle IN VARCHAR2,
fixed IN VARCHAR2 := 'NO',
enabled IN VARCHAR2 := 'YES')
RETURN PLS_INTEGER;
DBMS_SPM.LOAD_PLANS_FROM_CURSOR_CACHE (
sql_id IN VARCHAR2,
plan_hash_value IN NUMBER := NULL,
fixed IN VARCHAR2 := 'NO',
enabled IN VARCHAR2 := 'YES')
RETURN PLS_INTEGER;
DBMS_SPM.LOAD_PLANS_FROM_CURSOR_CACHE (
attribute_name IN VARCHAR2,
attribute_value IN VARCHAR2,
fixed IN VARCHAR2 := 'NO',
enabled IN VARCHAR2 := 'YES')
RETURN PLS_INTEGER;
Enkitec (c) 2014
One of possible attribute names:
• 'SQL_TEXT' (like)
• 'PARSING_SCHEMA_NAME' (equality)
• 'MODULE' (equality)
• 'ACTION' (equality)
SQL text to use in identifying the SQL plan
baseline into which the plans are loaded. If the
SQL plan baseline does not exist, it is created.
The use of text is crucial when the user tunes a
SQL statement by adding hints to its text and
then wants to load the resulting plan(s) into the
SQL plan baseline of the original SQL statement.
SQL handle to use in identifying the SQL plan
baseline into which the plans are loaded. The
sql_handle must denote an existing SQL plan
baseline. The use of handle is crucial when the
user tunes a SQL statement by adding hints to its
text and then wants to load the resulting plan(s)
into the SQL plan baseline of the original SQL
statement.
Plan identifier. Default NULL means capture all
plans present in the cursor cache for the SQL
statement identified by SQL_ID.
SQL Plan Baseline Loading Options
• Load a Plan from a Hinted version of a SQL into SQL
Baseline of Original SQL
– Use SQL Text if there is no pre-existing SQL Baseline
– Use SQL Handle if SQL Baseline already exists
• Load one or more Cursor Plans (memory) for a SQL
• Load Plans for Subset of Cursors based on Schema,
SQL Text “like” or Application (Module or Action)
Enkitec (c) 2014 23
Demo 6
• Load Plans for Query out of Demo 5
– demo5.sql (1st time)
– load_plans.sql
• Execute Demo 5 again and review Plan History
– demo5.sql (2nd time)
– list_plans.sql
• Execute demo5.sql 2x (3rd & 4th) and verify results
Enkitec (c) 2014 24
Demo 6 Results (after 3rd demo5.sql)
CHILD EXECUTIONS BUFFER_GETS PLAN_HASH_VALUE SHAR SENS AWRE
----------- ----------- ----------- --------------- ---- ---- ----
0 3 9090 3600618656 Y Y N
CHILD BUCKET_ID COUNT
----------- ----------- -----------
0 0 0
0 1 1
0 2 2
Note
-----
- SQL plan baseline SQL_PLAN_652hmt7yxthdwc0e59472 used for this statement
CREATED PLAN_NAME ENA ACC REP FIX
------------------------------ ------------------------------ --- --- --- ---
21-JUN-14 02.00.10.000000 PM SQL_PLAN_652hmt7yxthdw80508062 YES YES YES NO
21-JUN-14 02.00.10.000000 PM SQL_PLAN_652hmt7yxthdwc0e59472 YES YES YES NO
21-JUN-14 02.00.10.000000 PM SQL_PLAN_652hmt7yxthdwe00bee24 YES YES YES NO
21-JUN-14 02.00.19.000000 PM SQL_PLAN_652hmt7yxthdwc82a6b0c YES NO YES NO
Enkitec (c) 2014 25
Demo 6 Results (after 4th demo5.sql)
CHILD EXECUTIONS BUFFER_GETS PLAN_HASH_VALUE SHAR SENS AWRE
----------- ----------- ----------- --------------- ---- ---- ----
0 2 723482 847574763 N Y N
1 1 2404 3600618656 Y Y Y
2 1 1977 189372815 Y Y Y
3 1 568 847574763 Y Y Y
Note
-----
- SQL plan baseline SQL_PLAN_652hmt7yxthdw80508062 used for this statement
CREATED PLAN_NAME ENA ACC REP FIX
------------------------------ ------------------------------ --- --- --- ---
28-DEC-13 02.03.43.000000 PM SQL_PLAN_652hmt7yxthdw501f1424 YES YES YES NO
28-DEC-13 02.03.43.000000 PM SQL_PLAN_652hmt7yxthdwb6c39290 YES YES YES NO
28-DEC-13 02.03.43.000000 PM SQL_PLAN_652hmt7yxthdwd624c0cd YES YES YES NO
28-DEC-13 02.03.50.000000 PM SQL_PLAN_652hmt7yxthdwc82a6b0c YES NO YES NO
Enkitec (c) 2014 26
Demo 7
• Drop SQL Plan Baseline
– drop_plans.sql
• Create SQL Patch with /*+ BIND_AWARE */ Hint
– sqlpch.sql for 8u0n7w1jug5dg connected as SYS
• Load Plans for Query out of Demo 5
– demo5.sql
– load_plans.sql
Enkitec (c) 2014 27
Demo 7 Results
CHILD EXECUTIONS BUFFER_GETS PLAN_HASH_VALUE SHAR SENS AWRE
----------- ----------- ----------- --------------- ---- ---- ----
0 1 2191 847574763 N Y Y
1 1 3030 2048551027 Y Y Y
2 1 2404 3600618656 Y Y Y
3 1 1977 189372815 Y Y Y
4 1 568 847574763 Y Y Y
CREATED PLAN_NAME ENA ACC REP FIX
------------------------------ ------------------------------ --- --- --- ---
21-JUN-14 02.09.14.000000 PM SQL_PLAN_652hmt7yxthdw80508062 YES YES YES NO
21-JUN-14 02.09.14.000000 PM SQL_PLAN_652hmt7yxthdwc0e59472 YES YES YES NO
21-JUN-14 02.09.14.000000 PM SQL_PLAN_652hmt7yxthdwc82a6b0c YES YES YES NO
21-JUN-14 02.09.14.000000 PM SQL_PLAN_652hmt7yxthdwe00bee24 YES YES YES NO
Enkitec (c) 2014 28
Demo 8
• Execute queries 1-5 and observe how number of
Executions increases per Child Cursor
– flush.sql
– demo8.sql
– demo8.sql
– demo8.sql
Enkitec (c) 2014 29
Demo 8 Results
CHILD EXECUTIONS BUFFER_GETS PLAN_HASH_VALUE SHAR SENS AWRE
----------- ----------- ----------- --------------- ---- ---- ----
0 1 3030 2048551027 Y Y Y
1 1 2404 3600618656 Y Y Y
2 1 1977 189372815 Y Y Y
3 1 568 847574763 N Y Y
4 1 724 847574763 Y Y Y
Note
-----
- SQL patch "sqlpch_8u0n7w1jug5dg" used for this statement
- SQL plan baseline SQL_PLAN_652hmt7yxthdwb6c39290 used for this statement
CHILD EXECUTIONS BUFFER_GETS PLAN_HASH_VALUE SHAR SENS AWRE
----------- ----------- ----------- --------------- ---- ---- ----
0 2 6060 2048551027 Y Y Y
1 2 4808 3600618656 Y Y Y
2 2 3954 189372815 Y Y Y
3 1 568 847574763 N Y Y
4 3 2016 847574763 Y Y Y
Enkitec (c) 2014 30
Evolving a Plan (1)
• Evolving a Plan means “accepting” it
– Promoting it from Plan History into SQL Plan Baseline
• dbms_spm.evolve_sql_plan_baseline
– sql_handle (opt)
– plan_name (opt)
– verify (default YES)
– commit (default YES)
Enkitec (c) 2014 31
Enkitec (c) 2014 32
DBMS_SPM.EVOLVE_SQL_PLAN_BASELINE (
sql_handle IN VARCHAR2 := NULL,
plan_name IN VARCHAR2 := NULL,
time_limit IN INTEGER := DBMS_SPM.AUTO_LIMIT,
verify IN VARCHAR2 := 'YES',
commit IN VARCHAR2 := 'YES')
RETURN CLOB;
DBMS_SPM.EVOLVE_SQL_PLAN_BASELINE (
plan_list IN DBMS_SPM.NAME_LIST,
time_limit IN INTEGER := DBMS_SPM.AUTO_LIMIT,
verify IN VARCHAR2 := 'YES',
commit IN VARCHAR2 := 'YES')
RETURN CLOB;
Evolving a Plan (2)
Demo 9
• Drop SQL Plan Baseline
– drop_plans.sql
• Capture SQL Plan Baseline with 1 accepted Plan
– demo9.sql
– list_plans.sql
• Evolve all Plans on Plan History
– evolve.sql
Enkitec (c) 2014 33
FIXED Flag
• When set to YES
– Only FIXED Plans are considered for Plan Selection
– No more Plans are Captured into Plan History
Enkitec (c) 2014 34
Alter SQL Plan Baselines
Enkitec (c) 2014 35
DBMS_SPM.ALTER_SQL_PLAN_BASELINE (
sql_handle IN VARCHAR2 := NULL,
plan_name IN VARCHAR2 := NULL,
attribute_name IN VARCHAR2,
attribute_value IN VARCHAR2)
RETURN PLS_INTEGER;
Attribute Names & Values:
enabled 'YES' or 'NO'
fixed 'YES' or 'NO'
autopurge 'YES' or 'NO'
plan_name String of up to 30-characters
description String of up to 500-characters
Plan Selection (1)
• At hard parse when SQL Plan Baseline (SPB) exists
1. CBO computes an “Optimal” Plan (OP)
• Adaptive Cursor Sharing is used if applicable
2. If OP exists in SPB then execute this OP
3. If OP does not exist in SPB then store it in Plan History
a. If there are FIXED Plans in SPB
i. Re-cost all FIXED Plans using Binds and execute cheapest
b. If there are no FIXED Plans in SPM
i. Re-cost all Plans using Binds and execute cheapest
Enkitec (c) 2014 36
Plan Selection (2)
Enkitec (c) 2014 37
Demo 10
• FIX one Plan from SQL Plan Baseline
– alter_plans.sql
• Verify only one Plan was Executed
– flush.sql
– demo8.sql
– demo8.sql
Enkitec (c) 2014 38
SPM Summary
Enkitec (c) 2014 39
• SPM provides much desired Plan Stability
– Only “approved” Plans are allowed to Execute
• ACS can generate a healthy stock of Optimal Plans
– You can restrict them to work under SPM
• Combining ACS and SPM you can obtain
– Plan Flexibility and Plan Stability
ACS Suggested Strategy
• Use sys.dbms_sqldiag_internal.i_create_patch to
SQL Patch with BIND_AWARE the SQL on Baselines
• Use free script sqlpch.sql
Enkitec (c) 2014 40
SPM Suggested Strategies
1. Conservative
– One SQL at a time
2. Moderate
– One Application at a time (Module or Action)
– One Schema at a time
3. Aggressive (a.k.a. Cowboy method)
– All Application Schemas at once
Enkitec (c) 2014 41
Oracle Pack Licenses
• DBMS_SPM
– No Oracle Pack License
• DBMS_SQLTUNE
– Oracle Tuning Pack
• AWR
– Oracle Diagnostics Pack
Enkitec (c) 2014 42
References (1)
• Random Slowdown by Jonathan Lewis
– http://jonathanlewis.wordpress.com/2013/12/23/plan-
changes/
• SQL Plan Management SPM Aware Optimizer
– https://blogs.oracle.com/optimizer/entry/sql_plan_ma
nagement_part_2_of_4_spm_aware_optimizer
Enkitec (c) 2014 43
References (2)
• Oracle® Database PL/SQL Packages and Types
Reference
– 11g Release 2 (11.2)
– Part Number E25788-04
Enkitec (c) 2014 44
Contact Information
• carlos.sierra@enkitec.com
• carlos-sierra.net
• @csierra_usa
Enkitec (c) 2014 45

More Related Content

What's hot

SQLT XPLORE: The SQLT XPLAIN hidden child
SQLT XPLORE: The SQLT XPLAIN hidden childSQLT XPLORE: The SQLT XPLAIN hidden child
SQLT XPLORE: The SQLT XPLAIN hidden childCarlos Sierra
 
Understanding my database through SQL*Plus using the free tool eDB360
Understanding my database through SQL*Plus using the free tool eDB360Understanding my database through SQL*Plus using the free tool eDB360
Understanding my database through SQL*Plus using the free tool eDB360Carlos Sierra
 
SQL Tuning Tools of the Trade
SQL Tuning Tools of the TradeSQL Tuning Tools of the Trade
SQL Tuning Tools of the TradeEnkitec
 
Understanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginnersUnderstanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginnersCarlos Sierra
 
How to find what is making your Oracle database slow
How to find what is making your Oracle database slowHow to find what is making your Oracle database slow
How to find what is making your Oracle database slowSolarWinds
 
Understanding how is that adaptive cursor sharing (acs) produces multiple opt...
Understanding how is that adaptive cursor sharing (acs) produces multiple opt...Understanding how is that adaptive cursor sharing (acs) produces multiple opt...
Understanding how is that adaptive cursor sharing (acs) produces multiple opt...Enkitec
 
Oracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsOracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsEnkitec
 
Clone Oracle Databases In Minutes Without Risk Using Enterprise Manager 13c
Clone Oracle Databases In Minutes Without Risk Using Enterprise Manager 13cClone Oracle Databases In Minutes Without Risk Using Enterprise Manager 13c
Clone Oracle Databases In Minutes Without Risk Using Enterprise Manager 13cAlfredo Krieg
 
Hitchhiker's Guide to free Oracle tuning tools
Hitchhiker's Guide to free Oracle tuning toolsHitchhiker's Guide to free Oracle tuning tools
Hitchhiker's Guide to free Oracle tuning toolsBjoern Rost
 
Oracle Performance Tuning Training | Oracle Performance Tuning
Oracle Performance Tuning Training | Oracle Performance TuningOracle Performance Tuning Training | Oracle Performance Tuning
Oracle Performance Tuning Training | Oracle Performance TuningOracleTrainings
 
Oracle SQL tuning with SQL Plan Management
Oracle SQL tuning with SQL Plan ManagementOracle SQL tuning with SQL Plan Management
Oracle SQL tuning with SQL Plan ManagementBjoern Rost
 
OOUG - Oracle Performance Tuning with AAS
OOUG - Oracle Performance Tuning with AASOOUG - Oracle Performance Tuning with AAS
OOUG - Oracle Performance Tuning with AASKyle Hailey
 
Sql tuning made easier with sqltxplain (sqlt)
Sql tuning made easier with sqltxplain (sqlt)Sql tuning made easier with sqltxplain (sqlt)
Sql tuning made easier with sqltxplain (sqlt)Enkitec
 
Think Exa!
Think Exa!Think Exa!
Think Exa!Enkitec
 
SQLT XPLORE - The SQLT XPLAIN Hidden Child
SQLT XPLORE -  The SQLT XPLAIN Hidden ChildSQLT XPLORE -  The SQLT XPLAIN Hidden Child
SQLT XPLORE - The SQLT XPLAIN Hidden ChildEnkitec
 
Hotsos 2011: Mining the AWR repository for Capacity Planning, Visualization, ...
Hotsos 2011: Mining the AWR repository for Capacity Planning, Visualization, ...Hotsos 2011: Mining the AWR repository for Capacity Planning, Visualization, ...
Hotsos 2011: Mining the AWR repository for Capacity Planning, Visualization, ...Kristofferson A
 
Awr + 12c performance tuning
Awr + 12c performance tuningAwr + 12c performance tuning
Awr + 12c performance tuningAiougVizagChapter
 
Advanced tips for making Oracle databases faster
Advanced tips for making Oracle databases fasterAdvanced tips for making Oracle databases faster
Advanced tips for making Oracle databases fasterSolarWinds
 
Awr1page - Sanity checking time instrumentation in AWR reports
Awr1page - Sanity checking time instrumentation in AWR reportsAwr1page - Sanity checking time instrumentation in AWR reports
Awr1page - Sanity checking time instrumentation in AWR reportsJohn Beresniewicz
 

What's hot (20)

SQLT XPLORE: The SQLT XPLAIN hidden child
SQLT XPLORE: The SQLT XPLAIN hidden childSQLT XPLORE: The SQLT XPLAIN hidden child
SQLT XPLORE: The SQLT XPLAIN hidden child
 
SQL Tuning 101
SQL Tuning 101SQL Tuning 101
SQL Tuning 101
 
Understanding my database through SQL*Plus using the free tool eDB360
Understanding my database through SQL*Plus using the free tool eDB360Understanding my database through SQL*Plus using the free tool eDB360
Understanding my database through SQL*Plus using the free tool eDB360
 
SQL Tuning Tools of the Trade
SQL Tuning Tools of the TradeSQL Tuning Tools of the Trade
SQL Tuning Tools of the Trade
 
Understanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginnersUnderstanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginners
 
How to find what is making your Oracle database slow
How to find what is making your Oracle database slowHow to find what is making your Oracle database slow
How to find what is making your Oracle database slow
 
Understanding how is that adaptive cursor sharing (acs) produces multiple opt...
Understanding how is that adaptive cursor sharing (acs) produces multiple opt...Understanding how is that adaptive cursor sharing (acs) produces multiple opt...
Understanding how is that adaptive cursor sharing (acs) produces multiple opt...
 
Oracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsOracle Performance Tuning Fundamentals
Oracle Performance Tuning Fundamentals
 
Clone Oracle Databases In Minutes Without Risk Using Enterprise Manager 13c
Clone Oracle Databases In Minutes Without Risk Using Enterprise Manager 13cClone Oracle Databases In Minutes Without Risk Using Enterprise Manager 13c
Clone Oracle Databases In Minutes Without Risk Using Enterprise Manager 13c
 
Hitchhiker's Guide to free Oracle tuning tools
Hitchhiker's Guide to free Oracle tuning toolsHitchhiker's Guide to free Oracle tuning tools
Hitchhiker's Guide to free Oracle tuning tools
 
Oracle Performance Tuning Training | Oracle Performance Tuning
Oracle Performance Tuning Training | Oracle Performance TuningOracle Performance Tuning Training | Oracle Performance Tuning
Oracle Performance Tuning Training | Oracle Performance Tuning
 
Oracle SQL tuning with SQL Plan Management
Oracle SQL tuning with SQL Plan ManagementOracle SQL tuning with SQL Plan Management
Oracle SQL tuning with SQL Plan Management
 
OOUG - Oracle Performance Tuning with AAS
OOUG - Oracle Performance Tuning with AASOOUG - Oracle Performance Tuning with AAS
OOUG - Oracle Performance Tuning with AAS
 
Sql tuning made easier with sqltxplain (sqlt)
Sql tuning made easier with sqltxplain (sqlt)Sql tuning made easier with sqltxplain (sqlt)
Sql tuning made easier with sqltxplain (sqlt)
 
Think Exa!
Think Exa!Think Exa!
Think Exa!
 
SQLT XPLORE - The SQLT XPLAIN Hidden Child
SQLT XPLORE -  The SQLT XPLAIN Hidden ChildSQLT XPLORE -  The SQLT XPLAIN Hidden Child
SQLT XPLORE - The SQLT XPLAIN Hidden Child
 
Hotsos 2011: Mining the AWR repository for Capacity Planning, Visualization, ...
Hotsos 2011: Mining the AWR repository for Capacity Planning, Visualization, ...Hotsos 2011: Mining the AWR repository for Capacity Planning, Visualization, ...
Hotsos 2011: Mining the AWR repository for Capacity Planning, Visualization, ...
 
Awr + 12c performance tuning
Awr + 12c performance tuningAwr + 12c performance tuning
Awr + 12c performance tuning
 
Advanced tips for making Oracle databases faster
Advanced tips for making Oracle databases fasterAdvanced tips for making Oracle databases faster
Advanced tips for making Oracle databases faster
 
Awr1page - Sanity checking time instrumentation in AWR reports
Awr1page - Sanity checking time instrumentation in AWR reportsAwr1page - Sanity checking time instrumentation in AWR reports
Awr1page - Sanity checking time instrumentation in AWR reports
 

Similar to Using SQL Plan Management (SPM) to balance Plan Flexibility and Plan Stability

Using SQL Plan Management (SPM) to Balance Plan Flexibility and Plan Stability
Using SQL Plan Management (SPM) to Balance Plan Flexibility and Plan StabilityUsing SQL Plan Management (SPM) to Balance Plan Flexibility and Plan Stability
Using SQL Plan Management (SPM) to Balance Plan Flexibility and Plan StabilityEnkitec
 
Combining ACS Flexibility with SPM Stability
Combining ACS Flexibility with SPM StabilityCombining ACS Flexibility with SPM Stability
Combining ACS Flexibility with SPM StabilityEnkitec
 
Embarcadero In Search of Plan Stability Part 1 Webinar Slides
Embarcadero In Search of Plan Stability Part 1 Webinar SlidesEmbarcadero In Search of Plan Stability Part 1 Webinar Slides
Embarcadero In Search of Plan Stability Part 1 Webinar SlidesEmbarcadero Technologies
 
Performance Stability, Tips and Tricks and Underscores
Performance Stability, Tips and Tricks and UnderscoresPerformance Stability, Tips and Tricks and Underscores
Performance Stability, Tips and Tricks and UnderscoresJitendra Singh
 
My Experience Using Oracle SQL Plan Baselines 11g/12c
My Experience Using Oracle SQL Plan Baselines 11g/12cMy Experience Using Oracle SQL Plan Baselines 11g/12c
My Experience Using Oracle SQL Plan Baselines 11g/12cNelson Calero
 
Performance Management in Oracle 12c
Performance Management in Oracle 12cPerformance Management in Oracle 12c
Performance Management in Oracle 12cAlfredo Krieg
 
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...Nelson Calero
 
Some Iceberg Basics for Beginners (CDP).pdf
Some Iceberg Basics for Beginners (CDP).pdfSome Iceberg Basics for Beginners (CDP).pdf
Some Iceberg Basics for Beginners (CDP).pdfMichael Kogan
 
D73549GC10_06.pptx
D73549GC10_06.pptxD73549GC10_06.pptx
D73549GC10_06.pptxVLQuyNhn
 
Fast federated SQL with Apache Calcite
Fast federated SQL with Apache CalciteFast federated SQL with Apache Calcite
Fast federated SQL with Apache CalciteChris Baynes
 
Meeting the challenges of OLTP Big Data with Scylla
Meeting the challenges of OLTP Big Data with ScyllaMeeting the challenges of OLTP Big Data with Scylla
Meeting the challenges of OLTP Big Data with ScyllaScyllaDB
 
Adaptive Query Optimization
Adaptive Query OptimizationAdaptive Query Optimization
Adaptive Query OptimizationAnju Garg
 
SQLServerDays2012_SSIS_CDC
SQLServerDays2012_SSIS_CDCSQLServerDays2012_SSIS_CDC
SQLServerDays2012_SSIS_CDCKoenVerbeeck
 
Macy's: Changing Engines in Mid-Flight
Macy's: Changing Engines in Mid-FlightMacy's: Changing Engines in Mid-Flight
Macy's: Changing Engines in Mid-FlightDataStax Academy
 
Oracle DB 19c: SQL Tuning Using SPM
Oracle DB 19c: SQL Tuning Using SPMOracle DB 19c: SQL Tuning Using SPM
Oracle DB 19c: SQL Tuning Using SPMArturo Aranda
 
An Approach to Sql tuning - Part 1
An Approach to Sql tuning - Part 1An Approach to Sql tuning - Part 1
An Approach to Sql tuning - Part 1Navneet Upneja
 
Optimizing applications and database performance
Optimizing applications and database performanceOptimizing applications and database performance
Optimizing applications and database performanceInam Bukhary
 
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdfNOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdfcookie1969
 

Similar to Using SQL Plan Management (SPM) to balance Plan Flexibility and Plan Stability (20)

Using SQL Plan Management (SPM) to Balance Plan Flexibility and Plan Stability
Using SQL Plan Management (SPM) to Balance Plan Flexibility and Plan StabilityUsing SQL Plan Management (SPM) to Balance Plan Flexibility and Plan Stability
Using SQL Plan Management (SPM) to Balance Plan Flexibility and Plan Stability
 
Combining ACS Flexibility with SPM Stability
Combining ACS Flexibility with SPM StabilityCombining ACS Flexibility with SPM Stability
Combining ACS Flexibility with SPM Stability
 
Embarcadero In Search of Plan Stability Part 1 Webinar Slides
Embarcadero In Search of Plan Stability Part 1 Webinar SlidesEmbarcadero In Search of Plan Stability Part 1 Webinar Slides
Embarcadero In Search of Plan Stability Part 1 Webinar Slides
 
Performance Stability, Tips and Tricks and Underscores
Performance Stability, Tips and Tricks and UnderscoresPerformance Stability, Tips and Tricks and Underscores
Performance Stability, Tips and Tricks and Underscores
 
My Experience Using Oracle SQL Plan Baselines 11g/12c
My Experience Using Oracle SQL Plan Baselines 11g/12cMy Experience Using Oracle SQL Plan Baselines 11g/12c
My Experience Using Oracle SQL Plan Baselines 11g/12c
 
Performance Management in Oracle 12c
Performance Management in Oracle 12cPerformance Management in Oracle 12c
Performance Management in Oracle 12c
 
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...
 
Some Iceberg Basics for Beginners (CDP).pdf
Some Iceberg Basics for Beginners (CDP).pdfSome Iceberg Basics for Beginners (CDP).pdf
Some Iceberg Basics for Beginners (CDP).pdf
 
D73549GC10_06.pptx
D73549GC10_06.pptxD73549GC10_06.pptx
D73549GC10_06.pptx
 
Fast federated SQL with Apache Calcite
Fast federated SQL with Apache CalciteFast federated SQL with Apache Calcite
Fast federated SQL with Apache Calcite
 
Meeting the challenges of OLTP Big Data with Scylla
Meeting the challenges of OLTP Big Data with ScyllaMeeting the challenges of OLTP Big Data with Scylla
Meeting the challenges of OLTP Big Data with Scylla
 
Adaptive Query Optimization
Adaptive Query OptimizationAdaptive Query Optimization
Adaptive Query Optimization
 
SQLServerDays2012_SSIS_CDC
SQLServerDays2012_SSIS_CDCSQLServerDays2012_SSIS_CDC
SQLServerDays2012_SSIS_CDC
 
Macy's: Changing Engines in Mid-Flight
Macy's: Changing Engines in Mid-FlightMacy's: Changing Engines in Mid-Flight
Macy's: Changing Engines in Mid-Flight
 
Oracle DB 19c: SQL Tuning Using SPM
Oracle DB 19c: SQL Tuning Using SPMOracle DB 19c: SQL Tuning Using SPM
Oracle DB 19c: SQL Tuning Using SPM
 
Oracle SQL Tuning
Oracle SQL TuningOracle SQL Tuning
Oracle SQL Tuning
 
An Approach to Sql tuning - Part 1
An Approach to Sql tuning - Part 1An Approach to Sql tuning - Part 1
An Approach to Sql tuning - Part 1
 
Optimizing applications and database performance
Optimizing applications and database performanceOptimizing applications and database performance
Optimizing applications and database performance
 
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdfNOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
 
11gR2 Upgrade.pdf
11gR2 Upgrade.pdf11gR2 Upgrade.pdf
11gR2 Upgrade.pdf
 

Recently uploaded

Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 

Recently uploaded (20)

Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 

Using SQL Plan Management (SPM) to balance Plan Flexibility and Plan Stability

  • 1. Using SQL Plan Management (SPM) to balance Plan Flexibility and Plan Stability Carlos Sierra
  • 2. Carlos Sierra • SQLTXPLAIN + SQL Health-Check SQLHC + • Consultant/Developer/DBA/Design/+ • Oracle Performance + SQL Tuning • Oracle Database Health-Check • Tools + Scripts • Speaker Enkitec (c) 2014 2
  • 3. Topics • Motivation • SQL Plan Management (SPM) – Mechanics – Demos Enkitec (c) 2014 3
  • 4. Plan Flexibility • Cost-based Optimizer (CBO) – Introduced in Oracle 7 – Computes an Optimal Plan based on • Heuristics • Query Predicates • Schema Object Statistics • Several Others Enkitec (c) 2014 4
  • 5. Flexibility: Good or Evil? • CBO Mission – Compute an Optimal Plan for a given SQL and its Data • Plans have many and complex Dependencies • CBO Performance – Successful most of the times • Produces a sub-optimal Plan sometimes Enkitec (c) 2014 5
  • 6. DBA Recurrent Nightmare • A business critical process experiences an occasional slow down – Same SQL usually runs quickly – Developers claim they haven’t changed anything – Users claim they do the same every time – Business keeps reporting this: to YOU! Enkitec (c) 2014 6
  • 7. Why Plans Perform Inconsistently? (1) • Concurrency with some other Process • State of Buffer Cache • RAC Node Affinity • CPU Starvation • Sudden Changes on Data Volume • Inconsistent Performance through Database Link Enkitec (c) 2014 7
  • 8. Why Plans Perform Inconsistently? (2) • Downgraded Parallel Execution • Crossing Small-Table Threshold • Resource Manager Directive • Plan Flips • Many Others… Enkitec (c) 2014 8
  • 9. Why a Plan Flips? (1) • Bind Variable Peeking with Histograms • Outdated Schema Object (SO) Statistics • Missing SO Statistics • Fresh SO Statistics • New Empty Partitions Enkitec (c) 2014 9
  • 10. Why a Plan Flips? (2) • Incomplete set of CBO Hints – Either on SQL Text or SQL Profile • Dropped, Invalid, Invisible or new Indexes • Index or Table rebuild • Two or more Plans with similar Cost Enkitec (c) 2014 10
  • 11. Why a Plan Flips? (3) • Database Parameters Changes • CBO System Statistics Changes • Asynchronous SO Statistics Gathering • Many Others… Enkitec (c) 2014 11
  • 12. How to Mitigate Plan Flipping? • Solid CBO Statistics • Default CBO Parameters • Avoid Global Changes Enkitec (c) 2014 12
  • 13. Plan Flexibility Allies • CBO Parameters • CBO Statistics • Dynamic Sampling • Cardinality Feedback • Cursor Sharing • Adaptive Cursor Sharing (ACS) Enkitec (c) 2014 13
  • 14. Plan Stability Tools • CBO Hints • Stored Outlines • SQL Profiles • SQL Plan Management (SPM) Enkitec (c) 2014 14
  • 15. SQL Plan Management • 11g+ • Multiple Persistent Optimal Execution Plans per SQL • Only “accepted” and “enabled” Plans are Executed • New Plans are acknowledged but not Executed • Goal: Plan Stability with controlled Flexibility Enkitec (c) 2014 15
  • 16. SQL Plan Baseline • A set of Plans available to the CBO for a given SQL – Identified by SQL Handle and Signature • Hash function on SQL Text • dbms_sqltune.sqltext_to_signature – View dba_sql_plan_baselines • enabled = YES • accepted = YES • reproduced = YES Enkitec (c) 2014 16
  • 17. Plan History • Content of dba_sql_plan_baselines • Includes SQL Plan Baseline • Includes Pending Plans – accepted = NO and last_verified is NULL • Includes Rejected Plans – accepted = NO and last_verified is not NULL • Includes Disabled Plans Enkitec (c) 2014 17
  • 18. Methods to Create a Plan Baseline 1. Capture 2. Load a. Cursor Cache (CUR) b. SQL Tuning Set (STS) c. Stored Outline 3. Migration Enkitec (c) 2014 18 1. Capture 2. Load a. CUR b. STS c. AWR d. SPA e. TRC 3. Migration
  • 19. Capturing a SQL Plan Baseline (1) • Set optimizer_use_sql_plan_baselines to TRUE (default) • Set optimizer_capture_sql_plan_baselines to TRUE (default is FALSE) – Set this parameter at SESSION level • Execute SQL 2 times • Set optimizer_capture_sql_plan_baselines to FALSE Enkitec (c) 2014 19
  • 20. Capturing a SQL Plan Baseline (2) Enkitec (c) 2014 20
  • 21. Loading SQL Plan Baseline from Cache • dbms_spm.load_plans_from_cursor_cache – Inputs • sql_id • plan_hash_value (opt) – Outputs • Number of Plans loaded Enkitec (c) 2014 21
  • 22. 22 DBMS_SPM.LOAD_PLANS_FROM_CURSOR_CACHE ( sql_id IN VARCHAR2, plan_hash_value IN NUMBER := NULL, sql_text IN CLOB, fixed IN VARCHAR2 := 'NO', enabled IN VARCHAR2 := 'YES') RETURN PLS_INTEGER; DBMS_SPM.LOAD_PLANS_FROM_CURSOR_CACHE ( sql_id IN VARCHAR2, plan_hash_value IN NUMBER := NULL, sql_handle IN VARCHAR2, fixed IN VARCHAR2 := 'NO', enabled IN VARCHAR2 := 'YES') RETURN PLS_INTEGER; DBMS_SPM.LOAD_PLANS_FROM_CURSOR_CACHE ( sql_id IN VARCHAR2, plan_hash_value IN NUMBER := NULL, fixed IN VARCHAR2 := 'NO', enabled IN VARCHAR2 := 'YES') RETURN PLS_INTEGER; DBMS_SPM.LOAD_PLANS_FROM_CURSOR_CACHE ( attribute_name IN VARCHAR2, attribute_value IN VARCHAR2, fixed IN VARCHAR2 := 'NO', enabled IN VARCHAR2 := 'YES') RETURN PLS_INTEGER; Enkitec (c) 2014 One of possible attribute names: • 'SQL_TEXT' (like) • 'PARSING_SCHEMA_NAME' (equality) • 'MODULE' (equality) • 'ACTION' (equality) SQL text to use in identifying the SQL plan baseline into which the plans are loaded. If the SQL plan baseline does not exist, it is created. The use of text is crucial when the user tunes a SQL statement by adding hints to its text and then wants to load the resulting plan(s) into the SQL plan baseline of the original SQL statement. SQL handle to use in identifying the SQL plan baseline into which the plans are loaded. The sql_handle must denote an existing SQL plan baseline. The use of handle is crucial when the user tunes a SQL statement by adding hints to its text and then wants to load the resulting plan(s) into the SQL plan baseline of the original SQL statement. Plan identifier. Default NULL means capture all plans present in the cursor cache for the SQL statement identified by SQL_ID.
  • 23. SQL Plan Baseline Loading Options • Load a Plan from a Hinted version of a SQL into SQL Baseline of Original SQL – Use SQL Text if there is no pre-existing SQL Baseline – Use SQL Handle if SQL Baseline already exists • Load one or more Cursor Plans (memory) for a SQL • Load Plans for Subset of Cursors based on Schema, SQL Text “like” or Application (Module or Action) Enkitec (c) 2014 23
  • 24. Demo 6 • Load Plans for Query out of Demo 5 – demo5.sql (1st time) – load_plans.sql • Execute Demo 5 again and review Plan History – demo5.sql (2nd time) – list_plans.sql • Execute demo5.sql 2x (3rd & 4th) and verify results Enkitec (c) 2014 24
  • 25. Demo 6 Results (after 3rd demo5.sql) CHILD EXECUTIONS BUFFER_GETS PLAN_HASH_VALUE SHAR SENS AWRE ----------- ----------- ----------- --------------- ---- ---- ---- 0 3 9090 3600618656 Y Y N CHILD BUCKET_ID COUNT ----------- ----------- ----------- 0 0 0 0 1 1 0 2 2 Note ----- - SQL plan baseline SQL_PLAN_652hmt7yxthdwc0e59472 used for this statement CREATED PLAN_NAME ENA ACC REP FIX ------------------------------ ------------------------------ --- --- --- --- 21-JUN-14 02.00.10.000000 PM SQL_PLAN_652hmt7yxthdw80508062 YES YES YES NO 21-JUN-14 02.00.10.000000 PM SQL_PLAN_652hmt7yxthdwc0e59472 YES YES YES NO 21-JUN-14 02.00.10.000000 PM SQL_PLAN_652hmt7yxthdwe00bee24 YES YES YES NO 21-JUN-14 02.00.19.000000 PM SQL_PLAN_652hmt7yxthdwc82a6b0c YES NO YES NO Enkitec (c) 2014 25
  • 26. Demo 6 Results (after 4th demo5.sql) CHILD EXECUTIONS BUFFER_GETS PLAN_HASH_VALUE SHAR SENS AWRE ----------- ----------- ----------- --------------- ---- ---- ---- 0 2 723482 847574763 N Y N 1 1 2404 3600618656 Y Y Y 2 1 1977 189372815 Y Y Y 3 1 568 847574763 Y Y Y Note ----- - SQL plan baseline SQL_PLAN_652hmt7yxthdw80508062 used for this statement CREATED PLAN_NAME ENA ACC REP FIX ------------------------------ ------------------------------ --- --- --- --- 28-DEC-13 02.03.43.000000 PM SQL_PLAN_652hmt7yxthdw501f1424 YES YES YES NO 28-DEC-13 02.03.43.000000 PM SQL_PLAN_652hmt7yxthdwb6c39290 YES YES YES NO 28-DEC-13 02.03.43.000000 PM SQL_PLAN_652hmt7yxthdwd624c0cd YES YES YES NO 28-DEC-13 02.03.50.000000 PM SQL_PLAN_652hmt7yxthdwc82a6b0c YES NO YES NO Enkitec (c) 2014 26
  • 27. Demo 7 • Drop SQL Plan Baseline – drop_plans.sql • Create SQL Patch with /*+ BIND_AWARE */ Hint – sqlpch.sql for 8u0n7w1jug5dg connected as SYS • Load Plans for Query out of Demo 5 – demo5.sql – load_plans.sql Enkitec (c) 2014 27
  • 28. Demo 7 Results CHILD EXECUTIONS BUFFER_GETS PLAN_HASH_VALUE SHAR SENS AWRE ----------- ----------- ----------- --------------- ---- ---- ---- 0 1 2191 847574763 N Y Y 1 1 3030 2048551027 Y Y Y 2 1 2404 3600618656 Y Y Y 3 1 1977 189372815 Y Y Y 4 1 568 847574763 Y Y Y CREATED PLAN_NAME ENA ACC REP FIX ------------------------------ ------------------------------ --- --- --- --- 21-JUN-14 02.09.14.000000 PM SQL_PLAN_652hmt7yxthdw80508062 YES YES YES NO 21-JUN-14 02.09.14.000000 PM SQL_PLAN_652hmt7yxthdwc0e59472 YES YES YES NO 21-JUN-14 02.09.14.000000 PM SQL_PLAN_652hmt7yxthdwc82a6b0c YES YES YES NO 21-JUN-14 02.09.14.000000 PM SQL_PLAN_652hmt7yxthdwe00bee24 YES YES YES NO Enkitec (c) 2014 28
  • 29. Demo 8 • Execute queries 1-5 and observe how number of Executions increases per Child Cursor – flush.sql – demo8.sql – demo8.sql – demo8.sql Enkitec (c) 2014 29
  • 30. Demo 8 Results CHILD EXECUTIONS BUFFER_GETS PLAN_HASH_VALUE SHAR SENS AWRE ----------- ----------- ----------- --------------- ---- ---- ---- 0 1 3030 2048551027 Y Y Y 1 1 2404 3600618656 Y Y Y 2 1 1977 189372815 Y Y Y 3 1 568 847574763 N Y Y 4 1 724 847574763 Y Y Y Note ----- - SQL patch "sqlpch_8u0n7w1jug5dg" used for this statement - SQL plan baseline SQL_PLAN_652hmt7yxthdwb6c39290 used for this statement CHILD EXECUTIONS BUFFER_GETS PLAN_HASH_VALUE SHAR SENS AWRE ----------- ----------- ----------- --------------- ---- ---- ---- 0 2 6060 2048551027 Y Y Y 1 2 4808 3600618656 Y Y Y 2 2 3954 189372815 Y Y Y 3 1 568 847574763 N Y Y 4 3 2016 847574763 Y Y Y Enkitec (c) 2014 30
  • 31. Evolving a Plan (1) • Evolving a Plan means “accepting” it – Promoting it from Plan History into SQL Plan Baseline • dbms_spm.evolve_sql_plan_baseline – sql_handle (opt) – plan_name (opt) – verify (default YES) – commit (default YES) Enkitec (c) 2014 31
  • 32. Enkitec (c) 2014 32 DBMS_SPM.EVOLVE_SQL_PLAN_BASELINE ( sql_handle IN VARCHAR2 := NULL, plan_name IN VARCHAR2 := NULL, time_limit IN INTEGER := DBMS_SPM.AUTO_LIMIT, verify IN VARCHAR2 := 'YES', commit IN VARCHAR2 := 'YES') RETURN CLOB; DBMS_SPM.EVOLVE_SQL_PLAN_BASELINE ( plan_list IN DBMS_SPM.NAME_LIST, time_limit IN INTEGER := DBMS_SPM.AUTO_LIMIT, verify IN VARCHAR2 := 'YES', commit IN VARCHAR2 := 'YES') RETURN CLOB; Evolving a Plan (2)
  • 33. Demo 9 • Drop SQL Plan Baseline – drop_plans.sql • Capture SQL Plan Baseline with 1 accepted Plan – demo9.sql – list_plans.sql • Evolve all Plans on Plan History – evolve.sql Enkitec (c) 2014 33
  • 34. FIXED Flag • When set to YES – Only FIXED Plans are considered for Plan Selection – No more Plans are Captured into Plan History Enkitec (c) 2014 34
  • 35. Alter SQL Plan Baselines Enkitec (c) 2014 35 DBMS_SPM.ALTER_SQL_PLAN_BASELINE ( sql_handle IN VARCHAR2 := NULL, plan_name IN VARCHAR2 := NULL, attribute_name IN VARCHAR2, attribute_value IN VARCHAR2) RETURN PLS_INTEGER; Attribute Names & Values: enabled 'YES' or 'NO' fixed 'YES' or 'NO' autopurge 'YES' or 'NO' plan_name String of up to 30-characters description String of up to 500-characters
  • 36. Plan Selection (1) • At hard parse when SQL Plan Baseline (SPB) exists 1. CBO computes an “Optimal” Plan (OP) • Adaptive Cursor Sharing is used if applicable 2. If OP exists in SPB then execute this OP 3. If OP does not exist in SPB then store it in Plan History a. If there are FIXED Plans in SPB i. Re-cost all FIXED Plans using Binds and execute cheapest b. If there are no FIXED Plans in SPM i. Re-cost all Plans using Binds and execute cheapest Enkitec (c) 2014 36
  • 38. Demo 10 • FIX one Plan from SQL Plan Baseline – alter_plans.sql • Verify only one Plan was Executed – flush.sql – demo8.sql – demo8.sql Enkitec (c) 2014 38
  • 39. SPM Summary Enkitec (c) 2014 39 • SPM provides much desired Plan Stability – Only “approved” Plans are allowed to Execute • ACS can generate a healthy stock of Optimal Plans – You can restrict them to work under SPM • Combining ACS and SPM you can obtain – Plan Flexibility and Plan Stability
  • 40. ACS Suggested Strategy • Use sys.dbms_sqldiag_internal.i_create_patch to SQL Patch with BIND_AWARE the SQL on Baselines • Use free script sqlpch.sql Enkitec (c) 2014 40
  • 41. SPM Suggested Strategies 1. Conservative – One SQL at a time 2. Moderate – One Application at a time (Module or Action) – One Schema at a time 3. Aggressive (a.k.a. Cowboy method) – All Application Schemas at once Enkitec (c) 2014 41
  • 42. Oracle Pack Licenses • DBMS_SPM – No Oracle Pack License • DBMS_SQLTUNE – Oracle Tuning Pack • AWR – Oracle Diagnostics Pack Enkitec (c) 2014 42
  • 43. References (1) • Random Slowdown by Jonathan Lewis – http://jonathanlewis.wordpress.com/2013/12/23/plan- changes/ • SQL Plan Management SPM Aware Optimizer – https://blogs.oracle.com/optimizer/entry/sql_plan_ma nagement_part_2_of_4_spm_aware_optimizer Enkitec (c) 2014 43
  • 44. References (2) • Oracle® Database PL/SQL Packages and Types Reference – 11g Release 2 (11.2) – Part Number E25788-04 Enkitec (c) 2014 44
  • 45. Contact Information • carlos.sierra@enkitec.com • carlos-sierra.net • @csierra_usa Enkitec (c) 2014 45