SlideShare ist ein Scribd-Unternehmen logo
1 von 44
Understanding how is that
Adaptive Cursor Sharing (ACS)
produces multiple Optimal Plans
Carlos Sierra
Carlos Sierra
• SQLTXPLAIN + SQL Health-Check SQLHC +
• Consultant/Developer/DBA/Design/+
• Oracle Performance + SQL Tuning
• Oracle Database Health-Check
• Tools + Scripts
• Speaker
Enkitec (c) 2014 2
Topics
• Motivation
• Adaptive Cursor Sharing (ACS)
– Mechanics
– Demos
Enkitec (c) 2014 3
Plan Flexibility Allies
• CBO Parameters
• CBO Statistics
• Dynamic Sampling
• Cardinality Feedback
• Cursor Sharing
• Adaptive Cursor Sharing (ACS)
Enkitec (c) 2014 4
Plan Stability Tools
• CBO Hints
• Stored Outlines
• SQL Profiles
• SQL Plan Management (SPM)
Enkitec (c) 2014 5
Flexibility versus Stability
• Flexible Plans adapt as Data evolves over Time
• Performance of Stable Plans is more Predictable
• But, you can't eat your cake and have it (too)…
• Can we balance Flexibility and Stability???
Enkitec (c) 2014 6
Cursor Sharing Review
• Use of Bind Variables instead of Literals
– AND c.car_maker = ‘Ford’
– AND c.car_maker = :b1
• Goal: Reduce Hard Parsing
– Improve Scalability
• Reduce CPU utilization
• Reduce Shared Memory footprint
Enkitec (c) 2014 7
Cursor Sharing Shortcomings
• Flipping Plans
– Exacerbated by Histograms on Skewed Data
– AND c.car_maker = :b2
• :b2 := ‘Ford’
• :b2 := ‘Lotus’
– Plan is computed at hard parse
• Plan performance becomes a moving target
Enkitec (c) 2014 8
Adaptive Cursor Sharing (ACS)
• Available on 11g+
• Offers Multiple Optimal Plans per SQL
– As per “Selectivity” of Predicates
• :b2 := ‘Ford’ (many rows)
• :b2 := ‘Lotus’ (fewer rows)
• Works well with SQL Plan Management
Enkitec (c) 2014 9
ACS Challenges
• Strategy
– Minimize Resources Impact
• Implementation
– Monitor only a subset of SQL Statements
– Activate ACS only for a subset of the monitored SQL
– Share Executions Plans through a “Selectivity Profile”
Enkitec (c) 2014 10
Cursors State
• Bind Sensitive
– A subset of Cursors are Bind Sensitive
• Bind Aware
– A subset of Bind Sensitive Cursors become Bind Aware
Enkitec (c) 2014 11
All Statements
Bind Sensitive
Bind Aware
ACS
Becoming Bind Sensitive
1. SQL has Range Predicates on Bind Variables
– AND c.cust_year_of_birth BETWEEN :b3 AND :b4
– AND p.prod_category LIKE :b5
2. SQL has Equality Predicates on Bind Variables and
Column has a Histogram
– AND c.cust_marital_status = :b2
– AND TO_CHAR(s.time_id, 'YYYY') = :b6
Enkitec (c) 2014 12
Becoming Bind Aware
1. Rows Processed change substantially between
Executions
– Between a few rows to millions
2. Rows Processed oscillate significantly between
Executions
– Between a few rows and a few thousand
– Between a few thousand and millions
Enkitec (c) 2014 13
ACS Dynamic Views
• V$SQL (Cursor State)
– is_shareable (Y/N)
– is_bind_sensitive (Y/N)
– is_bind_aware (Y/N)
• V$SQL_CS_STATISTICS (Rows Processed)
• V$SQL_CS_HISTOGRAM (3 Buckets S/M/L)
• V$SQL_CS_SELECTIVITY (Selectivity Profile)
Enkitec (c) 2014 14
Rows Processed
• v$sql_cs_statistics.rows_processed
• Updated only at hard parse
• A measure of amount of work on Execution Plan
• Three sizes: S/M/L
– 0: Small
– 1: Medium
– 2: Large
Enkitec (c) 2014 15
Rows Processed
• v$sql_cs_statistics.rows_processed
• Updated only at hard parse
• A measure of amount of work on Execution Plan
• Three sizes: S/M/L (undocumented boundaries)
– 0: Small (less than 1K rows)
– 1: Medium (between 1k and 1m rows)
– 2: Large (more than 1m rows)
Enkitec (c) 2014 16
ACS Buckets
• v$sql_cs_histogram.bucket_id
– 0: Small
– 1: Medium
– 2: Large
• v$sql_cs_histogram.count
– Incremented with each Execution as per
• v$sql_cs_statistics.rows_processed
Enkitec (c) 2014 17
Rows Processed and ACS Buckets
IF v$sql_cs_statistics.rows_processed < 1K THEN
v$sql_cs_histogram.count(0)++
ELSIF v$sql_cs_statistics.rows_processed < 1M THEN
v$sql_cs_histogram.count(1)++
ELSE
v$sql_cs_histogram.count(2)++
END IF
Enkitec (c) 2014 18
Becoming Bind Aware
1. Small and Large buckets have a value
– bucket_id.count(0) > 0 AND bucket_id.count(2) > 0
2. Two adjacent buckets have same non-zero value
– bucket_id.count(0) = bucket_id.count(1) > 0
– bucket_id.count(1) = bucket_id.count(2) > 0
Enkitec (c) 2014 19
Rows Processed per Execution
• rows_processed(bucket_id)… Bind Aware(BA)
• 10(0)… 50(0)… 3,000,000(2)… BA
• 30(0)… 3,000(1)… BA
• 2,000,000(2)… 1(0)… BA
• 0(0)… 10,000(1)… BA
• 3,000(1)… 2,000(1)… 200(0)… 300(0)… BA
• 10… 100… 500… 2,000… 3,000… 5,000… BA
Enkitec (c) 2014 20
WHY becoming BA is important?
• Multiple Optimal Plans are created after Cursor
becomes Bind Aware
Enkitec (c) 2014 21
Recap
• V$SQL_CS_STATISTICS (Rows Processed)
– Bind Sensitive Cursors determine which bucket should be
incremented according to actual rows processed
• V$SQL_CS_HISTOGRAM (3 Buckets S/M/L)
– Bind Sensitive Cursors increase count (+1) of respective
bucket at the end of each execution
• V$SQL_CS_SELECTIVITY (Selectivity Profile)
– Bind Aware Cursors maintain this “Selectivity” Data Structure
– To determine which Cursor (Plan) to use on each execution
Enkitec (c) 2014 22
Sample Query (1)
SELECT p.prod_subcategory_desc subcatagory,
SUM(amount_sold) amount_sold
FROM sh.customers c,
sh.products p,
sh.sales s
WHERE c.cust_gender = 'M'
AND c.cust_marital_status = 'single'
AND c.cust_year_of_birth BETWEEN 1913 AND 1990
AND p.prod_category LIKE 'Software%'
AND TO_CHAR(s.time_id, 'YYYY') = '2001'
AND s.cust_id = c.cust_id
AND s.prod_id = p.prod_id
GROUP BY
p.prod_subcategory_desc
ORDER BY
p.prod_subcategory_desc;
Enkitec (c) 2014 23
Sample Query (2)
• Based on Sample Schema SH
– With CBO Histograms in all Columns
• Not a requirement for this ACS test
• 3 Tables with Filter Predicates
• 2 Joins
• 6 possible Join Orders
• Several possible Execution Plans
Enkitec (c) 2014 24
Demo 1
• 5 Executions of Sample Query using Literals
– Different values for each Execution
• Sequence 1, 2, 3, 4 and 5
– Each Execution performs a Hard Parse
– Each Execution computes a “new” Plan
– Each seems to be an “Optimal” Plan
Enkitec (c) 2014 25
Demo 2
• 5 Executions of Sample Query using Binds
– Different values for each Execution
• Sequence 1, 2, 3, 4 and 5
– Each Execution performs a Hard Parse
• Forced with a Cursor Flush before the Execution
– Each computes a “new” Optimal Plan
• Almost same as “with Literals”
Enkitec (c) 2014 26
Demo 2 Results
Query Rows Processed ACS Bucket Plan Hash Value
1 1,483,124 2 2048551027
2 1,280,074 2 3600618656
3 1,017,774 2 189372815
4 2,770 1 847574763
5 3,132 1 847574763
Enkitec (c) 2014 27
Demo 3
• 5 Executions of Sample Query using Binds
– Different values for each Execution
• Sequence 1, 2, 3, 4 and 5
– No Cursor Flush between Executions
– First Execution computes a “new” Optimal Plan
– All Executions use same Plan…
Enkitec (c) 2014 28
Demo 3 Results
Query Rows Processed ACS Bucket Optimal
Plan
ACS Aware Executed
1 1,483,124 2 2048551027 N 2048551027
2 1,280,074 (~1.2M) 2 3600618656 N 2048551027
3 1,017,774 (~1.2M) 2 189372815 N 2048551027
4 2,770 (~526K ) 1 847574763 N 2048551027
5 3,132 (~50) 1 (0) 847574763 N 2048551027
Enkitec (c) 2014 29
Demo 4
• 5 Executions of Sample Query using Binds
– Different values for each Execution
• Sequence 5, 4, 3, 2 and 1
– No Cursor Flush between Executions
– Cursor becomes Bind Aware after 2nd Execution
– All Executions used an Optimal Plan
Enkitec (c) 2014 30
Demo 4 Results
Query Rows Processed ACS Bucket Optimal
Plan
Bind Aware Executed
5 3,132 1 847574763 N 847574763
4 2,770 1 847574763 N 847574763
3 1,017,774 (~130K) 2 (1) 189372815 N 847574763
2 1,280,074 (~241K) 2 (1) 3600618656 N 847574763
1 1,483,124 (~1.7M) 2 2048551027 N 847574763
Enkitec (c) 2014 31
Demo 5
• 5 Executions of Sample Query using Binds
– Different values for each Execution
• Sequence 5, 1, 2, 3 and 4
– No Cursor Flush between Executions
– Cursor becomes Bind Aware after 2nd Execution
– All but one Executions used an Optimal Plan
Enkitec (c) 2014 32
Demo 5 Results
Query Rows Processed ACS Bucket Optimal
Plan
Bind Aware Executed
5 3,132 1 847574763 N 847574763
1 1,483,124 (1.7M) 2 2048551027 N 847574763
2 1,280,074 2 3600618656 Y 3600618656
3 1,017,774 2 189372815 Y 189372815
4 2,770 1 847574763 Y 847574763
Enkitec (c) 2014 33
What is the Problem?
• Ramp-up Process may lead to some suboptimal
Executions
– Sensitive to sequence of values passed…
• Kind of a Learning Curve…
– Can we override it?
Enkitec (c) 2014 34
Controlling ACS with CBO Hint
• /*+ BIND_AWARE */
– Bypasses the monitoring phase of a Bind Sensitive SQL
• /*+ NO_BIND_AWARE */
– Turns off ACS for given SQL
Enkitec (c) 2014 35
Controlling ACS with SQL Patch
• SYS.DBMS_SQLDIAG_INTERNAL.I_CREATE_PATCH
– sql_text
– hint_text => BIND_AWARE
• Script sqlpch.sql connected as SYS
– SQL_ID
• 8u0n7w1jug5dg
• Test Demo 5…
Enkitec (c) 2014 36
ACS Plan Selection
• On every Execution of Bind Aware Cursor
– Compute Selectivity of each qualifying Predicate
– Search Selectivity within Range of values on ACS
Selectivity Profile
– If within Range, lookup Child Number and use its Plan
– Else, Hard Parse and Execute newly computed Plan
• If same as existing Plan, then update Selectivity Profile
• Else, create Selectivity Profile for new Child Number
Enkitec (c) 2014 37
Selectivity Profile (1)
• v$sql_cs_selectivity
– predicate
– range_id
• low and high (selectivities)
– child_number
Enkitec (c) 2014 38
Selectivity Profile (2)
CHILD PREDICATE RANGE_ID LOW HIGH
----------- ---------- ----------- ---------- ----------
1 <=B4 0 0.860941 1.052262
1 =B1 0 0.602369 0.736229
1 =B2 0 0.455337 0.556523
1 >=B3 0 0.182445 0.222988
1 B5 0 0.306250 0.374306
2 <=B4 0 0.892666 1.091036
2 =B1 0 0.297574 0.363702
2 =B2 0 0.455337 0.556523
2 >=B3 0 0.077947 0.095268
2 B5 0 0.306250 0.374306
3 <=B4 0 0.836835 1.022798
3 =B1 0 0.297574 0.363702
3 =B2 0 0.002085 0.002548
3 >=B3 0 0.221447 0.270657
3 B5 0 0.306250 0.374306
Enkitec (c) 2014 39
ACS Summary
• ACS is capable of producing multiple Optimal
Execution Plans per SQL
• During ramp-up sub Optimal Plans may happen
• ACS Metadata resides in Memory (not Persistent)
• ACS provides desirable Plan Flexibility
• ACS does not address the Plan Stability concern
Enkitec (c) 2014 40
ACS Suggested Strategy
• Use sys.dbms_sqldiag_internal.i_create_patch to
SQL Patch with BIND_AWARE the SQL on Baselines
• Use free script sqlpch.sql
Enkitec (c) 2014 41
References (1)
• Using SQL Patch to add hints to a packaged
application
– https://blogs.oracle.com/optimizer/entry/how_can_i_h
int_a
• Skipping ACS ramp-up using a SQL Patch
– http://carlos-sierra.net/2014/06/19/skipping-acs-ramp-
up-using-a-sql-patch/
Enkitec (c) 2014 42
References (2)
• Oracle® Database PL/SQL Packages and Types
Reference
– 11g Release 2 (11.2)
– Part Number E25788-04
Enkitec (c) 2014 43
Contact Information
• carlos.sierra@enkitec.com
• carlos-sierra.net
• @csierra_usa
Enkitec (c) 2014 44

Weitere ähnliche Inhalte

Was ist angesagt?

Oracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsOracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsEnkitec
 
Oracle db performance tuning
Oracle db performance tuningOracle db performance tuning
Oracle db performance tuningSimon Huang
 
Same plan different performance
Same plan different performanceSame plan different performance
Same plan different performanceMauro Pagano
 
Oracle database performance tuning
Oracle database performance tuningOracle database performance tuning
Oracle database performance tuningYogiji Creations
 
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...Carlos Sierra
 
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ OracleUnderstanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ OracleGuatemala User Group
 
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
 
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
 
Oracle Performance Tools of the Trade
Oracle Performance Tools of the TradeOracle Performance Tools of the Trade
Oracle Performance Tools of the TradeCarlos Sierra
 
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
 
Beginners guide to_optimizer
Beginners guide to_optimizerBeginners guide to_optimizer
Beginners guide to_optimizerMaria Colgan
 
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
 
Oracle statistics by example
Oracle statistics by exampleOracle statistics by example
Oracle statistics by exampleMauro Pagano
 
Introducing the eDB360 Tool
Introducing the eDB360 ToolIntroducing the eDB360 Tool
Introducing the eDB360 ToolCarlos Sierra
 
Polymorphic Table Functions in SQL
Polymorphic Table Functions in SQLPolymorphic Table Functions in SQL
Polymorphic Table Functions in SQLChris Saxon
 
Explain the explain_plan
Explain the explain_planExplain the explain_plan
Explain the explain_planMaria Colgan
 
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
 
Adapting to Adaptive Plans on 12c
Adapting to Adaptive Plans on 12cAdapting to Adaptive Plans on 12c
Adapting to Adaptive Plans on 12cMauro Pagano
 
Deep review of LMS process
Deep review of LMS processDeep review of LMS process
Deep review of LMS processRiyaj Shamsudeen
 

Was ist angesagt? (20)

Oracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsOracle Performance Tuning Fundamentals
Oracle Performance Tuning Fundamentals
 
Oracle db performance tuning
Oracle db performance tuningOracle db performance tuning
Oracle db performance tuning
 
Same plan different performance
Same plan different performanceSame plan different performance
Same plan different performance
 
Oracle database performance tuning
Oracle database performance tuningOracle database performance tuning
Oracle database performance tuning
 
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...
 
SQL Tuning 101
SQL Tuning 101SQL Tuning 101
SQL Tuning 101
 
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ OracleUnderstanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
 
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
 
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
 
Oracle Performance Tools of the Trade
Oracle Performance Tools of the TradeOracle Performance Tools of the Trade
Oracle Performance Tools of the Trade
 
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
 
Beginners guide to_optimizer
Beginners guide to_optimizerBeginners guide to_optimizer
Beginners guide to_optimizer
 
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
 
Oracle statistics by example
Oracle statistics by exampleOracle statistics by example
Oracle statistics by example
 
Introducing the eDB360 Tool
Introducing the eDB360 ToolIntroducing the eDB360 Tool
Introducing the eDB360 Tool
 
Polymorphic Table Functions in SQL
Polymorphic Table Functions in SQLPolymorphic Table Functions in SQL
Polymorphic Table Functions in SQL
 
Explain the explain_plan
Explain the explain_planExplain the explain_plan
Explain the explain_plan
 
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
 
Adapting to Adaptive Plans on 12c
Adapting to Adaptive Plans on 12cAdapting to Adaptive Plans on 12c
Adapting to Adaptive Plans on 12c
 
Deep review of LMS process
Deep review of LMS processDeep review of LMS process
Deep review of LMS process
 

Ähnlich wie Understanding How is that Adaptive Cursor Sharing (ACS) produces multiple Optimal Plans

Understanding how is that adaptive cursor sharing (acs) produces multiple opt...
Understanding how is that adaptive cursor sharing (acs) produces multiple opt...Understanding how is that adaptive cursor sharing (acs) produces multiple opt...
Understanding how is that adaptive cursor sharing (acs) produces multiple opt...Enkitec
 
Combining ACS Flexibility with SPM Stability
Combining ACS Flexibility with SPM StabilityCombining ACS Flexibility with SPM Stability
Combining ACS Flexibility with SPM StabilityEnkitec
 
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
 
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
 
Macy's: Changing Engines in Mid-Flight
Macy's: Changing Engines in Mid-FlightMacy's: Changing Engines in Mid-Flight
Macy's: Changing Engines in Mid-FlightDataStax Academy
 
Using SQL Plan Management (SPM) to Balance Plan Flexibility and Plan Stability
Using SQL Plan Management (SPM) to Balance Plan Flexibility and Plan StabilityUsing SQL Plan Management (SPM) to Balance Plan Flexibility and Plan Stability
Using SQL Plan Management (SPM) to Balance Plan Flexibility and Plan StabilityEnkitec
 
Meeting the challenges of OLTP Big Data with Scylla
Meeting the challenges of OLTP Big Data with ScyllaMeeting the challenges of OLTP Big Data with Scylla
Meeting the challenges of OLTP Big Data with ScyllaScyllaDB
 
Embarcadero In Search of Plan Stability Part 1 Webinar Slides
Embarcadero In Search of Plan Stability Part 1 Webinar SlidesEmbarcadero In Search of Plan Stability Part 1 Webinar Slides
Embarcadero In Search of Plan Stability Part 1 Webinar SlidesEmbarcadero Technologies
 
Using adaptive cursor sharing (acs) to produce multiple optimal plans v2
Using adaptive cursor sharing (acs) to produce multiple optimal plans v2Using adaptive cursor sharing (acs) to produce multiple optimal plans v2
Using adaptive cursor sharing (acs) to produce multiple optimal plans v2Enkitec
 
Windows Azure: Lessons From the Field
Windows Azure: Lessons From the FieldWindows Azure: Lessons From the Field
Windows Azure: Lessons From the FieldMichael Collier
 
261197832 8-performance-tuning-part i
261197832 8-performance-tuning-part i261197832 8-performance-tuning-part i
261197832 8-performance-tuning-part iNaviSoft
 
Fast federated SQL with Apache Calcite
Fast federated SQL with Apache CalciteFast federated SQL with Apache Calcite
Fast federated SQL with Apache CalciteChris Baynes
 
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
 
Introducing the eDB360 Tool
Introducing the eDB360 ToolIntroducing the eDB360 Tool
Introducing the eDB360 ToolCarlos Sierra
 
Big Data, Bigger Analytics
Big Data, Bigger AnalyticsBig Data, Bigger Analytics
Big Data, Bigger AnalyticsItzhak Kameli
 
Introduction 6.1 01_architecture_overview
Introduction 6.1 01_architecture_overviewIntroduction 6.1 01_architecture_overview
Introduction 6.1 01_architecture_overviewAnvith S. Upadhyaya
 
Dealing with the Three Horrible Problems in Verification
Dealing with the Three Horrible Problems in VerificationDealing with the Three Horrible Problems in Verification
Dealing with the Three Horrible Problems in VerificationDVClub
 
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...Nelson Calero
 

Ähnlich wie Understanding How is that Adaptive Cursor Sharing (ACS) produces multiple Optimal Plans (20)

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...
 
Combining ACS Flexibility with SPM Stability
Combining ACS Flexibility with SPM StabilityCombining ACS Flexibility with SPM Stability
Combining ACS Flexibility with SPM Stability
 
Using SQL Plan Management (SPM) to balance Plan Flexibility and Plan Stability
Using SQL Plan Management (SPM) to balance Plan Flexibility and Plan StabilityUsing SQL Plan Management (SPM) to balance Plan Flexibility and Plan Stability
Using SQL Plan Management (SPM) to balance Plan Flexibility and Plan Stability
 
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
 
Macy's: Changing Engines in Mid-Flight
Macy's: Changing Engines in Mid-FlightMacy's: Changing Engines in Mid-Flight
Macy's: Changing Engines in Mid-Flight
 
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
 
sqltuning101-170419021007-2.pdf
sqltuning101-170419021007-2.pdfsqltuning101-170419021007-2.pdf
sqltuning101-170419021007-2.pdf
 
Meeting the challenges of OLTP Big Data with Scylla
Meeting the challenges of OLTP Big Data with ScyllaMeeting the challenges of OLTP Big Data with Scylla
Meeting the challenges of OLTP Big Data with Scylla
 
Embarcadero In Search of Plan Stability Part 1 Webinar Slides
Embarcadero In Search of Plan Stability Part 1 Webinar SlidesEmbarcadero In Search of Plan Stability Part 1 Webinar Slides
Embarcadero In Search of Plan Stability Part 1 Webinar Slides
 
Using adaptive cursor sharing (acs) to produce multiple optimal plans v2
Using adaptive cursor sharing (acs) to produce multiple optimal plans v2Using adaptive cursor sharing (acs) to produce multiple optimal plans v2
Using adaptive cursor sharing (acs) to produce multiple optimal plans v2
 
Windows Azure: Lessons From the Field
Windows Azure: Lessons From the FieldWindows Azure: Lessons From the Field
Windows Azure: Lessons From the Field
 
261197832 8-performance-tuning-part i
261197832 8-performance-tuning-part i261197832 8-performance-tuning-part i
261197832 8-performance-tuning-part i
 
Fast federated SQL with Apache Calcite
Fast federated SQL with Apache CalciteFast federated SQL with Apache Calcite
Fast federated SQL with Apache Calcite
 
Mutant Tests Too: The SQL
Mutant Tests Too: The SQLMutant Tests Too: The SQL
Mutant Tests Too: The SQL
 
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
 
Introducing the eDB360 Tool
Introducing the eDB360 ToolIntroducing the eDB360 Tool
Introducing the eDB360 Tool
 
Big Data, Bigger Analytics
Big Data, Bigger AnalyticsBig Data, Bigger Analytics
Big Data, Bigger Analytics
 
Introduction 6.1 01_architecture_overview
Introduction 6.1 01_architecture_overviewIntroduction 6.1 01_architecture_overview
Introduction 6.1 01_architecture_overview
 
Dealing with the Three Horrible Problems in Verification
Dealing with the Three Horrible Problems in VerificationDealing with the Three Horrible Problems in Verification
Dealing with the Three Horrible Problems in Verification
 
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...
 

Kürzlich hochgeladen

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 

Kürzlich hochgeladen (20)

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 

Understanding How is that Adaptive Cursor Sharing (ACS) produces multiple Optimal Plans

  • 1. Understanding how is that Adaptive Cursor Sharing (ACS) produces multiple Optimal Plans Carlos Sierra
  • 2. Carlos Sierra • SQLTXPLAIN + SQL Health-Check SQLHC + • Consultant/Developer/DBA/Design/+ • Oracle Performance + SQL Tuning • Oracle Database Health-Check • Tools + Scripts • Speaker Enkitec (c) 2014 2
  • 3. Topics • Motivation • Adaptive Cursor Sharing (ACS) – Mechanics – Demos Enkitec (c) 2014 3
  • 4. Plan Flexibility Allies • CBO Parameters • CBO Statistics • Dynamic Sampling • Cardinality Feedback • Cursor Sharing • Adaptive Cursor Sharing (ACS) Enkitec (c) 2014 4
  • 5. Plan Stability Tools • CBO Hints • Stored Outlines • SQL Profiles • SQL Plan Management (SPM) Enkitec (c) 2014 5
  • 6. Flexibility versus Stability • Flexible Plans adapt as Data evolves over Time • Performance of Stable Plans is more Predictable • But, you can't eat your cake and have it (too)… • Can we balance Flexibility and Stability??? Enkitec (c) 2014 6
  • 7. Cursor Sharing Review • Use of Bind Variables instead of Literals – AND c.car_maker = ‘Ford’ – AND c.car_maker = :b1 • Goal: Reduce Hard Parsing – Improve Scalability • Reduce CPU utilization • Reduce Shared Memory footprint Enkitec (c) 2014 7
  • 8. Cursor Sharing Shortcomings • Flipping Plans – Exacerbated by Histograms on Skewed Data – AND c.car_maker = :b2 • :b2 := ‘Ford’ • :b2 := ‘Lotus’ – Plan is computed at hard parse • Plan performance becomes a moving target Enkitec (c) 2014 8
  • 9. Adaptive Cursor Sharing (ACS) • Available on 11g+ • Offers Multiple Optimal Plans per SQL – As per “Selectivity” of Predicates • :b2 := ‘Ford’ (many rows) • :b2 := ‘Lotus’ (fewer rows) • Works well with SQL Plan Management Enkitec (c) 2014 9
  • 10. ACS Challenges • Strategy – Minimize Resources Impact • Implementation – Monitor only a subset of SQL Statements – Activate ACS only for a subset of the monitored SQL – Share Executions Plans through a “Selectivity Profile” Enkitec (c) 2014 10
  • 11. Cursors State • Bind Sensitive – A subset of Cursors are Bind Sensitive • Bind Aware – A subset of Bind Sensitive Cursors become Bind Aware Enkitec (c) 2014 11 All Statements Bind Sensitive Bind Aware ACS
  • 12. Becoming Bind Sensitive 1. SQL has Range Predicates on Bind Variables – AND c.cust_year_of_birth BETWEEN :b3 AND :b4 – AND p.prod_category LIKE :b5 2. SQL has Equality Predicates on Bind Variables and Column has a Histogram – AND c.cust_marital_status = :b2 – AND TO_CHAR(s.time_id, 'YYYY') = :b6 Enkitec (c) 2014 12
  • 13. Becoming Bind Aware 1. Rows Processed change substantially between Executions – Between a few rows to millions 2. Rows Processed oscillate significantly between Executions – Between a few rows and a few thousand – Between a few thousand and millions Enkitec (c) 2014 13
  • 14. ACS Dynamic Views • V$SQL (Cursor State) – is_shareable (Y/N) – is_bind_sensitive (Y/N) – is_bind_aware (Y/N) • V$SQL_CS_STATISTICS (Rows Processed) • V$SQL_CS_HISTOGRAM (3 Buckets S/M/L) • V$SQL_CS_SELECTIVITY (Selectivity Profile) Enkitec (c) 2014 14
  • 15. Rows Processed • v$sql_cs_statistics.rows_processed • Updated only at hard parse • A measure of amount of work on Execution Plan • Three sizes: S/M/L – 0: Small – 1: Medium – 2: Large Enkitec (c) 2014 15
  • 16. Rows Processed • v$sql_cs_statistics.rows_processed • Updated only at hard parse • A measure of amount of work on Execution Plan • Three sizes: S/M/L (undocumented boundaries) – 0: Small (less than 1K rows) – 1: Medium (between 1k and 1m rows) – 2: Large (more than 1m rows) Enkitec (c) 2014 16
  • 17. ACS Buckets • v$sql_cs_histogram.bucket_id – 0: Small – 1: Medium – 2: Large • v$sql_cs_histogram.count – Incremented with each Execution as per • v$sql_cs_statistics.rows_processed Enkitec (c) 2014 17
  • 18. Rows Processed and ACS Buckets IF v$sql_cs_statistics.rows_processed < 1K THEN v$sql_cs_histogram.count(0)++ ELSIF v$sql_cs_statistics.rows_processed < 1M THEN v$sql_cs_histogram.count(1)++ ELSE v$sql_cs_histogram.count(2)++ END IF Enkitec (c) 2014 18
  • 19. Becoming Bind Aware 1. Small and Large buckets have a value – bucket_id.count(0) > 0 AND bucket_id.count(2) > 0 2. Two adjacent buckets have same non-zero value – bucket_id.count(0) = bucket_id.count(1) > 0 – bucket_id.count(1) = bucket_id.count(2) > 0 Enkitec (c) 2014 19
  • 20. Rows Processed per Execution • rows_processed(bucket_id)… Bind Aware(BA) • 10(0)… 50(0)… 3,000,000(2)… BA • 30(0)… 3,000(1)… BA • 2,000,000(2)… 1(0)… BA • 0(0)… 10,000(1)… BA • 3,000(1)… 2,000(1)… 200(0)… 300(0)… BA • 10… 100… 500… 2,000… 3,000… 5,000… BA Enkitec (c) 2014 20
  • 21. WHY becoming BA is important? • Multiple Optimal Plans are created after Cursor becomes Bind Aware Enkitec (c) 2014 21
  • 22. Recap • V$SQL_CS_STATISTICS (Rows Processed) – Bind Sensitive Cursors determine which bucket should be incremented according to actual rows processed • V$SQL_CS_HISTOGRAM (3 Buckets S/M/L) – Bind Sensitive Cursors increase count (+1) of respective bucket at the end of each execution • V$SQL_CS_SELECTIVITY (Selectivity Profile) – Bind Aware Cursors maintain this “Selectivity” Data Structure – To determine which Cursor (Plan) to use on each execution Enkitec (c) 2014 22
  • 23. Sample Query (1) SELECT p.prod_subcategory_desc subcatagory, SUM(amount_sold) amount_sold FROM sh.customers c, sh.products p, sh.sales s WHERE c.cust_gender = 'M' AND c.cust_marital_status = 'single' AND c.cust_year_of_birth BETWEEN 1913 AND 1990 AND p.prod_category LIKE 'Software%' AND TO_CHAR(s.time_id, 'YYYY') = '2001' AND s.cust_id = c.cust_id AND s.prod_id = p.prod_id GROUP BY p.prod_subcategory_desc ORDER BY p.prod_subcategory_desc; Enkitec (c) 2014 23
  • 24. Sample Query (2) • Based on Sample Schema SH – With CBO Histograms in all Columns • Not a requirement for this ACS test • 3 Tables with Filter Predicates • 2 Joins • 6 possible Join Orders • Several possible Execution Plans Enkitec (c) 2014 24
  • 25. Demo 1 • 5 Executions of Sample Query using Literals – Different values for each Execution • Sequence 1, 2, 3, 4 and 5 – Each Execution performs a Hard Parse – Each Execution computes a “new” Plan – Each seems to be an “Optimal” Plan Enkitec (c) 2014 25
  • 26. Demo 2 • 5 Executions of Sample Query using Binds – Different values for each Execution • Sequence 1, 2, 3, 4 and 5 – Each Execution performs a Hard Parse • Forced with a Cursor Flush before the Execution – Each computes a “new” Optimal Plan • Almost same as “with Literals” Enkitec (c) 2014 26
  • 27. Demo 2 Results Query Rows Processed ACS Bucket Plan Hash Value 1 1,483,124 2 2048551027 2 1,280,074 2 3600618656 3 1,017,774 2 189372815 4 2,770 1 847574763 5 3,132 1 847574763 Enkitec (c) 2014 27
  • 28. Demo 3 • 5 Executions of Sample Query using Binds – Different values for each Execution • Sequence 1, 2, 3, 4 and 5 – No Cursor Flush between Executions – First Execution computes a “new” Optimal Plan – All Executions use same Plan… Enkitec (c) 2014 28
  • 29. Demo 3 Results Query Rows Processed ACS Bucket Optimal Plan ACS Aware Executed 1 1,483,124 2 2048551027 N 2048551027 2 1,280,074 (~1.2M) 2 3600618656 N 2048551027 3 1,017,774 (~1.2M) 2 189372815 N 2048551027 4 2,770 (~526K ) 1 847574763 N 2048551027 5 3,132 (~50) 1 (0) 847574763 N 2048551027 Enkitec (c) 2014 29
  • 30. Demo 4 • 5 Executions of Sample Query using Binds – Different values for each Execution • Sequence 5, 4, 3, 2 and 1 – No Cursor Flush between Executions – Cursor becomes Bind Aware after 2nd Execution – All Executions used an Optimal Plan Enkitec (c) 2014 30
  • 31. Demo 4 Results Query Rows Processed ACS Bucket Optimal Plan Bind Aware Executed 5 3,132 1 847574763 N 847574763 4 2,770 1 847574763 N 847574763 3 1,017,774 (~130K) 2 (1) 189372815 N 847574763 2 1,280,074 (~241K) 2 (1) 3600618656 N 847574763 1 1,483,124 (~1.7M) 2 2048551027 N 847574763 Enkitec (c) 2014 31
  • 32. Demo 5 • 5 Executions of Sample Query using Binds – Different values for each Execution • Sequence 5, 1, 2, 3 and 4 – No Cursor Flush between Executions – Cursor becomes Bind Aware after 2nd Execution – All but one Executions used an Optimal Plan Enkitec (c) 2014 32
  • 33. Demo 5 Results Query Rows Processed ACS Bucket Optimal Plan Bind Aware Executed 5 3,132 1 847574763 N 847574763 1 1,483,124 (1.7M) 2 2048551027 N 847574763 2 1,280,074 2 3600618656 Y 3600618656 3 1,017,774 2 189372815 Y 189372815 4 2,770 1 847574763 Y 847574763 Enkitec (c) 2014 33
  • 34. What is the Problem? • Ramp-up Process may lead to some suboptimal Executions – Sensitive to sequence of values passed… • Kind of a Learning Curve… – Can we override it? Enkitec (c) 2014 34
  • 35. Controlling ACS with CBO Hint • /*+ BIND_AWARE */ – Bypasses the monitoring phase of a Bind Sensitive SQL • /*+ NO_BIND_AWARE */ – Turns off ACS for given SQL Enkitec (c) 2014 35
  • 36. Controlling ACS with SQL Patch • SYS.DBMS_SQLDIAG_INTERNAL.I_CREATE_PATCH – sql_text – hint_text => BIND_AWARE • Script sqlpch.sql connected as SYS – SQL_ID • 8u0n7w1jug5dg • Test Demo 5… Enkitec (c) 2014 36
  • 37. ACS Plan Selection • On every Execution of Bind Aware Cursor – Compute Selectivity of each qualifying Predicate – Search Selectivity within Range of values on ACS Selectivity Profile – If within Range, lookup Child Number and use its Plan – Else, Hard Parse and Execute newly computed Plan • If same as existing Plan, then update Selectivity Profile • Else, create Selectivity Profile for new Child Number Enkitec (c) 2014 37
  • 38. Selectivity Profile (1) • v$sql_cs_selectivity – predicate – range_id • low and high (selectivities) – child_number Enkitec (c) 2014 38
  • 39. Selectivity Profile (2) CHILD PREDICATE RANGE_ID LOW HIGH ----------- ---------- ----------- ---------- ---------- 1 <=B4 0 0.860941 1.052262 1 =B1 0 0.602369 0.736229 1 =B2 0 0.455337 0.556523 1 >=B3 0 0.182445 0.222988 1 B5 0 0.306250 0.374306 2 <=B4 0 0.892666 1.091036 2 =B1 0 0.297574 0.363702 2 =B2 0 0.455337 0.556523 2 >=B3 0 0.077947 0.095268 2 B5 0 0.306250 0.374306 3 <=B4 0 0.836835 1.022798 3 =B1 0 0.297574 0.363702 3 =B2 0 0.002085 0.002548 3 >=B3 0 0.221447 0.270657 3 B5 0 0.306250 0.374306 Enkitec (c) 2014 39
  • 40. ACS Summary • ACS is capable of producing multiple Optimal Execution Plans per SQL • During ramp-up sub Optimal Plans may happen • ACS Metadata resides in Memory (not Persistent) • ACS provides desirable Plan Flexibility • ACS does not address the Plan Stability concern Enkitec (c) 2014 40
  • 41. ACS Suggested Strategy • Use sys.dbms_sqldiag_internal.i_create_patch to SQL Patch with BIND_AWARE the SQL on Baselines • Use free script sqlpch.sql Enkitec (c) 2014 41
  • 42. References (1) • Using SQL Patch to add hints to a packaged application – https://blogs.oracle.com/optimizer/entry/how_can_i_h int_a • Skipping ACS ramp-up using a SQL Patch – http://carlos-sierra.net/2014/06/19/skipping-acs-ramp- up-using-a-sql-patch/ Enkitec (c) 2014 42
  • 43. References (2) • Oracle® Database PL/SQL Packages and Types Reference – 11g Release 2 (11.2) – Part Number E25788-04 Enkitec (c) 2014 43
  • 44. Contact Information • carlos.sierra@enkitec.com • carlos-sierra.net • @csierra_usa Enkitec (c) 2014 44