SlideShare uma empresa Scribd logo
1 de 20
Forcing SQL execution
plan instability
Maris Elsins
Oracle [Applications] DBA
Meetup v2.0
© 2011 Pythian2
Who I am
• 9yOracle: 3y – PL/SQL Developer, 6y – Oracle [Apps] DBA
• Certificates: 10g OCM, 9i/10g/11g OCP, 11i Apps DBA OCP, 11i
SysAdmin OCE
• Working for Pythian since 07.2011
• Conferences:
• : 2007/2008/2010/2011
• : 2009/2010
• OUG Harmony : 2010/2011
• How to find me?
• http://www.pythian.com/news/author/elsins/
• http://appsdbalife.wordpress.com/
• http://lv.linkedin.com/in/mariselsins
• http://education.oracle.com/education/otn/melsins.html
• @MarisElsins
© 2011 Pythian3
Agenda
• Let’s talk about basics and stability at first
• Introduction about SQL execution plans
• Why do execution plans change?
• Why DBAs should be thinking about plan (in)stability?
• What plan stability features are available?
• SQL Plan Management (Baselines)
• SQL execution plan instability
• Why we would like to cause instability of execution
plans?
• How to «help» oracle to choose different execution plan?
• How to force oracle to use the plan which we know is
better?
© 2011 Pythian
Lets talk about basics and
stability!
4
© 2011 Pythian5
What is the «execution plan»?
• Set of detailed instructions on how to execute the
DML statement
• The instructions determine execution decisions like:
• In what order the tables (data sets) will be accessed
• What will be the access path (table scan/index)
• What will be the access method (index range scan / )
• How the data sets will be joint (HJ/NL/MJ)
• What/when set operations will be applied (union/minus/...)
• ... ~30 different operations available ...
• Each valid DML statement has an execution plan
• Execution plan is built by Optimizer during SQL parse
phase
© 2011 Pythian6
Sample execution plan
select o.order_date, i.product_id, i.unit_price, i.quantity
from orders o, order_items i
where i.order_id=o.order_id and o.customer_id=120;
--------------------------------------------------------
| Id | Operation | Name |
--------------------------------------------------------
| 0 | SELECT STATEMENT | |
|* 1 | HASH JOIN | |
| 2 | TABLE ACCESS BY INDEX ROWID| ORDERS |
|* 3 | INDEX RANGE SCAN | ORD_CUSTOMER_IX |
| 4 | TABLE ACCESS FULL | ORDER_ITEMS |
--------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("I"."ORDER_ID"="O"."ORDER_ID")
3 - access("O"."CUSTOMER_ID"=120)
© 2011 Pythian7
How to find the execution plan?
• DEMO1
• explain plan for select... – be careful!
• select * from table(DBMS_XPLAN.DISPLAY);
• Autotrace – be careful!
• dbms_xplan.display_cursor – this is good!
• Trace file STAT rows – this is good!
• However! Tkprof with «explain» option = be careful!
• Be Careful! = The execution plan might not be the one
that’s actually used at the time of execution
• this is good! = The execution plan is the one that’s
actually used at the time of execution
© 2011 Pythian8
Why do execution plans change?
• Execution plans are built by optimizer during hard parse operation.
• Hard parse happens just before execution when:
• The query is not found in the library cache (text of the statement is different)
• The query found in the library cache is semantically different
• The query found in the library cache has been invalidated
• The session settings / features are different
• ...
• It’s imposible to have total control over hard parses
• Following things can impact which plan will be chosen by the
optimizer:
• Optimizer statistics – DEMO2
• Data set
• Configuration
• Bind variables
• ...
• Any guesses on how many causes there are for queries with the same
text to have different execution plans? (v$sql_shared_cursor)
© 2011 Pythian9
Why DBAs should be thinking about execution
plan (in)stability?
• Because DBAs hate Mondays.
• Because data change and optimizer makes mistakes.
• Because optimizer behaviour can change after
patching / updates.
• Because bind variable peeking can make you hate
Tuesdays too.
• Because global configuration changes can affect
queries that we don’t want to be affected.
• e.g. pga_aggregate_target and hash joins
• Becuase ...
© 2011 Pythian10
Why DBAs are not thinking much about
execution plan (in)stability?
People get used to frequent performance issues
There were no good solutions to the problem
..But now it can be changed
© 2011 Pythian11
What plan stability features are available?
• Rule Based Optimizer :D 
• Hints 
• Stop collecting statistics 
• Outlines («Plan Stability» from 8i, not in 12c) /
• Useful to fight issues with individual SQLs (e.g. Bind variable
peeking)
• not good for wide use as the plans are completely locked
• Baselines («SQL Plan Management» from 11g) 
• Provides stability and also the flexibility
• DEMO3 Outlines
• DEMO4 Baselines
© 2011 Pythian12
More about Baselines...
• Capturing the baselines
• Automatic1
• OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES=TRUE
• 1st baseline is accepted automatically, others are not accepted
• Baseline is automatically created only for the queries that are executed at least 2
times
• DEMO2
• Automatic2
• OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES=FALSE
• If the baseline for the SQL exists already and possibly more efective execution plan
is identified
• Manually (DBMS_SPM)
• Load from Cursor cache (filter by schema, module, action)
• Load from Sql Tuning Set (DBMS_SQLTUNE = Tuning Pack)
• Load from AWR (DBMS_SQLTUNE = Tuning Pack)
• All manually loaded baselines are accepted when loaded
• Which baseline is used by optimizer?
• Fixed baseline with the lowest cost
• Accepted baseline with the lowest cost
© 2011 Pythian13
Evolving the baselines...
• What Evolving does?
• Compares the performance of new baselines to the best accepted baseline
• Comparison is done by executing sqls (comparing elapsed time, buffer gets,
...)
• If the new execution plan performs better, the baseline is accepted
• Evolving SQL Baselines
• Automatically = SQL Tuning Advisor = Tuning Pack licenses required
• Manually
• By Running DBMS_SPM.evolve_sql_plan_baseline
• By loading the new baselines from the cursor cache.
• SQL Plan Management (Baselines) is one of the TOP new features in 11g
© 2011 Pythian
SQL execution plan instability
Forcing optimizer to choose different execution plan
14
© 2011 Pythian15
Why we would like to force optimizer to use
different execution plan?
• Typical situations that benefit from ability to force usage
of different execution plans
• Optimizer refuses to generate the most efficient execution plan, we
need to force the usage of our tuned execution plan.
• We have an emergency!
• We have a poorly performin 3rd party application without access to
the source code, we are not able to tune the SQLs.
• Change control process is to painful and long (I’m not suggesting to
skip the testing)
• How do we want to do it?
• We want to affect only the queries we choose
• We want to affect those queries only in the way we choose
• We want flexibility in case situation changes
• We want a supported approach
• We don’t want to cause any downtime
• We don’t want to pay more 
© 2011 Pythian16
What features are available to force optimizer
to use different execution plan?
• Preferred approach
• Collect statistics so that they represent the data correctly 
• Tune the query, but don’t use hints
• Other options only when preferred approach is not possible
• Set and lock statistics 
• Adjust settings / init parameters 
• Globally
• Using logon triggers
• Outlines /
• SQL Profiles (EE+Diag+Tuning Packs = $) /
• Provides additional selectivity estimates to the optimizer
• Baselines 
Wait a second, there are copy/paste issues on this slide!
Outlines and Baselines are plan stability features!
...yes, but they can be used for other purposes too...
© 2011 Pythian17
Using Outlines to force usage of the execution plan
• Based on «How to Edit a Stored Outline to Use the Plan from
Another Stored Outline [ID 730062.1]»
• Create 2 private outlines
• For current execution plan
• For the wanted execution plan
• Swap private outlines
• Test private outlines
• Make the new outline public
• The method is supported by Oracle and available for versions 9i-
11gR2
• DEMO6
© 2011 Pythian18
Using Baselines to force usage of the execution plan
• Similarily to outlines there is an option to swap baselines by
• exporting them to stage table
• updating the data
• importing the modified baseline
• Recently J.Lewis suggested an easier way to build a «fake» baseline
• http://jonathanlewis.wordpress.com/2011/01/12/fake-baselines/
• Use dbms_spm.load_plans_from_cursor_cache to create the baseline
by combining data from 2 different SQLs:
• sql_text from bad SQL
• Sql_id and plan_hash_value from good SQL
• The method is fully supported by Oracle
• DEMO7
© 2011 Pythian19
Summary
• Databases change and so do the execution plans
• They can change to better one or worse ones
• There are situation when we need plan stability to
avoid bad surprises
• There are also situations when we want to enforce
different execution plan for particualt SQL
• Till 11g there were no good flexible features for that
• Check out the SQL Plan Management if you’re on 11g+
• Easy to use
• Offers Flexibility
• Available on 11g+ SE/EE
• Be careful with performance management options:
• Easy to do something that requires licensing
• control_management_pack_access
© 2011 Pythian20
Pythian Facts
• Founded in 1997, over 14 years
• 130+ employees
• 5 offices in 5 countries
• lots of employees around the world
• Employs
• 6 Oracle ACEs (Including 1 ACE director)
• Several Oracle Masters
• Plenty of technical geeks
• Platinum level partner in the Oracle Partner Network
• Actively supports technical communities via
• Blogging
• Conferences
• SIGs and other events
• Winner of Oracle North American Titan Award for Oracle
Exadata Pythian Oracle Titan Award.mp4

Mais conteúdo relacionado

Mais procurados

KoprowskiT - SQLBITS X - 2am a disaster just began
KoprowskiT - SQLBITS X - 2am a disaster just beganKoprowskiT - SQLBITS X - 2am a disaster just began
KoprowskiT - SQLBITS X - 2am a disaster just beganTobias Koprowski
 
MySQL Performance Tuning: The Perfect Scalability (OOW2019)
MySQL Performance Tuning: The Perfect Scalability (OOW2019)MySQL Performance Tuning: The Perfect Scalability (OOW2019)
MySQL Performance Tuning: The Perfect Scalability (OOW2019)Mirko Ortensi
 
MySQL 5.7: Focus on InnoDB
MySQL 5.7: Focus on InnoDBMySQL 5.7: Focus on InnoDB
MySQL 5.7: Focus on InnoDBMario Beck
 
Oracle Database appliance - Value proposition Webcast
Oracle Database appliance - Value proposition WebcastOracle Database appliance - Value proposition Webcast
Oracle Database appliance - Value proposition WebcastThanos TP
 
Extreme Availability using Oracle 12c Features: Your very last system shutdown?
Extreme Availability using Oracle 12c Features: Your very last system shutdown?Extreme Availability using Oracle 12c Features: Your very last system shutdown?
Extreme Availability using Oracle 12c Features: Your very last system shutdown?Toronto-Oracle-Users-Group
 
Making MySQL highly available using Oracle Grid Infrastructure
Making MySQL highly available using Oracle Grid InfrastructureMaking MySQL highly available using Oracle Grid Infrastructure
Making MySQL highly available using Oracle Grid InfrastructureIlmar Kerm
 
Exadata 12c New Features RMOUG
Exadata 12c New Features RMOUGExadata 12c New Features RMOUG
Exadata 12c New Features RMOUGFuad Arshad
 
WebLogic on ODA - Oracle Open World 2013
WebLogic on ODA - Oracle Open World 2013WebLogic on ODA - Oracle Open World 2013
WebLogic on ODA - Oracle Open World 2013Michel Schildmeijer
 
C15LV: Ins and Outs of Concurrent Processing Configuration in Oracle e-Busine...
C15LV: Ins and Outs of Concurrent Processing Configuration in Oracle e-Busine...C15LV: Ins and Outs of Concurrent Processing Configuration in Oracle e-Busine...
C15LV: Ins and Outs of Concurrent Processing Configuration in Oracle e-Busine...Maris Elsins
 
My sql performance tuning course
My sql performance tuning courseMy sql performance tuning course
My sql performance tuning courseAlberto Centanni
 
Enterprise PostgreSQL - EDB's answer to conventional Databases
Enterprise PostgreSQL - EDB's answer to conventional DatabasesEnterprise PostgreSQL - EDB's answer to conventional Databases
Enterprise PostgreSQL - EDB's answer to conventional DatabasesAshnikbiz
 
MySQL Performance Metrics that Matter
MySQL Performance Metrics that MatterMySQL Performance Metrics that Matter
MySQL Performance Metrics that MatterMorgan Tocker
 
Docker Concepts for Oracle/MySQL DBAs and DevOps
Docker Concepts for Oracle/MySQL DBAs and DevOpsDocker Concepts for Oracle/MySQL DBAs and DevOps
Docker Concepts for Oracle/MySQL DBAs and DevOpsZohar Elkayam
 
Whitepaper: Running Oracle e-Business Suite Database on Oracle Database Appli...
Whitepaper: Running Oracle e-Business Suite Database on Oracle Database Appli...Whitepaper: Running Oracle e-Business Suite Database on Oracle Database Appli...
Whitepaper: Running Oracle e-Business Suite Database on Oracle Database Appli...Maris Elsins
 
Oracle Database Appliance X5-2
Oracle Database Appliance X5-2 Oracle Database Appliance X5-2
Oracle Database Appliance X5-2 Yasir El Nimr
 
Oracle Database Appliance Workshop
Oracle Database Appliance WorkshopOracle Database Appliance Workshop
Oracle Database Appliance WorkshopMarketingArrowECS_CZ
 
Sql Server 2014 In Memory
Sql Server 2014 In MemorySql Server 2014 In Memory
Sql Server 2014 In MemoryRavi Okade
 
KoprowskiT_SQLRelay2014#8_Birmingham_FromPlanToBackupToCloud
KoprowskiT_SQLRelay2014#8_Birmingham_FromPlanToBackupToCloudKoprowskiT_SQLRelay2014#8_Birmingham_FromPlanToBackupToCloud
KoprowskiT_SQLRelay2014#8_Birmingham_FromPlanToBackupToCloudTobias Koprowski
 
SPSSac2014 - SharePoint Infrastructure Tips and Tricks for On-Premises and Hy...
SPSSac2014 - SharePoint Infrastructure Tips and Tricks for On-Premises and Hy...SPSSac2014 - SharePoint Infrastructure Tips and Tricks for On-Premises and Hy...
SPSSac2014 - SharePoint Infrastructure Tips and Tricks for On-Premises and Hy...Michael Noel
 
The InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQLThe InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQLMorgan Tocker
 

Mais procurados (20)

KoprowskiT - SQLBITS X - 2am a disaster just began
KoprowskiT - SQLBITS X - 2am a disaster just beganKoprowskiT - SQLBITS X - 2am a disaster just began
KoprowskiT - SQLBITS X - 2am a disaster just began
 
MySQL Performance Tuning: The Perfect Scalability (OOW2019)
MySQL Performance Tuning: The Perfect Scalability (OOW2019)MySQL Performance Tuning: The Perfect Scalability (OOW2019)
MySQL Performance Tuning: The Perfect Scalability (OOW2019)
 
MySQL 5.7: Focus on InnoDB
MySQL 5.7: Focus on InnoDBMySQL 5.7: Focus on InnoDB
MySQL 5.7: Focus on InnoDB
 
Oracle Database appliance - Value proposition Webcast
Oracle Database appliance - Value proposition WebcastOracle Database appliance - Value proposition Webcast
Oracle Database appliance - Value proposition Webcast
 
Extreme Availability using Oracle 12c Features: Your very last system shutdown?
Extreme Availability using Oracle 12c Features: Your very last system shutdown?Extreme Availability using Oracle 12c Features: Your very last system shutdown?
Extreme Availability using Oracle 12c Features: Your very last system shutdown?
 
Making MySQL highly available using Oracle Grid Infrastructure
Making MySQL highly available using Oracle Grid InfrastructureMaking MySQL highly available using Oracle Grid Infrastructure
Making MySQL highly available using Oracle Grid Infrastructure
 
Exadata 12c New Features RMOUG
Exadata 12c New Features RMOUGExadata 12c New Features RMOUG
Exadata 12c New Features RMOUG
 
WebLogic on ODA - Oracle Open World 2013
WebLogic on ODA - Oracle Open World 2013WebLogic on ODA - Oracle Open World 2013
WebLogic on ODA - Oracle Open World 2013
 
C15LV: Ins and Outs of Concurrent Processing Configuration in Oracle e-Busine...
C15LV: Ins and Outs of Concurrent Processing Configuration in Oracle e-Busine...C15LV: Ins and Outs of Concurrent Processing Configuration in Oracle e-Busine...
C15LV: Ins and Outs of Concurrent Processing Configuration in Oracle e-Busine...
 
My sql performance tuning course
My sql performance tuning courseMy sql performance tuning course
My sql performance tuning course
 
Enterprise PostgreSQL - EDB's answer to conventional Databases
Enterprise PostgreSQL - EDB's answer to conventional DatabasesEnterprise PostgreSQL - EDB's answer to conventional Databases
Enterprise PostgreSQL - EDB's answer to conventional Databases
 
MySQL Performance Metrics that Matter
MySQL Performance Metrics that MatterMySQL Performance Metrics that Matter
MySQL Performance Metrics that Matter
 
Docker Concepts for Oracle/MySQL DBAs and DevOps
Docker Concepts for Oracle/MySQL DBAs and DevOpsDocker Concepts for Oracle/MySQL DBAs and DevOps
Docker Concepts for Oracle/MySQL DBAs and DevOps
 
Whitepaper: Running Oracle e-Business Suite Database on Oracle Database Appli...
Whitepaper: Running Oracle e-Business Suite Database on Oracle Database Appli...Whitepaper: Running Oracle e-Business Suite Database on Oracle Database Appli...
Whitepaper: Running Oracle e-Business Suite Database on Oracle Database Appli...
 
Oracle Database Appliance X5-2
Oracle Database Appliance X5-2 Oracle Database Appliance X5-2
Oracle Database Appliance X5-2
 
Oracle Database Appliance Workshop
Oracle Database Appliance WorkshopOracle Database Appliance Workshop
Oracle Database Appliance Workshop
 
Sql Server 2014 In Memory
Sql Server 2014 In MemorySql Server 2014 In Memory
Sql Server 2014 In Memory
 
KoprowskiT_SQLRelay2014#8_Birmingham_FromPlanToBackupToCloud
KoprowskiT_SQLRelay2014#8_Birmingham_FromPlanToBackupToCloudKoprowskiT_SQLRelay2014#8_Birmingham_FromPlanToBackupToCloud
KoprowskiT_SQLRelay2014#8_Birmingham_FromPlanToBackupToCloud
 
SPSSac2014 - SharePoint Infrastructure Tips and Tricks for On-Premises and Hy...
SPSSac2014 - SharePoint Infrastructure Tips and Tricks for On-Premises and Hy...SPSSac2014 - SharePoint Infrastructure Tips and Tricks for On-Premises and Hy...
SPSSac2014 - SharePoint Infrastructure Tips and Tricks for On-Premises and Hy...
 
The InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQLThe InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQL
 

Semelhante a LVOUG meetup #2 - Forcing SQL Execution Plan Instability

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
 
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
 
Protect Sensitive Data: Implementing Fine-Grained Access Control in Oracle
Protect Sensitive Data: Implementing Fine-Grained Access Control in OracleProtect Sensitive Data: Implementing Fine-Grained Access Control in Oracle
Protect Sensitive Data: Implementing Fine-Grained Access Control in OracleNelson Calero
 
Beginners guide to_optimizer
Beginners guide to_optimizerBeginners guide to_optimizer
Beginners guide to_optimizerMaria Colgan
 
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
 
Ten query tuning techniques every SQL Server programmer should know
Ten query tuning techniques every SQL Server programmer should knowTen query tuning techniques every SQL Server programmer should know
Ten query tuning techniques every SQL Server programmer should knowKevin Kline
 
ORACLE 12C-New-Features
ORACLE 12C-New-FeaturesORACLE 12C-New-Features
ORACLE 12C-New-FeaturesNavneet Upneja
 
Splunk in Rakuten: Splunk as a Service for all
Splunk in Rakuten: Splunk as a Service for allSplunk in Rakuten: Splunk as a Service for all
Splunk in Rakuten: Splunk as a Service for allTimur Bagirov
 
Upcoming changes in MySQL 5.7
Upcoming changes in MySQL 5.7Upcoming changes in MySQL 5.7
Upcoming changes in MySQL 5.7Morgan Tocker
 
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
 
Sql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ISql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ICarlos Oliveira
 
Sql developer - Powerful Free tool for Developers and DBA's
Sql developer - Powerful Free tool for Developers and DBA'sSql developer - Powerful Free tool for Developers and DBA's
Sql developer - Powerful Free tool for Developers and DBA'sNavneet Upneja
 
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
 
Oracle Enterprise Manager 12c: updates and upgrades.
Oracle Enterprise Manager 12c: updates and upgrades.Oracle Enterprise Manager 12c: updates and upgrades.
Oracle Enterprise Manager 12c: updates and upgrades.Rolta
 
DataStax: Setting Your Database Management on Autopilot with OpsCenter
DataStax: Setting Your Database Management on Autopilot with OpsCenterDataStax: Setting Your Database Management on Autopilot with OpsCenter
DataStax: Setting Your Database Management on Autopilot with OpsCenterDataStax Academy
 
Webinar: Ten Ways to Enhance Your Salesforce.com Application in 2013
Webinar: Ten Ways to Enhance Your Salesforce.com Application in 2013Webinar: Ten Ways to Enhance Your Salesforce.com Application in 2013
Webinar: Ten Ways to Enhance Your Salesforce.com Application in 2013Emtec Inc.
 
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
 
High Performance SSRS
High Performance SSRSHigh Performance SSRS
High Performance SSRSBert Wagner
 

Semelhante a LVOUG meetup #2 - Forcing SQL Execution Plan Instability (20)

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
 
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
 
Protect Sensitive Data: Implementing Fine-Grained Access Control in Oracle
Protect Sensitive Data: Implementing Fine-Grained Access Control in OracleProtect Sensitive Data: Implementing Fine-Grained Access Control in Oracle
Protect Sensitive Data: Implementing Fine-Grained Access Control in Oracle
 
Beginners guide to_optimizer
Beginners guide to_optimizerBeginners guide to_optimizer
Beginners guide to_optimizer
 
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
 
Ten query tuning techniques every SQL Server programmer should know
Ten query tuning techniques every SQL Server programmer should knowTen query tuning techniques every SQL Server programmer should know
Ten query tuning techniques every SQL Server programmer should know
 
11gR2 Upgrade.pdf
11gR2 Upgrade.pdf11gR2 Upgrade.pdf
11gR2 Upgrade.pdf
 
11gR2 Upgrade.pdf
11gR2 Upgrade.pdf11gR2 Upgrade.pdf
11gR2 Upgrade.pdf
 
ORACLE 12C-New-Features
ORACLE 12C-New-FeaturesORACLE 12C-New-Features
ORACLE 12C-New-Features
 
Splunk in Rakuten: Splunk as a Service for all
Splunk in Rakuten: Splunk as a Service for allSplunk in Rakuten: Splunk as a Service for all
Splunk in Rakuten: Splunk as a Service for all
 
Upcoming changes in MySQL 5.7
Upcoming changes in MySQL 5.7Upcoming changes in MySQL 5.7
Upcoming changes in MySQL 5.7
 
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
 
Sql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ISql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices I
 
Sql developer - Powerful Free tool for Developers and DBA's
Sql developer - Powerful Free tool for Developers and DBA'sSql developer - Powerful Free tool for Developers and DBA's
Sql developer - Powerful Free tool for Developers and DBA's
 
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
 
Oracle Enterprise Manager 12c: updates and upgrades.
Oracle Enterprise Manager 12c: updates and upgrades.Oracle Enterprise Manager 12c: updates and upgrades.
Oracle Enterprise Manager 12c: updates and upgrades.
 
DataStax: Setting Your Database Management on Autopilot with OpsCenter
DataStax: Setting Your Database Management on Autopilot with OpsCenterDataStax: Setting Your Database Management on Autopilot with OpsCenter
DataStax: Setting Your Database Management on Autopilot with OpsCenter
 
Webinar: Ten Ways to Enhance Your Salesforce.com Application in 2013
Webinar: Ten Ways to Enhance Your Salesforce.com Application in 2013Webinar: Ten Ways to Enhance Your Salesforce.com Application in 2013
Webinar: Ten Ways to Enhance Your Salesforce.com Application in 2013
 
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
 
High Performance SSRS
High Performance SSRSHigh Performance SSRS
High Performance SSRS
 

Mais de Maris Elsins

An AWS DMS Replication Journey from Oracle to Aurora MySQL
An AWS DMS Replication Journey from Oracle to Aurora MySQLAn AWS DMS Replication Journey from Oracle to Aurora MySQL
An AWS DMS Replication Journey from Oracle to Aurora MySQLMaris Elsins
 
Oracle Databases on AWS - Getting the Best Out of RDS and EC2
Oracle Databases on AWS - Getting the Best Out of RDS and EC2Oracle Databases on AWS - Getting the Best Out of RDS and EC2
Oracle Databases on AWS - Getting the Best Out of RDS and EC2Maris Elsins
 
Migrating and Running DBs on Amazon RDS for Oracle
Migrating and Running DBs on Amazon RDS for OracleMigrating and Running DBs on Amazon RDS for Oracle
Migrating and Running DBs on Amazon RDS for OracleMaris Elsins
 
Mining AWR V2 - Trend Analysis
Mining AWR V2 - Trend AnalysisMining AWR V2 - Trend Analysis
Mining AWR V2 - Trend AnalysisMaris Elsins
 
Mining the AWR: Alternative Methods for Identification of the Top SQLs (inclu...
Mining the AWR: Alternative Methods for Identification of the Top SQLs (inclu...Mining the AWR: Alternative Methods for Identification of the Top SQLs (inclu...
Mining the AWR: Alternative Methods for Identification of the Top SQLs (inclu...Maris Elsins
 
LVOUG meetup #4 - Case Study 10g to 11g
LVOUG meetup #4 - Case Study 10g to 11gLVOUG meetup #4 - Case Study 10g to 11g
LVOUG meetup #4 - Case Study 10g to 11gMaris Elsins
 
Surviving the Crisis With the Help of Oracle Database Resource Manager
Surviving the Crisis With the Help of Oracle Database Resource ManagerSurviving the Crisis With the Help of Oracle Database Resource Manager
Surviving the Crisis With the Help of Oracle Database Resource ManagerMaris Elsins
 
Concurrent Processing Performance Analysis for Apps DBAs
Concurrent Processing Performance Analysis for Apps DBAsConcurrent Processing Performance Analysis for Apps DBAs
Concurrent Processing Performance Analysis for Apps DBAsMaris Elsins
 
Simplify Consolidation with Oracle Database 12c
Simplify Consolidation with Oracle Database 12cSimplify Consolidation with Oracle Database 12c
Simplify Consolidation with Oracle Database 12cMaris Elsins
 
10 ways to improve your rman script
10 ways to improve your rman script10 ways to improve your rman script
10 ways to improve your rman scriptMaris Elsins
 
Wildcard13 - warmup slides for the "Roundtable discussion with Oracle Profess...
Wildcard13 - warmup slides for the "Roundtable discussion with Oracle Profess...Wildcard13 - warmup slides for the "Roundtable discussion with Oracle Profess...
Wildcard13 - warmup slides for the "Roundtable discussion with Oracle Profess...Maris Elsins
 
Internals of concurent managers
Internals of concurent managersInternals of concurent managers
Internals of concurent managersMaris Elsins
 
Using SQL Plan Management for Performance Testing
Using SQL Plan Management for Performance TestingUsing SQL Plan Management for Performance Testing
Using SQL Plan Management for Performance TestingMaris Elsins
 

Mais de Maris Elsins (13)

An AWS DMS Replication Journey from Oracle to Aurora MySQL
An AWS DMS Replication Journey from Oracle to Aurora MySQLAn AWS DMS Replication Journey from Oracle to Aurora MySQL
An AWS DMS Replication Journey from Oracle to Aurora MySQL
 
Oracle Databases on AWS - Getting the Best Out of RDS and EC2
Oracle Databases on AWS - Getting the Best Out of RDS and EC2Oracle Databases on AWS - Getting the Best Out of RDS and EC2
Oracle Databases on AWS - Getting the Best Out of RDS and EC2
 
Migrating and Running DBs on Amazon RDS for Oracle
Migrating and Running DBs on Amazon RDS for OracleMigrating and Running DBs on Amazon RDS for Oracle
Migrating and Running DBs on Amazon RDS for Oracle
 
Mining AWR V2 - Trend Analysis
Mining AWR V2 - Trend AnalysisMining AWR V2 - Trend Analysis
Mining AWR V2 - Trend Analysis
 
Mining the AWR: Alternative Methods for Identification of the Top SQLs (inclu...
Mining the AWR: Alternative Methods for Identification of the Top SQLs (inclu...Mining the AWR: Alternative Methods for Identification of the Top SQLs (inclu...
Mining the AWR: Alternative Methods for Identification of the Top SQLs (inclu...
 
LVOUG meetup #4 - Case Study 10g to 11g
LVOUG meetup #4 - Case Study 10g to 11gLVOUG meetup #4 - Case Study 10g to 11g
LVOUG meetup #4 - Case Study 10g to 11g
 
Surviving the Crisis With the Help of Oracle Database Resource Manager
Surviving the Crisis With the Help of Oracle Database Resource ManagerSurviving the Crisis With the Help of Oracle Database Resource Manager
Surviving the Crisis With the Help of Oracle Database Resource Manager
 
Concurrent Processing Performance Analysis for Apps DBAs
Concurrent Processing Performance Analysis for Apps DBAsConcurrent Processing Performance Analysis for Apps DBAs
Concurrent Processing Performance Analysis for Apps DBAs
 
Simplify Consolidation with Oracle Database 12c
Simplify Consolidation with Oracle Database 12cSimplify Consolidation with Oracle Database 12c
Simplify Consolidation with Oracle Database 12c
 
10 ways to improve your rman script
10 ways to improve your rman script10 ways to improve your rman script
10 ways to improve your rman script
 
Wildcard13 - warmup slides for the "Roundtable discussion with Oracle Profess...
Wildcard13 - warmup slides for the "Roundtable discussion with Oracle Profess...Wildcard13 - warmup slides for the "Roundtable discussion with Oracle Profess...
Wildcard13 - warmup slides for the "Roundtable discussion with Oracle Profess...
 
Internals of concurent managers
Internals of concurent managersInternals of concurent managers
Internals of concurent managers
 
Using SQL Plan Management for Performance Testing
Using SQL Plan Management for Performance TestingUsing SQL Plan Management for Performance Testing
Using SQL Plan Management for Performance Testing
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 

Último (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 

LVOUG meetup #2 - Forcing SQL Execution Plan Instability

  • 1. Forcing SQL execution plan instability Maris Elsins Oracle [Applications] DBA Meetup v2.0
  • 2. © 2011 Pythian2 Who I am • 9yOracle: 3y – PL/SQL Developer, 6y – Oracle [Apps] DBA • Certificates: 10g OCM, 9i/10g/11g OCP, 11i Apps DBA OCP, 11i SysAdmin OCE • Working for Pythian since 07.2011 • Conferences: • : 2007/2008/2010/2011 • : 2009/2010 • OUG Harmony : 2010/2011 • How to find me? • http://www.pythian.com/news/author/elsins/ • http://appsdbalife.wordpress.com/ • http://lv.linkedin.com/in/mariselsins • http://education.oracle.com/education/otn/melsins.html • @MarisElsins
  • 3. © 2011 Pythian3 Agenda • Let’s talk about basics and stability at first • Introduction about SQL execution plans • Why do execution plans change? • Why DBAs should be thinking about plan (in)stability? • What plan stability features are available? • SQL Plan Management (Baselines) • SQL execution plan instability • Why we would like to cause instability of execution plans? • How to «help» oracle to choose different execution plan? • How to force oracle to use the plan which we know is better?
  • 4. © 2011 Pythian Lets talk about basics and stability! 4
  • 5. © 2011 Pythian5 What is the «execution plan»? • Set of detailed instructions on how to execute the DML statement • The instructions determine execution decisions like: • In what order the tables (data sets) will be accessed • What will be the access path (table scan/index) • What will be the access method (index range scan / ) • How the data sets will be joint (HJ/NL/MJ) • What/when set operations will be applied (union/minus/...) • ... ~30 different operations available ... • Each valid DML statement has an execution plan • Execution plan is built by Optimizer during SQL parse phase
  • 6. © 2011 Pythian6 Sample execution plan select o.order_date, i.product_id, i.unit_price, i.quantity from orders o, order_items i where i.order_id=o.order_id and o.customer_id=120; -------------------------------------------------------- | Id | Operation | Name | -------------------------------------------------------- | 0 | SELECT STATEMENT | | |* 1 | HASH JOIN | | | 2 | TABLE ACCESS BY INDEX ROWID| ORDERS | |* 3 | INDEX RANGE SCAN | ORD_CUSTOMER_IX | | 4 | TABLE ACCESS FULL | ORDER_ITEMS | -------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - access("I"."ORDER_ID"="O"."ORDER_ID") 3 - access("O"."CUSTOMER_ID"=120)
  • 7. © 2011 Pythian7 How to find the execution plan? • DEMO1 • explain plan for select... – be careful! • select * from table(DBMS_XPLAN.DISPLAY); • Autotrace – be careful! • dbms_xplan.display_cursor – this is good! • Trace file STAT rows – this is good! • However! Tkprof with «explain» option = be careful! • Be Careful! = The execution plan might not be the one that’s actually used at the time of execution • this is good! = The execution plan is the one that’s actually used at the time of execution
  • 8. © 2011 Pythian8 Why do execution plans change? • Execution plans are built by optimizer during hard parse operation. • Hard parse happens just before execution when: • The query is not found in the library cache (text of the statement is different) • The query found in the library cache is semantically different • The query found in the library cache has been invalidated • The session settings / features are different • ... • It’s imposible to have total control over hard parses • Following things can impact which plan will be chosen by the optimizer: • Optimizer statistics – DEMO2 • Data set • Configuration • Bind variables • ... • Any guesses on how many causes there are for queries with the same text to have different execution plans? (v$sql_shared_cursor)
  • 9. © 2011 Pythian9 Why DBAs should be thinking about execution plan (in)stability? • Because DBAs hate Mondays. • Because data change and optimizer makes mistakes. • Because optimizer behaviour can change after patching / updates. • Because bind variable peeking can make you hate Tuesdays too. • Because global configuration changes can affect queries that we don’t want to be affected. • e.g. pga_aggregate_target and hash joins • Becuase ...
  • 10. © 2011 Pythian10 Why DBAs are not thinking much about execution plan (in)stability? People get used to frequent performance issues There were no good solutions to the problem ..But now it can be changed
  • 11. © 2011 Pythian11 What plan stability features are available? • Rule Based Optimizer :D  • Hints  • Stop collecting statistics  • Outlines («Plan Stability» from 8i, not in 12c) / • Useful to fight issues with individual SQLs (e.g. Bind variable peeking) • not good for wide use as the plans are completely locked • Baselines («SQL Plan Management» from 11g)  • Provides stability and also the flexibility • DEMO3 Outlines • DEMO4 Baselines
  • 12. © 2011 Pythian12 More about Baselines... • Capturing the baselines • Automatic1 • OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES=TRUE • 1st baseline is accepted automatically, others are not accepted • Baseline is automatically created only for the queries that are executed at least 2 times • DEMO2 • Automatic2 • OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES=FALSE • If the baseline for the SQL exists already and possibly more efective execution plan is identified • Manually (DBMS_SPM) • Load from Cursor cache (filter by schema, module, action) • Load from Sql Tuning Set (DBMS_SQLTUNE = Tuning Pack) • Load from AWR (DBMS_SQLTUNE = Tuning Pack) • All manually loaded baselines are accepted when loaded • Which baseline is used by optimizer? • Fixed baseline with the lowest cost • Accepted baseline with the lowest cost
  • 13. © 2011 Pythian13 Evolving the baselines... • What Evolving does? • Compares the performance of new baselines to the best accepted baseline • Comparison is done by executing sqls (comparing elapsed time, buffer gets, ...) • If the new execution plan performs better, the baseline is accepted • Evolving SQL Baselines • Automatically = SQL Tuning Advisor = Tuning Pack licenses required • Manually • By Running DBMS_SPM.evolve_sql_plan_baseline • By loading the new baselines from the cursor cache. • SQL Plan Management (Baselines) is one of the TOP new features in 11g
  • 14. © 2011 Pythian SQL execution plan instability Forcing optimizer to choose different execution plan 14
  • 15. © 2011 Pythian15 Why we would like to force optimizer to use different execution plan? • Typical situations that benefit from ability to force usage of different execution plans • Optimizer refuses to generate the most efficient execution plan, we need to force the usage of our tuned execution plan. • We have an emergency! • We have a poorly performin 3rd party application without access to the source code, we are not able to tune the SQLs. • Change control process is to painful and long (I’m not suggesting to skip the testing) • How do we want to do it? • We want to affect only the queries we choose • We want to affect those queries only in the way we choose • We want flexibility in case situation changes • We want a supported approach • We don’t want to cause any downtime • We don’t want to pay more 
  • 16. © 2011 Pythian16 What features are available to force optimizer to use different execution plan? • Preferred approach • Collect statistics so that they represent the data correctly  • Tune the query, but don’t use hints • Other options only when preferred approach is not possible • Set and lock statistics  • Adjust settings / init parameters  • Globally • Using logon triggers • Outlines / • SQL Profiles (EE+Diag+Tuning Packs = $) / • Provides additional selectivity estimates to the optimizer • Baselines  Wait a second, there are copy/paste issues on this slide! Outlines and Baselines are plan stability features! ...yes, but they can be used for other purposes too...
  • 17. © 2011 Pythian17 Using Outlines to force usage of the execution plan • Based on «How to Edit a Stored Outline to Use the Plan from Another Stored Outline [ID 730062.1]» • Create 2 private outlines • For current execution plan • For the wanted execution plan • Swap private outlines • Test private outlines • Make the new outline public • The method is supported by Oracle and available for versions 9i- 11gR2 • DEMO6
  • 18. © 2011 Pythian18 Using Baselines to force usage of the execution plan • Similarily to outlines there is an option to swap baselines by • exporting them to stage table • updating the data • importing the modified baseline • Recently J.Lewis suggested an easier way to build a «fake» baseline • http://jonathanlewis.wordpress.com/2011/01/12/fake-baselines/ • Use dbms_spm.load_plans_from_cursor_cache to create the baseline by combining data from 2 different SQLs: • sql_text from bad SQL • Sql_id and plan_hash_value from good SQL • The method is fully supported by Oracle • DEMO7
  • 19. © 2011 Pythian19 Summary • Databases change and so do the execution plans • They can change to better one or worse ones • There are situation when we need plan stability to avoid bad surprises • There are also situations when we want to enforce different execution plan for particualt SQL • Till 11g there were no good flexible features for that • Check out the SQL Plan Management if you’re on 11g+ • Easy to use • Offers Flexibility • Available on 11g+ SE/EE • Be careful with performance management options: • Easy to do something that requires licensing • control_management_pack_access
  • 20. © 2011 Pythian20 Pythian Facts • Founded in 1997, over 14 years • 130+ employees • 5 offices in 5 countries • lots of employees around the world • Employs • 6 Oracle ACEs (Including 1 ACE director) • Several Oracle Masters • Plenty of technical geeks • Platinum level partner in the Oracle Partner Network • Actively supports technical communities via • Blogging • Conferences • SIGs and other events • Winner of Oracle North American Titan Award for Oracle Exadata Pythian Oracle Titan Award.mp4