SlideShare a Scribd company logo
1 of 48
Adapting and adopting
SQL Plan Management
to achieve execution plan stability for sub-second queries on a high-rate
OLTP mission-critical application
Carlos Sierra
Wide spikes are
usually the
signature of a “plan
flip”
A “plan flip” on one
SQL statement
caused wide spikes
One SQL statement
with 3 distinct
Execution Plans
Plans flip frequently
for this SQL
statement
Multiple plans co-exist
Another SQL
statement with
multiple overlapping
Execution Plans
Motivation
• Plan stability is more valuable than plan flexibility when
• Strict SLAs in the order of milliseconds
• Simple queries execute dozens of times per second
• Out-of-the-box “Automatic SPM Evolve Task” is great … but
• It may accept sub-optimal execution plans on a non-typical application
• e.g.: binds captured could be outdated in a matter of hours
• Historical plan performance could be used to determine future SQL
performance with some degree of confidence
• We just need to implement an autonomous custom algorithm …
About the application and environment
• Oracle 12c multi-tenant on Oracle Servers X5-2 with NVMe SSD
• OLTP application with copies in 30+ databases and 700+ PDBs
• Row by row web-based custom application
• Transaction isolation implemented through application-enforced
serialization
• Few critical queries encapsulated as “critical serial-path transaction”
• Typical transaction executes in ~10ms including up to 10 queries
• A “plan-flip” constantly risks breaching stringent milliseconds SLAs
A typical query
SELECT …
FROM SYSTEMS
WHERE (id, TxnID, 1) IN ( SELECT id, TxnID,
ROW_NUMBER() OVER ( PARTITION BY id ORDER BY
TxnID DESC ) rn
FROM SYSTEMS WHERE TxnID <= :1 )
AND Live = 'Y'
AND ((compartmentId = :2))
ORDER BY compartmentId ASC, id ASC
FETCH FIRST :3 ROWS ONLY
A typical execution plan
A typical performance scorecard
Adaptive SQL Plan Management on 12c
• Refer to this link for details
https://oracle-base.com/articles/12c/adaptive-sql-plan-management-12cr1
• Evolution of SPBs is “on” by default
• View dba_advisor_parameters
• Filter task_name = ‘SYS_AUTO_SPM_EVOLVE_TASK’
• Columns parameter_name and parameter_value
• Look for ACCEPT_PLANS parameter
• Last evolution: DBMS_SPM.report_auto_evolve_task
• Creation of SPB is “off” by default
Automatic SPM Evolve Task
Plan is evaluated using variable
values captured at the time the
test plan is created.
The “evolve task” determines
the base plan performs poorly
when executed passing
outdated values.
This application has a fast
moving time window.
Custom SPM Implementation Objectives
• Reduce the number of incidents where the execution of a new plan
causes a performance regression of an SLA related SQL statement
• Create a SQL Plan Baseline (SPB) a.k.a. “pin a plan” when such a plan
has a proven record of consistent good performance (i.e. learn from
history or lack of history)
• Ignore SQL statements that are too young
• If a SQL statement changes, then re-learn from history and “pin a
plan” once it becomes mature again
• Flag a plan as permanent once its SPB has also matured
• Clean up unwanted plans
FPZ Algorithm
• Pre-select SQL_ID/PHV candidates, mainly from shared pool
• If there exists a valid SQL Plan Baseline (SPB) for candidate
• Demote SPB if underperforms (disable it)
• Promote SPB after proven performance (fix it)
• Else (no SPB exists for candidate)
• Further screen candidate
• Create SPB if candidate is accepted
• Log decision
FPZ Algorithm
Pre-select SQL_ID/PHV candidates
• For PHV, at least one child cursor is valid, shareable and not obsolete
• Parent cursor’s first load time is > 6 days
• SQL (parent cursor) is mature
• Cursor has been active within the last 24 hours
• Parsing user and schema is not SYS nor Oracle managed
• PDB is not CDB$ROOT or PDB$SEED
• PHV and Executions are > 0
• Some others
Consider Plan candidates from AWR, only if
1. Plan is not on Shared Pool
• Plan was generated in the past (AWR) but not currently in memory
2. There are other Plans for SQL on Shared Pool (with no SPB)
• SQL is active and has no SPB
3. Focus is on one SQL and not entire PDB or CDB
• Algorithm skips AWR plans which are candidates from Shared Pool
(because AWR does not store SPB name on SQLSTAT)
Note: not having SPB name on AWR SQLSTAT would cause algorithm to re-
create SPB on every execution
What is a valid SQL Plan Baseline (SPB)?
• Accepted
• Enabled
• Reproduced
• Not necessary Fixed
Disable SPB if underperforms
• Cursor’s average elapsed time per execution > 10x category’s
threshold
• Cursor’s average elapsed time per execution > 100x SPB average
elapsed time per execution
• Evaluate after N executions (as per candidate threshold)
SPB demotion to “DISABLE”
Cursor Cache
Plans with
SPB
SPBs that qualify for a
“DISABLE” demotion
Enabled
Accepted
Reproduced
Not Fixed
Avg ET > 10x Max Category Threshold
Avg ET > 100x SPB snapshot
SPB evaluation and conditional promotion
• If not “fixed” and “created” > 14 days
• Set “FIX” flag to YES
• Plan is mature, in use and with acceptable performance
• Note: after “fixed” no new plans are created into Plan History
SPB promotion to “FIX”
Cursor Cache
Plans with
SPB
SPBs that qualify for a
“FIX” promotion
Enabled
Accepted
Reproduced
Not Fixed
Age > 14d
Further screen SQL_ID/PHV candidates
• Plan has > “X” executions
• > 10,000 for some categories
• > 1,000 for other categories
• Hint: Start SPM Automation with high-rate SQL only
• Plan’s average execution time is < “X”ms
• < 0.5ms for some categories
• < 10ms for other categories
• Proven acceptable “on average” performance based on cumulative metrics
• Or lack of historical metrics which usually denote a light-weight SQL
SPB creation
Cursor Cache and
AWR SQLSTAT
Plan candidates
for SPB
Plans that qualify
for a SPB
Executions > 2,500
Elapsed Time per Execution < 10s
Age > 4d
Executions > 25,000
Elapsed Time per Execution < 1.25ms
Age > 6d
Categorizing SQL statements
• Use Module and Action, and/or parse SQL text
• Critical transaction (e.g.)
• Commit path
• Begin transaction
• Garbage collection
• Non-critical transaction (e.g.)
• Scan read
• Something else (i.e.)
• Categorize as non-application and possibly reject candidate
Further screen SQL_ID/PHV candidates (cont.)
• Plan has no AWR performance history (low database load); or
• Plan has AWR recent performance history (60 days) such as
• Execution time’s 90th Percentile < 2x cursor’s category and < 20x cursor’s avg
• e.g. < 2.5ms and < 20x avg
• Execution time’s 95th Percentile < 3x cursor’s category and < 30x cursor’s avg
• e.g. < 3.75ms and < 30x avg
• Execution time’s 97th Percentile < 4x cursor’s category and < 40x cursor’s avg
• e.g. < 5ms and < 40x avg
• Execution time’s 99th Percentile < 5x cursor’s category and < 50x cursor’s avg
• e.g. < 6.25ms and < 50x avg
Algorithm’s aggressiveness style - sample
Level Meaning > Executions < Elapsed Time (ms)
1 Conservative 25,000 0.25
2 20,000 0.50
3 Moderate 15,000 0.75
4 10,000 1.00
5 Aggressive 5,000 1.25
Lvl > Execs < ET (ms) Avg < ET (ms) 90th Pctl < ET (ms) 95th Pctl < ET (ms) 97th Pctl < ET (ms) 99th Pctl
1 25,000 0.25 0.50 0.75 1.00 1.25
2 20,000 0.50 1.00 1.50 2.00 2.50
3 15,000 0.75 1.50 2.25 3.00 3.75
4 10,000 1.00 2.00 3.00 4.00 5.00
5 5,000 1.25 2.50 3.75 5.00 6.25
Begin Tx Category
Implementation
Sample category thresholds implementation
Category > Executions
Conservative
> Executions
Moderate
> Executions
Aggressive
< ET (ms)
Conservative
< ET (ms)
Moderate
< ET (ms)
Aggressive
CommitTx 25,000 15,000 5,000 0.5 1.5 2.5
BeginTx 25,000 15,000 5,000 0.25 0.75 1.25
Read 5,000 3,000 1,000 10 30 50
GC 5,000 3,000 1,000 1,000 3,000 5,000
Other 5,000 3,000 1,000 200 600 1,000
Create SQL Plan Baseline (SPB)
• Enabled
• Accepted
• But not “Fixed”
• Source most from Cursor Cache, and some from AWR
Log decision
• Update SPB “description”
• Source SQL_ID
• Source plan hash value (PHV)
• Date when promoted to “Fixed” or demoted from “Fixed”
• Write into log
• Created SPB with selection metrics such as execution percentiles
• Promoted and demoted SPBs, with criteria used
• Rejected candidates and reason
• Preserve logs for at least 1 month
FPZ Algorithm (recap)
• Pre-select SQL_ID/PHV candidates, mainly from shared pool
• If there exists a valid SQL Plan Baseline (SPB) for candidate
• Demote SPB if underperforms (disable it)
• Promote SPB after proven performance (fix it)
• Else (no SPB exists for candidate)
• Further screen candidate
• Create SPB if candidate is accepted
• Log decision
AWR Configuration
• EXEC DBMS_SPM.CONFIGURE('plan_retention_weeks', 13);
• EXEC DBMS_WORKLOAD_REPOSITORY.MODIFY_SNAPSHOT_SETTINGS(topnsql=>300);
• ALTER SYSTEM SET "_awr_sql_child_limit" = 2000;
Additional considerations
• Set Autopurge to NO for Plans on black-list
• Manually (out of scope for automation)
• What if there is no “proven consistent performance”?
• What if average performance is higher than target threshold?
• What if predicates selectivity requires more than one execution plan?
• What if SQL produces different plans across databases?
FPZ Algorithm Automation
• PL/SQL package
• Can be executed from SQL*Plus or OEM calling a PL/SQL library
• Executed connecting as CDB$ROOT
• Set of configuration constants
• How many SPB to create and how many promote? (or report only)
• Report rejected candidates and non-promoted SPBs?
• Evaluate particular application categories
• Number of executions to consider a candidate, or to qualify for a SPB
• Time per execution to qualify a candidate for SPM
• Factors over average elapsed time for 90th, 95th, 97th and 99th percentiles
• Days of AWR history to consider
Dry run results and sample output
+------------------------------------------------------------
|
| Candidates : 2019
| SPBs Qualified for Creation : 977
| SPBs Qualified for Promotion : 4
| SPBs Created : 0
| SPBs Promoted : 0
| Date and Time (end) : 2017-10-22T14:33:42
| Duration (secs) : 102
|
+------------------------------------------------------------
Implementation results
Implementation results
Implementation results
Outlier sample
Outliers
• SQL not considered by PL/SQL library
• Candidates rejected for valid reasons (performance, executions, age, etc.)
• Bug on Algorithm or PL/SQL library?
• Algorithm too restrictive?
• Short-lived small spikes
• Executions burst combined with frequent hard-parses due to CBO statistics
gathering
• SQL has multiple optimal plans as per Adaptive Cursor Sharing (ACS)
• Algorithm implements a subset
Closing remarks
• Past performance may not be indicative of future results
• Nevertheless: historical plan performance can be used to determine future SQL
performance with some degree of confidence
• Not every SQL statement gets a SPB
• Some queries are still at risk of spikes
• Lower rate of executions, performance above thresholds, new SQL, etc.
• And not every plan becomes a SPB (think ACS)
• Method presented reduces frequency of “plan flips”
• Consistent latency is more important than best performance

More Related Content

What's hot

Online index rebuild automation
Online index rebuild automationOnline index rebuild automation
Online index rebuild automationCarlos Sierra
 
How a Developer can Troubleshoot a SQL performing poorly on a Production DB
How a Developer can Troubleshoot a SQL performing poorly on a Production DBHow a Developer can Troubleshoot a SQL performing poorly on a Production DB
How a Developer can Troubleshoot a SQL performing poorly on a Production DBCarlos Sierra
 
Oracle Performance Tools of the Trade
Oracle Performance Tools of the TradeOracle Performance Tools of the Trade
Oracle Performance Tools of the TradeCarlos Sierra
 
Ash architecture and advanced usage rmoug2014
Ash architecture and advanced usage rmoug2014Ash architecture and advanced usage rmoug2014
Ash architecture and advanced usage rmoug2014John Beresniewicz
 
Tanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools shortTanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools shortTanel Poder
 
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAsOracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAsZohar Elkayam
 
Same plan different performance
Same plan different performanceSame plan different performance
Same plan different performanceMauro Pagano
 
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2Tanel Poder
 
Chasing the optimizer
Chasing the optimizerChasing the optimizer
Chasing the optimizerMauro Pagano
 
Troubleshooting Complex Performance issues - Oracle SEG$ contention
Troubleshooting Complex Performance issues - Oracle SEG$ contentionTroubleshooting Complex Performance issues - Oracle SEG$ contention
Troubleshooting Complex Performance issues - Oracle SEG$ contentionTanel Poder
 
Ash masters : advanced ash analytics on Oracle
Ash masters : advanced ash analytics on Oracle Ash masters : advanced ash analytics on Oracle
Ash masters : advanced ash analytics on Oracle Kyle Hailey
 
Tanel Poder - Performance stories from Exadata Migrations
Tanel Poder - Performance stories from Exadata MigrationsTanel Poder - Performance stories from Exadata Migrations
Tanel Poder - Performance stories from Exadata MigrationsTanel Poder
 
Your tuning arsenal: AWR, ADDM, ASH, Metrics and Advisors
Your tuning arsenal: AWR, ADDM, ASH, Metrics and AdvisorsYour tuning arsenal: AWR, ADDM, ASH, Metrics and Advisors
Your tuning arsenal: AWR, ADDM, ASH, Metrics and AdvisorsJohn Kanagaraj
 
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...Aaron Shilo
 
Understanding oracle rac internals part 2 - slides
Understanding oracle rac internals   part 2 - slidesUnderstanding oracle rac internals   part 2 - slides
Understanding oracle rac internals part 2 - slidesMohamed Farouk
 
Troubleshooting Complex Oracle Performance Problems with Tanel Poder
Troubleshooting Complex Oracle Performance Problems with Tanel PoderTroubleshooting Complex Oracle Performance Problems with Tanel Poder
Troubleshooting Complex Oracle Performance Problems with Tanel PoderTanel Poder
 
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
 
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 1
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 1Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 1
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 1Tanel Poder
 
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentalsDB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentalsJohn Beresniewicz
 

What's hot (20)

Online index rebuild automation
Online index rebuild automationOnline index rebuild automation
Online index rebuild automation
 
How a Developer can Troubleshoot a SQL performing poorly on a Production DB
How a Developer can Troubleshoot a SQL performing poorly on a Production DBHow a Developer can Troubleshoot a SQL performing poorly on a Production DB
How a Developer can Troubleshoot a SQL performing poorly on a Production DB
 
Oracle Performance Tools of the Trade
Oracle Performance Tools of the TradeOracle Performance Tools of the Trade
Oracle Performance Tools of the Trade
 
Ash architecture and advanced usage rmoug2014
Ash architecture and advanced usage rmoug2014Ash architecture and advanced usage rmoug2014
Ash architecture and advanced usage rmoug2014
 
Tanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools shortTanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools short
 
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAsOracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
 
Same plan different performance
Same plan different performanceSame plan different performance
Same plan different performance
 
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2
 
Chasing the optimizer
Chasing the optimizerChasing the optimizer
Chasing the optimizer
 
Troubleshooting Complex Performance issues - Oracle SEG$ contention
Troubleshooting Complex Performance issues - Oracle SEG$ contentionTroubleshooting Complex Performance issues - Oracle SEG$ contention
Troubleshooting Complex Performance issues - Oracle SEG$ contention
 
Ash masters : advanced ash analytics on Oracle
Ash masters : advanced ash analytics on Oracle Ash masters : advanced ash analytics on Oracle
Ash masters : advanced ash analytics on Oracle
 
Tanel Poder - Performance stories from Exadata Migrations
Tanel Poder - Performance stories from Exadata MigrationsTanel Poder - Performance stories from Exadata Migrations
Tanel Poder - Performance stories from Exadata Migrations
 
Your tuning arsenal: AWR, ADDM, ASH, Metrics and Advisors
Your tuning arsenal: AWR, ADDM, ASH, Metrics and AdvisorsYour tuning arsenal: AWR, ADDM, ASH, Metrics and Advisors
Your tuning arsenal: AWR, ADDM, ASH, Metrics and Advisors
 
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
 
SQLd360
SQLd360SQLd360
SQLd360
 
Understanding oracle rac internals part 2 - slides
Understanding oracle rac internals   part 2 - slidesUnderstanding oracle rac internals   part 2 - slides
Understanding oracle rac internals part 2 - slides
 
Troubleshooting Complex Oracle Performance Problems with Tanel Poder
Troubleshooting Complex Oracle Performance Problems with Tanel PoderTroubleshooting Complex Oracle Performance Problems with Tanel Poder
Troubleshooting Complex Oracle Performance Problems with Tanel Poder
 
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
 
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 1
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 1Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 1
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 1
 
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentalsDB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
 

Similar to Adapting and adopting spm v04

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
 
OUG Harmony 2012 - Using SQL Plan Baselines for Performance Testing
OUG Harmony 2012 -  Using SQL Plan Baselines for Performance TestingOUG Harmony 2012 -  Using SQL Plan Baselines for Performance Testing
OUG Harmony 2012 - Using SQL Plan Baselines for Performance TestingMaris Elsins
 
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
 
Oracle SQL, PL/SQL Performance tuning
Oracle SQL, PL/SQL Performance tuningOracle SQL, PL/SQL Performance tuning
Oracle SQL, PL/SQL Performance tuningSmitha Padmanabhan
 
DB12c: All You Need to Know About the Resource Manager
DB12c: All You Need to Know About the Resource ManagerDB12c: All You Need to Know About the Resource Manager
DB12c: All You Need to Know About the Resource ManagerAndrejs Vorobjovs
 
Database Fundamental Concepts- Series 1 - Performance Analysis
Database Fundamental Concepts- Series 1 - Performance AnalysisDatabase Fundamental Concepts- Series 1 - Performance Analysis
Database Fundamental Concepts- Series 1 - Performance AnalysisDAGEOP LTD
 
DB12c: All You Need to Know About the Resource Manager
DB12c: All You Need to Know About the Resource ManagerDB12c: All You Need to Know About the Resource Manager
DB12c: All You Need to Know About the Resource ManagerMaris Elsins
 
Configuring Sage 500 for Performance
Configuring Sage 500 for PerformanceConfiguring Sage 500 for Performance
Configuring Sage 500 for PerformanceRKLeSolutions
 
제3회난공불락 오픈소스 인프라세미나 - MySQL Performance
제3회난공불락 오픈소스 인프라세미나 - MySQL Performance제3회난공불락 오픈소스 인프라세미나 - MySQL Performance
제3회난공불락 오픈소스 인프라세미나 - MySQL PerformanceTommy Lee
 
ebs-performance-tuning-part-1-470542.pdf
ebs-performance-tuning-part-1-470542.pdfebs-performance-tuning-part-1-470542.pdf
ebs-performance-tuning-part-1-470542.pdfElboulmaniMohamed
 
261197832 8-performance-tuning-part i
261197832 8-performance-tuning-part i261197832 8-performance-tuning-part i
261197832 8-performance-tuning-part iNaviSoft
 
collab2011-tuning-ebusiness-421966.pdf
collab2011-tuning-ebusiness-421966.pdfcollab2011-tuning-ebusiness-421966.pdf
collab2011-tuning-ebusiness-421966.pdfElboulmaniMohamed
 
Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cRonald Francisco Vargas Quesada
 
Modernizing your database with SQL Server 2019
Modernizing your database with SQL Server 2019Modernizing your database with SQL Server 2019
Modernizing your database with SQL Server 2019Antonios Chatzipavlis
 
Apache Kylin: OLAP Engine on Hadoop - Tech Deep Dive
Apache Kylin: OLAP Engine on Hadoop - Tech Deep DiveApache Kylin: OLAP Engine on Hadoop - Tech Deep Dive
Apache Kylin: OLAP Engine on Hadoop - Tech Deep DiveXu Jiang
 
Collaborate 2011-tuning-ebusiness-416502
Collaborate 2011-tuning-ebusiness-416502Collaborate 2011-tuning-ebusiness-416502
Collaborate 2011-tuning-ebusiness-416502kaziul Islam Bulbul
 
Performance Management in Oracle 12c
Performance Management in Oracle 12cPerformance Management in Oracle 12c
Performance Management in Oracle 12cAlfredo Krieg
 

Similar to Adapting and adopting spm v04 (20)

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
 
sqltuning101-170419021007-2.pdf
sqltuning101-170419021007-2.pdfsqltuning101-170419021007-2.pdf
sqltuning101-170419021007-2.pdf
 
OUG Harmony 2012 - Using SQL Plan Baselines for Performance Testing
OUG Harmony 2012 -  Using SQL Plan Baselines for Performance TestingOUG Harmony 2012 -  Using SQL Plan Baselines for Performance Testing
OUG Harmony 2012 - Using SQL Plan Baselines for Performance Testing
 
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
 
SQLDay2013_MarcinSzeliga_StoredProcedures
SQLDay2013_MarcinSzeliga_StoredProceduresSQLDay2013_MarcinSzeliga_StoredProcedures
SQLDay2013_MarcinSzeliga_StoredProcedures
 
Oracle SQL, PL/SQL Performance tuning
Oracle SQL, PL/SQL Performance tuningOracle SQL, PL/SQL Performance tuning
Oracle SQL, PL/SQL Performance tuning
 
DB12c: All You Need to Know About the Resource Manager
DB12c: All You Need to Know About the Resource ManagerDB12c: All You Need to Know About the Resource Manager
DB12c: All You Need to Know About the Resource Manager
 
Database Fundamental Concepts- Series 1 - Performance Analysis
Database Fundamental Concepts- Series 1 - Performance AnalysisDatabase Fundamental Concepts- Series 1 - Performance Analysis
Database Fundamental Concepts- Series 1 - Performance Analysis
 
DB12c: All You Need to Know About the Resource Manager
DB12c: All You Need to Know About the Resource ManagerDB12c: All You Need to Know About the Resource Manager
DB12c: All You Need to Know About the Resource Manager
 
Configuring Sage 500 for Performance
Configuring Sage 500 for PerformanceConfiguring Sage 500 for Performance
Configuring Sage 500 for Performance
 
제3회난공불락 오픈소스 인프라세미나 - MySQL Performance
제3회난공불락 오픈소스 인프라세미나 - MySQL Performance제3회난공불락 오픈소스 인프라세미나 - MySQL Performance
제3회난공불락 오픈소스 인프라세미나 - MySQL Performance
 
ebs-performance-tuning-part-1-470542.pdf
ebs-performance-tuning-part-1-470542.pdfebs-performance-tuning-part-1-470542.pdf
ebs-performance-tuning-part-1-470542.pdf
 
261197832 8-performance-tuning-part i
261197832 8-performance-tuning-part i261197832 8-performance-tuning-part i
261197832 8-performance-tuning-part i
 
collab2011-tuning-ebusiness-421966.pdf
collab2011-tuning-ebusiness-421966.pdfcollab2011-tuning-ebusiness-421966.pdf
collab2011-tuning-ebusiness-421966.pdf
 
Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12c
 
Modernizing your database with SQL Server 2019
Modernizing your database with SQL Server 2019Modernizing your database with SQL Server 2019
Modernizing your database with SQL Server 2019
 
Apache Kylin: OLAP Engine on Hadoop - Tech Deep Dive
Apache Kylin: OLAP Engine on Hadoop - Tech Deep DiveApache Kylin: OLAP Engine on Hadoop - Tech Deep Dive
Apache Kylin: OLAP Engine on Hadoop - Tech Deep Dive
 
Collaborate 2011-tuning-ebusiness-416502
Collaborate 2011-tuning-ebusiness-416502Collaborate 2011-tuning-ebusiness-416502
Collaborate 2011-tuning-ebusiness-416502
 
Performance Management in Oracle 12c
Performance Management in Oracle 12cPerformance Management in Oracle 12c
Performance Management in Oracle 12c
 

More from Carlos Sierra

Oracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsOracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsCarlos Sierra
 
Introducing the eDB360 Tool
Introducing the eDB360 ToolIntroducing the eDB360 Tool
Introducing the eDB360 ToolCarlos Sierra
 
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...Carlos Sierra
 
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 StabilityCarlos Sierra
 
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)Carlos Sierra
 
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
 

More from Carlos Sierra (6)

Oracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsOracle Performance Tuning Fundamentals
Oracle Performance Tuning Fundamentals
 
Introducing the eDB360 Tool
Introducing the eDB360 ToolIntroducing the eDB360 Tool
Introducing the eDB360 Tool
 
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...
 
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
 
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)
 
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
 

Recently uploaded

Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 

Adapting and adopting spm v04

  • 1. Adapting and adopting SQL Plan Management to achieve execution plan stability for sub-second queries on a high-rate OLTP mission-critical application Carlos Sierra
  • 2. Wide spikes are usually the signature of a “plan flip”
  • 3. A “plan flip” on one SQL statement caused wide spikes
  • 4. One SQL statement with 3 distinct Execution Plans
  • 5. Plans flip frequently for this SQL statement
  • 6. Multiple plans co-exist Another SQL statement with multiple overlapping Execution Plans
  • 7. Motivation • Plan stability is more valuable than plan flexibility when • Strict SLAs in the order of milliseconds • Simple queries execute dozens of times per second • Out-of-the-box “Automatic SPM Evolve Task” is great … but • It may accept sub-optimal execution plans on a non-typical application • e.g.: binds captured could be outdated in a matter of hours • Historical plan performance could be used to determine future SQL performance with some degree of confidence • We just need to implement an autonomous custom algorithm …
  • 8. About the application and environment • Oracle 12c multi-tenant on Oracle Servers X5-2 with NVMe SSD • OLTP application with copies in 30+ databases and 700+ PDBs • Row by row web-based custom application • Transaction isolation implemented through application-enforced serialization • Few critical queries encapsulated as “critical serial-path transaction” • Typical transaction executes in ~10ms including up to 10 queries • A “plan-flip” constantly risks breaching stringent milliseconds SLAs
  • 9. A typical query SELECT … FROM SYSTEMS WHERE (id, TxnID, 1) IN ( SELECT id, TxnID, ROW_NUMBER() OVER ( PARTITION BY id ORDER BY TxnID DESC ) rn FROM SYSTEMS WHERE TxnID <= :1 ) AND Live = 'Y' AND ((compartmentId = :2)) ORDER BY compartmentId ASC, id ASC FETCH FIRST :3 ROWS ONLY
  • 12. Adaptive SQL Plan Management on 12c • Refer to this link for details https://oracle-base.com/articles/12c/adaptive-sql-plan-management-12cr1 • Evolution of SPBs is “on” by default • View dba_advisor_parameters • Filter task_name = ‘SYS_AUTO_SPM_EVOLVE_TASK’ • Columns parameter_name and parameter_value • Look for ACCEPT_PLANS parameter • Last evolution: DBMS_SPM.report_auto_evolve_task • Creation of SPB is “off” by default
  • 13. Automatic SPM Evolve Task Plan is evaluated using variable values captured at the time the test plan is created. The “evolve task” determines the base plan performs poorly when executed passing outdated values. This application has a fast moving time window.
  • 14. Custom SPM Implementation Objectives • Reduce the number of incidents where the execution of a new plan causes a performance regression of an SLA related SQL statement • Create a SQL Plan Baseline (SPB) a.k.a. “pin a plan” when such a plan has a proven record of consistent good performance (i.e. learn from history or lack of history) • Ignore SQL statements that are too young • If a SQL statement changes, then re-learn from history and “pin a plan” once it becomes mature again • Flag a plan as permanent once its SPB has also matured • Clean up unwanted plans
  • 15. FPZ Algorithm • Pre-select SQL_ID/PHV candidates, mainly from shared pool • If there exists a valid SQL Plan Baseline (SPB) for candidate • Demote SPB if underperforms (disable it) • Promote SPB after proven performance (fix it) • Else (no SPB exists for candidate) • Further screen candidate • Create SPB if candidate is accepted • Log decision
  • 17. Pre-select SQL_ID/PHV candidates • For PHV, at least one child cursor is valid, shareable and not obsolete • Parent cursor’s first load time is > 6 days • SQL (parent cursor) is mature • Cursor has been active within the last 24 hours • Parsing user and schema is not SYS nor Oracle managed • PDB is not CDB$ROOT or PDB$SEED • PHV and Executions are > 0 • Some others
  • 18. Consider Plan candidates from AWR, only if 1. Plan is not on Shared Pool • Plan was generated in the past (AWR) but not currently in memory 2. There are other Plans for SQL on Shared Pool (with no SPB) • SQL is active and has no SPB 3. Focus is on one SQL and not entire PDB or CDB • Algorithm skips AWR plans which are candidates from Shared Pool (because AWR does not store SPB name on SQLSTAT) Note: not having SPB name on AWR SQLSTAT would cause algorithm to re- create SPB on every execution
  • 19. What is a valid SQL Plan Baseline (SPB)? • Accepted • Enabled • Reproduced • Not necessary Fixed
  • 20. Disable SPB if underperforms • Cursor’s average elapsed time per execution > 10x category’s threshold • Cursor’s average elapsed time per execution > 100x SPB average elapsed time per execution • Evaluate after N executions (as per candidate threshold)
  • 21. SPB demotion to “DISABLE” Cursor Cache Plans with SPB SPBs that qualify for a “DISABLE” demotion Enabled Accepted Reproduced Not Fixed Avg ET > 10x Max Category Threshold Avg ET > 100x SPB snapshot
  • 22. SPB evaluation and conditional promotion • If not “fixed” and “created” > 14 days • Set “FIX” flag to YES • Plan is mature, in use and with acceptable performance • Note: after “fixed” no new plans are created into Plan History
  • 23. SPB promotion to “FIX” Cursor Cache Plans with SPB SPBs that qualify for a “FIX” promotion Enabled Accepted Reproduced Not Fixed Age > 14d
  • 24. Further screen SQL_ID/PHV candidates • Plan has > “X” executions • > 10,000 for some categories • > 1,000 for other categories • Hint: Start SPM Automation with high-rate SQL only • Plan’s average execution time is < “X”ms • < 0.5ms for some categories • < 10ms for other categories • Proven acceptable “on average” performance based on cumulative metrics • Or lack of historical metrics which usually denote a light-weight SQL
  • 25. SPB creation Cursor Cache and AWR SQLSTAT Plan candidates for SPB Plans that qualify for a SPB Executions > 2,500 Elapsed Time per Execution < 10s Age > 4d Executions > 25,000 Elapsed Time per Execution < 1.25ms Age > 6d
  • 26. Categorizing SQL statements • Use Module and Action, and/or parse SQL text • Critical transaction (e.g.) • Commit path • Begin transaction • Garbage collection • Non-critical transaction (e.g.) • Scan read • Something else (i.e.) • Categorize as non-application and possibly reject candidate
  • 27.
  • 28. Further screen SQL_ID/PHV candidates (cont.) • Plan has no AWR performance history (low database load); or • Plan has AWR recent performance history (60 days) such as • Execution time’s 90th Percentile < 2x cursor’s category and < 20x cursor’s avg • e.g. < 2.5ms and < 20x avg • Execution time’s 95th Percentile < 3x cursor’s category and < 30x cursor’s avg • e.g. < 3.75ms and < 30x avg • Execution time’s 97th Percentile < 4x cursor’s category and < 40x cursor’s avg • e.g. < 5ms and < 40x avg • Execution time’s 99th Percentile < 5x cursor’s category and < 50x cursor’s avg • e.g. < 6.25ms and < 50x avg
  • 29. Algorithm’s aggressiveness style - sample Level Meaning > Executions < Elapsed Time (ms) 1 Conservative 25,000 0.25 2 20,000 0.50 3 Moderate 15,000 0.75 4 10,000 1.00 5 Aggressive 5,000 1.25 Lvl > Execs < ET (ms) Avg < ET (ms) 90th Pctl < ET (ms) 95th Pctl < ET (ms) 97th Pctl < ET (ms) 99th Pctl 1 25,000 0.25 0.50 0.75 1.00 1.25 2 20,000 0.50 1.00 1.50 2.00 2.50 3 15,000 0.75 1.50 2.25 3.00 3.75 4 10,000 1.00 2.00 3.00 4.00 5.00 5 5,000 1.25 2.50 3.75 5.00 6.25 Begin Tx Category Implementation
  • 30. Sample category thresholds implementation Category > Executions Conservative > Executions Moderate > Executions Aggressive < ET (ms) Conservative < ET (ms) Moderate < ET (ms) Aggressive CommitTx 25,000 15,000 5,000 0.5 1.5 2.5 BeginTx 25,000 15,000 5,000 0.25 0.75 1.25 Read 5,000 3,000 1,000 10 30 50 GC 5,000 3,000 1,000 1,000 3,000 5,000 Other 5,000 3,000 1,000 200 600 1,000
  • 31. Create SQL Plan Baseline (SPB) • Enabled • Accepted • But not “Fixed” • Source most from Cursor Cache, and some from AWR
  • 32. Log decision • Update SPB “description” • Source SQL_ID • Source plan hash value (PHV) • Date when promoted to “Fixed” or demoted from “Fixed” • Write into log • Created SPB with selection metrics such as execution percentiles • Promoted and demoted SPBs, with criteria used • Rejected candidates and reason • Preserve logs for at least 1 month
  • 33. FPZ Algorithm (recap) • Pre-select SQL_ID/PHV candidates, mainly from shared pool • If there exists a valid SQL Plan Baseline (SPB) for candidate • Demote SPB if underperforms (disable it) • Promote SPB after proven performance (fix it) • Else (no SPB exists for candidate) • Further screen candidate • Create SPB if candidate is accepted • Log decision
  • 34. AWR Configuration • EXEC DBMS_SPM.CONFIGURE('plan_retention_weeks', 13); • EXEC DBMS_WORKLOAD_REPOSITORY.MODIFY_SNAPSHOT_SETTINGS(topnsql=>300); • ALTER SYSTEM SET "_awr_sql_child_limit" = 2000;
  • 35. Additional considerations • Set Autopurge to NO for Plans on black-list • Manually (out of scope for automation) • What if there is no “proven consistent performance”? • What if average performance is higher than target threshold? • What if predicates selectivity requires more than one execution plan? • What if SQL produces different plans across databases?
  • 36. FPZ Algorithm Automation • PL/SQL package • Can be executed from SQL*Plus or OEM calling a PL/SQL library • Executed connecting as CDB$ROOT • Set of configuration constants • How many SPB to create and how many promote? (or report only) • Report rejected candidates and non-promoted SPBs? • Evaluate particular application categories • Number of executions to consider a candidate, or to qualify for a SPB • Time per execution to qualify a candidate for SPM • Factors over average elapsed time for 90th, 95th, 97th and 99th percentiles • Days of AWR history to consider
  • 37.
  • 38. Dry run results and sample output +------------------------------------------------------------ | | Candidates : 2019 | SPBs Qualified for Creation : 977 | SPBs Qualified for Promotion : 4 | SPBs Created : 0 | SPBs Promoted : 0 | Date and Time (end) : 2017-10-22T14:33:42 | Duration (secs) : 102 | +------------------------------------------------------------
  • 39.
  • 40.
  • 41.
  • 42.
  • 47. Outliers • SQL not considered by PL/SQL library • Candidates rejected for valid reasons (performance, executions, age, etc.) • Bug on Algorithm or PL/SQL library? • Algorithm too restrictive? • Short-lived small spikes • Executions burst combined with frequent hard-parses due to CBO statistics gathering • SQL has multiple optimal plans as per Adaptive Cursor Sharing (ACS) • Algorithm implements a subset
  • 48. Closing remarks • Past performance may not be indicative of future results • Nevertheless: historical plan performance can be used to determine future SQL performance with some degree of confidence • Not every SQL statement gets a SPB • Some queries are still at risk of spikes • Lower rate of executions, performance above thresholds, new SQL, etc. • And not every plan becomes a SPB (think ACS) • Method presented reduces frequency of “plan flips” • Consistent latency is more important than best performance