SlideShare a Scribd company logo
Using Adaptive Cursor Sharing (ACS) to
produce multiple Optimal Plans
Carlos Sierra
Carlos Sierra
Senior Technical Consultant at Enkitec
§  SQL Tuner handyman: developer, advisor, trainer, support
§  IT: Enkitec (<0.2), Oracle(17), UNISYS(12), Ford(3), others(3)
§  Florida(17), Venezuela(3), Puerto Rico(6), Michigan(1), Mexico(x)
§  Tools: SQLTXPLAIN(SQLT), SQLHC, TRCANLZR(TRCA), others
§  Motto: Life’s Good!

2
Adaptive Cursor Sharing (ACS)
§  Motivation
§  Mechanics
§  Test Case
§  Demo
§  Remarks

3
ACS Motivation
SQL Processing
Hard parsing is expensive!
§  Hard parse side effects
–  CPU consumption
–  Latch contention

§  Excessive hard parsing
–  Affects concurrency
–  Restricts scalability

§  Mitigating hard parsing
–  Cursor sharing

5
Implementing Cursor Sharing
Replacing literals with bind variables

6
Before Bind Peeking
Before 9i CBO was blind to values passed
§  Predicate
–  WHERE channel_id = :b1

§  Unknowns
–  Is :b1 between low and high values of channel_id?
–  Is :b1 a popular value of channel_id?
–  Are there any rows with value :b1 for channel_id?

§  Penalty
–  Possible suboptimal plans

7
With Bind Peeking
9i offers a partial solution
§  Predicate
–  WHERE channel_id = :b1

§  Plan is determined by peeked values
–  EXEC :b1 := 9;

§  Optimal plan for 1st execution
–  CBO can use low/high and histograms on channel_id

§  Penalty
–  Possible suboptimal plans for subsequent executions on skewed data
8
Real-life Problem with Bind Peeking
People Soft Payroll Application
§  WHERE employee BETWEEN :b1 AND :b2
§  Payroll for one employee
–  :b1 = 123456
–  :b2 = 123456

§  Payroll for one company
–  :b1 = 000001
–  :b2 = 999999

§  Doing payroll for an employee first then entire company
9
With Adaptive Cursor Sharing
11g improves cursor sharing
§  Some queries are ACS candidates
§  Sophisticated non-persistent mechanism
§  Selectivity of predicates determine plan
§  Multiple optimal plans for a query!
–  If ACS is successfully applied

§  Penalty
–  Marginal increase in CPU and memory overhead

10
ACS Mechanics
ACS high-level Overview
High level overview
§  If SQL with binds meets some requirements
–  Flag cursor as bind sensitive
–  Start monitoring data volume manipulated by cursor

§  If bind sensitive and data volume manipulated by cursor varies

significantly
–  Flag cursor as bind aware
–  Start generating multiple optimal plans for this query on next hard parse

§  If bind aware then use selectivity of predicates to decide on plan
12
Bind Sensitive
Minimum requirements
§  SQL has explicit binds
–  Or literals and cursor_sharing is “force”

§  Predicate: column + operand + bind_variable
–  Equality operand “=“ and histogram on column
§  Ex: channel_id = :b1

–  Non-equality operand (range) regardless of histogram on column
§  “>”, “>=“, “<“, ‘<=“, BETWEEN, LIKE

13
Bind Aware
How to become bind aware?
§  Significant changes in data volume manipulated by cursor
–  A few rows versus a few thousands of rows
–  A few thousands of rows versus a few millions of rows

§  Specifying /*+ BIND_AWARE */ CBO Hint
–  Bypasses the monitoring phase on data volume

14
Plan Selection
Based on selectivity profile of predicates
§  Evaluate selectivity of predicates at soft parse
§  Compare to a non-persistent selectivity profile
§  If within ranges of a known profile then select associated plan
§  Else hard parse
–  Compute and execute newly generated plan
–  Create selectivity profile for new plan or update profile of existing plan

§  If ranges on selectivity profiles overlap then merge profiles

15
V$ dynamic views for ACS
ACS non-persistent performance views
§  V$SQL
–  Shareable, bind sensitive and bind aware flags

§  V$SQL_CS_STATISTICS
–  Data volume manipulated (rows processed)

§  V$SQL_CS_HISTOGRAM
–  Record keeping of data volume per execution (small, medium, large)

§  V$SQL_CS_SELECTIVITY
–  Predicates selectivity profiles
16
ACS Test Case
Our Query with Literals
Guesstimate execution plan then verify it with demo 0

18
Possible Access Paths?

19
Optimal Execution Plan

20
Our Query with Bind Variables
How many optimal execution plans can you foresee?

21
Multiple Optimal Plans for one Query
Guesstimate optimal plan (access paths) for each query

Query

:b1

:b2

AP1

AP2

q1

9

33

N1

N2

q2

5

32

q3

2

999

q4

9

999

q5

2

33

22
Multiple Optimal Plans for one Query
Guesstimate optimal plan (access paths) for each query

Query

:b1

:b2

AP1

AP2

q1

9

33

N1

N2

q2

5

32

N1

N2

q3

2

999

FTS

FTS

q4

9

999

N1

FTS

q5

2

33

FTS

N2

23
Multiple Optimal Plans for one Query
Execute demos 1-5 and verify access paths

Query

:b1

:b2

AP1

AP2

q1

9

33

N1

N2

q2

5

32

N1

N2

q3

2

999

FTS

FTS

q4

9

999

N1

FTS

q5

2

33

FTS

N2

24
Bind Sensitive: Rows Processed
Monitor v$sql_cs_statistics.rows_processed
§  Data volume manipulated
–  Fuzzy representation
–  S: few rows
–  M: thousands or rows
–  L: millions of rows

§  v$sql_cs_histogram
–  Bucket(0): S
–  Bucket(1): M
–  Bucket(2): L

Rows
Processed

Query

:b1

:b2

Optimal

q1

9

33

N1/N2

37,382

q2

5

32

N1/N2

2

q3

2

999 FTS/FTS

8,021,324

q4

9

999

N1/FTS

6,233,815

q5

2

33

FTS/N2

1,825,131
25
ACS Demo
Demo 6: When Cursor becomes Bind Aware?
Obtain rows processed from demo 1-5 then guesstimate aware flag
Rows
Processed

Query

:b1

:b2

Optimal

Bucket

q1

9

33

N1/N2

37,382

q2

5

32

N1/N2

2

q3

2

999 FTS/FTS

8,021,324

q4

9

999

N1/FTS

6,233,815

q5

2

33

FTS/N2

Aware

Child

Actual

1,825,131

27
Demo 6: When Cursor becomes Bind Aware?
Obtain rows processed from demo 1-5 then guesstimate aware flag
Rows
Processed

Query

:b1

:b2

Optimal

Bucket

q1

9

33

N1/N2

37,382

1

q2

5

32

N1/N2

2

0

q3

2

999 FTS/FTS

8,021,324

2

q4

9

999

N1/FTS

6,233,815

2

q5

2

33

FTS/N2

1,825,131

Aware

Child

Actual

2

28
Demo 6: When Cursor becomes Bind Aware?
Obtain rows processed from demo 1-5 then guesstimate aware flag

Query

:b1

:b2

Optimal

q1

9

33

N1/N2

q2

5

32

N1/N2

q3

2

q4
q5

Rows
Processed

Bucket

Aware

37,382

1

N

2

0

N

999 FTS/FTS

8,021,324

2

Y

9

999

N1/FTS

6,233,815

2

Y

2

33

FTS/N2

1,825,131

2

Child

Actual

Y

29
Demo 6: When Cursor becomes Bind Aware?
Obtain rows processed from demo 1-5 then guesstimate aware flag

Query

:b1

:b2

Optimal

q1

9

33

N1/N2

q2

5

32

N1/N2

q3

2

q4
q5

Rows
Processed

Bucket

Aware

Child

Actual

37,382

1

N

0

N1/N2

2

0

N

0

N1/N2

999 FTS/FTS

8,021,324

2

Y

1

FTS/FTS

9

999

N1/FTS

6,233,815

2

Y

2

N1/FTS

2

33

FTS/N2

1,825,131

2

Y

3

FTS/N2

30
Demo 6: When Cursor becomes Bind Aware?
Obtain rows processed from demo 1-5 then guesstimate aware flag

Query

:b1

:b2

Optimal

q1

9

33

N1/N2

q2

5

32

N1/N2

q3

2

q4
q5

Rows
Processed

Bucket

Aware

Child

Actual

37,382

1

N

0

N1/N2

2

0

N

0

N1/N2

999 FTS/FTS

8,021,324

2

Y

1

FTS/FTS

9

999

N1/FTS

6,233,815

2

Y

2

N1/FTS

2

33

FTS/N2

1,825,131

2

Y

3

FTS/N2

31
Demo 7: When Cursor becomes Bind Aware?
Compute bucket and guesstimate aware flag and actual plan
Rows
Processed

Query

:b1

:b2

Optimal

Bucket

q5

2

33

FTS/N2

1,825,131

q4

9

999

N1/FTS

6,233,815

q3

2

999 FTS/FTS

q2

5

32

N1/N2

2

q1

9

33

N1/N2

Aware

Child

Actual

37,382

8,021,324

32
Demo 7: When Cursor becomes Bind Aware?
Compute bucket and guesstimate aware flag and actual plan
Rows
Processed

Query

:b1

:b2

Optimal

Bucket

q5

2

33

FTS/N2

1,825,131

2

q4

9

999

N1/FTS

6,233,815

2

q3

2

999 FTS/FTS

8,021,324

2

q2

5

32

N1/N2

2

0

q1

9

33

N1/N2

37,382

Aware

Child

Actual

1

33
Demo 7: When Cursor becomes Bind Aware?
Compute bucket and guesstimate aware flag and actual plan

Query

:b1

:b2

Optimal

q5

2

33

FTS/N2

q4

9

999

N1/FTS

q3

2

999 FTS/FTS

q2

5

32

q1

9

33

Rows
Processed

Bucket

Aware

1,825,131

2

N

6,233,815

2

N

8,021,324

2

N

N1/N2

2

0

N

N1/N2

37,382

1

Child

Actual

Y

34
Demo 7: When Cursor becomes Bind Aware?
Compute bucket and guesstimate aware flag and actual plan

Query

:b1

:b2

Optimal

q5

2

33

FTS/N2

q4

9

999

N1/FTS

q3

2

999 FTS/FTS

q2

5

32

q1

9

33

Rows
Processed

Bucket

Aware

Child

Actual

1,825,131

2

N

0

FTS/N2

6,233,815

2

N

0

FTS/N2

8,021,324

2

N

0

FTS/N2

N1/N2

2

0

N

0

FTS/N2

N1/N2

37,382

1

Y

1

N1/N2

35
Demo 7: When Cursor becomes Bind Aware?
Compute bucket and guesstimate aware flag and actual plan

Query

:b1

:b2

Optimal

q5

2

33

FTS/N2

q4

9

999

N1/FTS

q3

2

999 FTS/FTS

q2

5

32

q1

9

33

Rows
Processed

Bucket

Aware

Child

Actual

1,825,131

2

N

0

FTS/N2

6,233,815

2

N

0

FTS/N2

8,021,324

2

N

0

FTS/N2

N1/N2

2

0

N

0

FTS/N2

N1/N2

37,382

1

Y

1

N1/N2

36
Demo 8: When Cursor becomes Bind Aware?
Guesstimate aware flag and actual plan
Rows
Processed

Query

:b1

:b2

Optimal

Bucket

q5

2

33

FTS/N2

1,825,131

2

q4

9

999

N1/FTS

6,233,815

2

q3

2

999 FTS/FTS

8,021,324

2

q1

9

33

N1/N2

37,382

1

q2

5

32

N1/N2

2

Aware

Child

Actual

0

37
Demo 8: When Cursor becomes Bind Aware?
Guesstimate aware flag and actual plan

Query

:b1

:b2

Optimal

q5

2

33

FTS/N2

q4

9

999

N1/FTS

q3

2

999 FTS/FTS

q1

9

33

q2

5

32

Rows
Processed

Bucket

Aware

1,825,131

2

N

6,233,815

2

N

8,021,324

2

N

N1/N2

37,382

1

N

N1/N2

2

0

Child

Actual

N

38
Demo 8: When Cursor becomes Bind Aware?
Guesstimate aware flag and actual plan

Query

:b1

:b2

Optimal

q5

2

33

FTS/N2

q4

9

999

N1/FTS

q3

2

999 FTS/FTS

q1

9

33

q2

5

32

Rows
Processed

Bucket

Aware

Child

Actual

1,825,131

2

N

0

FTS/N2

6,233,815

2

N

0

FTS/N2

8,021,324

2

N

0

FTS/N2

N1/N2

37,382

1

N

0

FTS/N2

N1/N2

2

0

N

0

FTS/N2

39
Demo 8: When Cursor becomes Bind Aware?
Guesstimate aware flag and actual plan

Query

:b1

:b2

Optimal

q5

2

33

FTS/N2

q4

9

999

N1/FTS

q3

2

999 FTS/FTS

q1

9

33

q2

5

32

Rows
Processed

Bucket

Aware

Child

Actual

1,825,131

2

N

0

FTS/N2

6,233,815

2

N

0

FTS/N2

8,021,324

2

N

0

FTS/N2

N1/N2

37,382

1

N

0

FTS/N2

N1/N2

2

0

N

0

FTS/N2

40
Real-life Problem with ACS
People Soft Payroll Application
§  WHERE employee BETWEEN :b1 AND :b2
§  Payroll for one employee
–  :b1 = 123456
–  :b2 = 123456

§  Payroll for one company
–  :b1 = 000001
–  :b2 = 999999

§  Doing payroll for a few employees first then entire company
41
Closing Remarks
Understanding Selectivity Profile
From demo 6

Query

:b1

:b2

Child

q3

2

999

1

q4

9

999

2

q5

2

33

3
43
Understanding Selectivity Profile
From demo 6

Query

:b1

:b2

Child

q3

2

999

1

q4

9

999

2

q5

2

33

3
44
Understanding Selectivity Profile
From demo 6

Query

:b1

:b2

Child

q3

2

999

1

q4

9

999

2

q5

2

33

3
45
Remarks on Bind Sensitivity
Based on experimental observation
§  Monitor V$SQL_CS_STATISTICS.rows_processed
–  If small number of rows then
§  V$SQL_CS_HISTOGRAM.bucket_id(0)++

–  If medium number of rows then
§  V$SQL_CS_HISTOGRAM.bucket_id(1)++

–  If large number of rows then
§  V$SQL_CS_HISTOGRAM.bucket_id(2)++

46
Remarks on Bind Aware
Based on experimental observation
§  Some cases where cursor may become bind aware
–  bucket_id(0) = bucket_id(1) > 0
–  bucket_id(1) = bucket_id(2) > 0
–  bucket_id(0) > 0 and bucket_id(2) > 0

§  Or use /*+ BIND_AWARE */ CBO Hint
–  What if we cannot modify code?

47
Conclusions
ACS can produce multiple optimal plans for one query
§  ACS only applies to a subset of queries with binds
§  ACS requires a ramp-up process (few executions)
§  In some cases cursor may fail to become bind aware
§  To force a cursor become bind aware use CBO Hint
§  ACS is not persistent
§  ACS works well with SQL Plan Management

48
Give Away
Script sqlt/utl/coe_gen_sql_patch.sql (MOS 215187.1)
§  Creates a SQL Patch for one SQL_ID
§  Turns “on” EVENT 10053 for SQL_ID
§  Hints on SQL Patch
–  GATHER_PLAN_STATISTICS
–  MONITOR
–  BIND_AWARE

§  Consider using and customizing this free script

49
References and Contact Info
Oracle Optimizer Blog
§  https://blogs.oracle.com/optimizer/
–  Insight into the workings of the Optimizer

§  carlos.sierra@enkitec.com
§  http://carlos-sierra.net
§  @csierra_usa

50
Using adaptive cursor sharing (acs) to produce multiple optimal plans v2

More Related Content

Similar to Using adaptive cursor sharing (acs) to produce multiple optimal plans v2

APAC ksqlDB Workshop
APAC ksqlDB WorkshopAPAC ksqlDB Workshop
APAC ksqlDB Workshop
confluent
 
Mutant Tests Too: The SQL
Mutant Tests Too: The SQLMutant Tests Too: The SQL
Mutant Tests Too: The SQL
DataWorks Summit
 
Compiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow AnalysisCompiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow Analysis
Eelco Visser
 
Web Service Composition as a Planning Task: Experiments using Knowledge-Based...
Web Service Composition as a Planning Task: Experiments using Knowledge-Based...Web Service Composition as a Planning Task: Experiments using Knowledge-Based...
Web Service Composition as a Planning Task: Experiments using Knowledge-Based...
Erick Ornio
 
Oracle Database In-Memory Option in Action
Oracle Database In-Memory Option in ActionOracle Database In-Memory Option in Action
Oracle Database In-Memory Option in Action
Tanel Poder
 
In Memory Database In Action by Tanel Poder and Kerry Osborne
In Memory Database In Action by Tanel Poder and Kerry OsborneIn Memory Database In Action by Tanel Poder and Kerry Osborne
In Memory Database In Action by Tanel Poder and Kerry Osborne
Enkitec
 
Combining ACS Flexibility with SPM Stability
Combining ACS Flexibility with SPM StabilityCombining ACS Flexibility with SPM Stability
Combining ACS Flexibility with SPM StabilityEnkitec
 
Deep Dive of ADBMS Migration to Apache Spark—Use Cases Sharing
Deep Dive of ADBMS Migration to Apache Spark—Use Cases SharingDeep Dive of ADBMS Migration to Apache Spark—Use Cases Sharing
Deep Dive of ADBMS Migration to Apache Spark—Use Cases Sharing
Databricks
 
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
 
Introduction 6.1 01_architecture_overview
Introduction 6.1 01_architecture_overviewIntroduction 6.1 01_architecture_overview
Introduction 6.1 01_architecture_overview
Anvith S. Upadhyaya
 
Chicago Kafka Meetup
Chicago Kafka MeetupChicago Kafka Meetup
Chicago Kafka Meetup
Cliff Gilmore
 
Changing landscapes in data integration - Kafka Connect for near real-time da...
Changing landscapes in data integration - Kafka Connect for near real-time da...Changing landscapes in data integration - Kafka Connect for near real-time da...
Changing landscapes in data integration - Kafka Connect for near real-time da...
HostedbyConfluent
 
Couchbase 5.5: N1QL and Indexing features
Couchbase 5.5: N1QL and Indexing featuresCouchbase 5.5: N1QL and Indexing features
Couchbase 5.5: N1QL and Indexing features
Keshav Murthy
 
How to use Impala query plan and profile to fix performance issues
How to use Impala query plan and profile to fix performance issuesHow to use Impala query plan and profile to fix performance issues
How to use Impala query plan and profile to fix performance issues
Cloudera, Inc.
 
Static analysis of java enterprise applications
Static analysis of java enterprise applicationsStatic analysis of java enterprise applications
Static analysis of java enterprise applications
Anastasiοs Antoniadis
 
Things YouShould Be Doing When Using Cassandra Drivers
Things YouShould Be Doing When Using Cassandra DriversThings YouShould Be Doing When Using Cassandra Drivers
Things YouShould Be Doing When Using Cassandra Drivers
Rebecca Mills
 
Parallel Tuning of Machine Learning Algorithms, Thesis Proposal
Parallel Tuning of Machine Learning Algorithms, Thesis ProposalParallel Tuning of Machine Learning Algorithms, Thesis Proposal
Parallel Tuning of Machine Learning Algorithms, Thesis ProposalGianmario Spacagna
 
Streams Don't Fail Me Now - Robustness Features in Kafka Streams
Streams Don't Fail Me Now - Robustness Features in Kafka StreamsStreams Don't Fail Me Now - Robustness Features in Kafka Streams
Streams Don't Fail Me Now - Robustness Features in Kafka Streams
HostedbyConfluent
 
Towards Dynamic Consistency Checking in Goal-directed Predicate Answer Set Pr...
Towards Dynamic Consistency Checking in Goal-directed Predicate Answer Set Pr...Towards Dynamic Consistency Checking in Goal-directed Predicate Answer Set Pr...
Towards Dynamic Consistency Checking in Goal-directed Predicate Answer Set Pr...
Universidad Rey Juan Carlos
 
Cassandra Tools and Distributed Administration (Jeffrey Berger, Knewton) | C*...
Cassandra Tools and Distributed Administration (Jeffrey Berger, Knewton) | C*...Cassandra Tools and Distributed Administration (Jeffrey Berger, Knewton) | C*...
Cassandra Tools and Distributed Administration (Jeffrey Berger, Knewton) | C*...
DataStax
 

Similar to Using adaptive cursor sharing (acs) to produce multiple optimal plans v2 (20)

APAC ksqlDB Workshop
APAC ksqlDB WorkshopAPAC ksqlDB Workshop
APAC ksqlDB Workshop
 
Mutant Tests Too: The SQL
Mutant Tests Too: The SQLMutant Tests Too: The SQL
Mutant Tests Too: The SQL
 
Compiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow AnalysisCompiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow Analysis
 
Web Service Composition as a Planning Task: Experiments using Knowledge-Based...
Web Service Composition as a Planning Task: Experiments using Knowledge-Based...Web Service Composition as a Planning Task: Experiments using Knowledge-Based...
Web Service Composition as a Planning Task: Experiments using Knowledge-Based...
 
Oracle Database In-Memory Option in Action
Oracle Database In-Memory Option in ActionOracle Database In-Memory Option in Action
Oracle Database In-Memory Option in Action
 
In Memory Database In Action by Tanel Poder and Kerry Osborne
In Memory Database In Action by Tanel Poder and Kerry OsborneIn Memory Database In Action by Tanel Poder and Kerry Osborne
In Memory Database In Action by Tanel Poder and Kerry Osborne
 
Combining ACS Flexibility with SPM Stability
Combining ACS Flexibility with SPM StabilityCombining ACS Flexibility with SPM Stability
Combining ACS Flexibility with SPM Stability
 
Deep Dive of ADBMS Migration to Apache Spark—Use Cases Sharing
Deep Dive of ADBMS Migration to Apache Spark—Use Cases SharingDeep Dive of ADBMS Migration to Apache Spark—Use Cases Sharing
Deep Dive of ADBMS Migration to Apache Spark—Use Cases Sharing
 
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
 
Introduction 6.1 01_architecture_overview
Introduction 6.1 01_architecture_overviewIntroduction 6.1 01_architecture_overview
Introduction 6.1 01_architecture_overview
 
Chicago Kafka Meetup
Chicago Kafka MeetupChicago Kafka Meetup
Chicago Kafka Meetup
 
Changing landscapes in data integration - Kafka Connect for near real-time da...
Changing landscapes in data integration - Kafka Connect for near real-time da...Changing landscapes in data integration - Kafka Connect for near real-time da...
Changing landscapes in data integration - Kafka Connect for near real-time da...
 
Couchbase 5.5: N1QL and Indexing features
Couchbase 5.5: N1QL and Indexing featuresCouchbase 5.5: N1QL and Indexing features
Couchbase 5.5: N1QL and Indexing features
 
How to use Impala query plan and profile to fix performance issues
How to use Impala query plan and profile to fix performance issuesHow to use Impala query plan and profile to fix performance issues
How to use Impala query plan and profile to fix performance issues
 
Static analysis of java enterprise applications
Static analysis of java enterprise applicationsStatic analysis of java enterprise applications
Static analysis of java enterprise applications
 
Things YouShould Be Doing When Using Cassandra Drivers
Things YouShould Be Doing When Using Cassandra DriversThings YouShould Be Doing When Using Cassandra Drivers
Things YouShould Be Doing When Using Cassandra Drivers
 
Parallel Tuning of Machine Learning Algorithms, Thesis Proposal
Parallel Tuning of Machine Learning Algorithms, Thesis ProposalParallel Tuning of Machine Learning Algorithms, Thesis Proposal
Parallel Tuning of Machine Learning Algorithms, Thesis Proposal
 
Streams Don't Fail Me Now - Robustness Features in Kafka Streams
Streams Don't Fail Me Now - Robustness Features in Kafka StreamsStreams Don't Fail Me Now - Robustness Features in Kafka Streams
Streams Don't Fail Me Now - Robustness Features in Kafka Streams
 
Towards Dynamic Consistency Checking in Goal-directed Predicate Answer Set Pr...
Towards Dynamic Consistency Checking in Goal-directed Predicate Answer Set Pr...Towards Dynamic Consistency Checking in Goal-directed Predicate Answer Set Pr...
Towards Dynamic Consistency Checking in Goal-directed Predicate Answer Set Pr...
 
Cassandra Tools and Distributed Administration (Jeffrey Berger, Knewton) | C*...
Cassandra Tools and Distributed Administration (Jeffrey Berger, Knewton) | C*...Cassandra Tools and Distributed Administration (Jeffrey Berger, Knewton) | C*...
Cassandra Tools and Distributed Administration (Jeffrey Berger, Knewton) | C*...
 

More from Enkitec

Using Angular JS in APEX
Using Angular JS in APEXUsing Angular JS in APEX
Using Angular JS in APEX
Enkitec
 
Controlling execution plans 2014
Controlling execution plans   2014Controlling execution plans   2014
Controlling execution plans 2014
Enkitec
 
Engineered Systems: Environment-as-a-Service Demonstration
Engineered Systems: Environment-as-a-Service DemonstrationEngineered Systems: Environment-as-a-Service Demonstration
Engineered Systems: Environment-as-a-Service Demonstration
Enkitec
 
Think Exa!
Think Exa!Think Exa!
Think Exa!
Enkitec
 
In Search of Plan Stability - Part 1
In Search of Plan Stability - Part 1In Search of Plan Stability - Part 1
In Search of Plan Stability - Part 1
Enkitec
 
Mini Session - Using GDB for Profiling
Mini Session - Using GDB for ProfilingMini Session - Using GDB for Profiling
Mini Session - Using GDB for Profiling
Enkitec
 
Profiling Oracle with GDB
Profiling Oracle with GDBProfiling Oracle with GDB
Profiling Oracle with GDB
Enkitec
 
Oracle Performance Tools of the Trade
Oracle Performance Tools of the TradeOracle Performance Tools of the Trade
Oracle Performance Tools of the Trade
Enkitec
 
Oracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsOracle Performance Tuning Fundamentals
Oracle Performance Tuning Fundamentals
Enkitec
 
SQL Tuning Tools of the Trade
SQL Tuning Tools of the TradeSQL Tuning Tools of the Trade
SQL Tuning Tools of the Trade
Enkitec
 
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
Enkitec
 
Oracle GoldenGate Architecture Performance
Oracle GoldenGate Architecture PerformanceOracle GoldenGate Architecture Performance
Oracle GoldenGate Architecture PerformanceEnkitec
 
OGG Architecture Performance
OGG Architecture PerformanceOGG Architecture Performance
OGG Architecture PerformanceEnkitec
 
APEX Security Primer
APEX Security PrimerAPEX Security Primer
APEX Security PrimerEnkitec
 
How Many Ways Can I Manage Oracle GoldenGate?
How Many Ways Can I Manage Oracle GoldenGate?How Many Ways Can I Manage Oracle GoldenGate?
How Many Ways Can I Manage Oracle GoldenGate?Enkitec
 
Sql tuning made easier with sqltxplain (sqlt)
Sql tuning made easier with sqltxplain (sqlt)Sql tuning made easier with sqltxplain (sqlt)
Sql tuning made easier with sqltxplain (sqlt)Enkitec
 
Profiling the logwriter and database writer
Profiling the logwriter and database writerProfiling the logwriter and database writer
Profiling the logwriter and database writerEnkitec
 
Fatkulin hotsos 2014
Fatkulin hotsos 2014Fatkulin hotsos 2014
Fatkulin hotsos 2014Enkitec
 
Why You May Not Need Offloading
Why You May Not Need OffloadingWhy You May Not Need Offloading
Why You May Not Need OffloadingEnkitec
 
LOBS, BLOBS, CLOBS: Dealing with Attachments in APEX
LOBS, BLOBS, CLOBS: Dealing with Attachments in APEXLOBS, BLOBS, CLOBS: Dealing with Attachments in APEX
LOBS, BLOBS, CLOBS: Dealing with Attachments in APEXEnkitec
 

More from Enkitec (20)

Using Angular JS in APEX
Using Angular JS in APEXUsing Angular JS in APEX
Using Angular JS in APEX
 
Controlling execution plans 2014
Controlling execution plans   2014Controlling execution plans   2014
Controlling execution plans 2014
 
Engineered Systems: Environment-as-a-Service Demonstration
Engineered Systems: Environment-as-a-Service DemonstrationEngineered Systems: Environment-as-a-Service Demonstration
Engineered Systems: Environment-as-a-Service Demonstration
 
Think Exa!
Think Exa!Think Exa!
Think Exa!
 
In Search of Plan Stability - Part 1
In Search of Plan Stability - Part 1In Search of Plan Stability - Part 1
In Search of Plan Stability - Part 1
 
Mini Session - Using GDB for Profiling
Mini Session - Using GDB for ProfilingMini Session - Using GDB for Profiling
Mini Session - Using GDB for Profiling
 
Profiling Oracle with GDB
Profiling Oracle with GDBProfiling Oracle with GDB
Profiling Oracle with GDB
 
Oracle Performance Tools of the Trade
Oracle Performance Tools of the TradeOracle Performance Tools of the Trade
Oracle Performance Tools of the Trade
 
Oracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsOracle Performance Tuning Fundamentals
Oracle Performance Tuning Fundamentals
 
SQL Tuning Tools of the Trade
SQL Tuning Tools of the TradeSQL Tuning Tools of the Trade
SQL Tuning Tools of the Trade
 
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
 
Oracle GoldenGate Architecture Performance
Oracle GoldenGate Architecture PerformanceOracle GoldenGate Architecture Performance
Oracle GoldenGate Architecture Performance
 
OGG Architecture Performance
OGG Architecture PerformanceOGG Architecture Performance
OGG Architecture Performance
 
APEX Security Primer
APEX Security PrimerAPEX Security Primer
APEX Security Primer
 
How Many Ways Can I Manage Oracle GoldenGate?
How Many Ways Can I Manage Oracle GoldenGate?How Many Ways Can I Manage Oracle GoldenGate?
How Many Ways Can I Manage Oracle GoldenGate?
 
Sql tuning made easier with sqltxplain (sqlt)
Sql tuning made easier with sqltxplain (sqlt)Sql tuning made easier with sqltxplain (sqlt)
Sql tuning made easier with sqltxplain (sqlt)
 
Profiling the logwriter and database writer
Profiling the logwriter and database writerProfiling the logwriter and database writer
Profiling the logwriter and database writer
 
Fatkulin hotsos 2014
Fatkulin hotsos 2014Fatkulin hotsos 2014
Fatkulin hotsos 2014
 
Why You May Not Need Offloading
Why You May Not Need OffloadingWhy You May Not Need Offloading
Why You May Not Need Offloading
 
LOBS, BLOBS, CLOBS: Dealing with Attachments in APEX
LOBS, BLOBS, CLOBS: Dealing with Attachments in APEXLOBS, BLOBS, CLOBS: Dealing with Attachments in APEX
LOBS, BLOBS, CLOBS: Dealing with Attachments in APEX
 

Recently uploaded

Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 

Recently uploaded (20)

Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 

Using adaptive cursor sharing (acs) to produce multiple optimal plans v2

  • 1. Using Adaptive Cursor Sharing (ACS) to produce multiple Optimal Plans Carlos Sierra
  • 2. Carlos Sierra Senior Technical Consultant at Enkitec §  SQL Tuner handyman: developer, advisor, trainer, support §  IT: Enkitec (<0.2), Oracle(17), UNISYS(12), Ford(3), others(3) §  Florida(17), Venezuela(3), Puerto Rico(6), Michigan(1), Mexico(x) §  Tools: SQLTXPLAIN(SQLT), SQLHC, TRCANLZR(TRCA), others §  Motto: Life’s Good! 2
  • 3. Adaptive Cursor Sharing (ACS) §  Motivation §  Mechanics §  Test Case §  Demo §  Remarks 3
  • 5. SQL Processing Hard parsing is expensive! §  Hard parse side effects –  CPU consumption –  Latch contention §  Excessive hard parsing –  Affects concurrency –  Restricts scalability §  Mitigating hard parsing –  Cursor sharing 5
  • 6. Implementing Cursor Sharing Replacing literals with bind variables 6
  • 7. Before Bind Peeking Before 9i CBO was blind to values passed §  Predicate –  WHERE channel_id = :b1 §  Unknowns –  Is :b1 between low and high values of channel_id? –  Is :b1 a popular value of channel_id? –  Are there any rows with value :b1 for channel_id? §  Penalty –  Possible suboptimal plans 7
  • 8. With Bind Peeking 9i offers a partial solution §  Predicate –  WHERE channel_id = :b1 §  Plan is determined by peeked values –  EXEC :b1 := 9; §  Optimal plan for 1st execution –  CBO can use low/high and histograms on channel_id §  Penalty –  Possible suboptimal plans for subsequent executions on skewed data 8
  • 9. Real-life Problem with Bind Peeking People Soft Payroll Application §  WHERE employee BETWEEN :b1 AND :b2 §  Payroll for one employee –  :b1 = 123456 –  :b2 = 123456 §  Payroll for one company –  :b1 = 000001 –  :b2 = 999999 §  Doing payroll for an employee first then entire company 9
  • 10. With Adaptive Cursor Sharing 11g improves cursor sharing §  Some queries are ACS candidates §  Sophisticated non-persistent mechanism §  Selectivity of predicates determine plan §  Multiple optimal plans for a query! –  If ACS is successfully applied §  Penalty –  Marginal increase in CPU and memory overhead 10
  • 12. ACS high-level Overview High level overview §  If SQL with binds meets some requirements –  Flag cursor as bind sensitive –  Start monitoring data volume manipulated by cursor §  If bind sensitive and data volume manipulated by cursor varies significantly –  Flag cursor as bind aware –  Start generating multiple optimal plans for this query on next hard parse §  If bind aware then use selectivity of predicates to decide on plan 12
  • 13. Bind Sensitive Minimum requirements §  SQL has explicit binds –  Or literals and cursor_sharing is “force” §  Predicate: column + operand + bind_variable –  Equality operand “=“ and histogram on column §  Ex: channel_id = :b1 –  Non-equality operand (range) regardless of histogram on column §  “>”, “>=“, “<“, ‘<=“, BETWEEN, LIKE 13
  • 14. Bind Aware How to become bind aware? §  Significant changes in data volume manipulated by cursor –  A few rows versus a few thousands of rows –  A few thousands of rows versus a few millions of rows §  Specifying /*+ BIND_AWARE */ CBO Hint –  Bypasses the monitoring phase on data volume 14
  • 15. Plan Selection Based on selectivity profile of predicates §  Evaluate selectivity of predicates at soft parse §  Compare to a non-persistent selectivity profile §  If within ranges of a known profile then select associated plan §  Else hard parse –  Compute and execute newly generated plan –  Create selectivity profile for new plan or update profile of existing plan §  If ranges on selectivity profiles overlap then merge profiles 15
  • 16. V$ dynamic views for ACS ACS non-persistent performance views §  V$SQL –  Shareable, bind sensitive and bind aware flags §  V$SQL_CS_STATISTICS –  Data volume manipulated (rows processed) §  V$SQL_CS_HISTOGRAM –  Record keeping of data volume per execution (small, medium, large) §  V$SQL_CS_SELECTIVITY –  Predicates selectivity profiles 16
  • 18. Our Query with Literals Guesstimate execution plan then verify it with demo 0 18
  • 21. Our Query with Bind Variables How many optimal execution plans can you foresee? 21
  • 22. Multiple Optimal Plans for one Query Guesstimate optimal plan (access paths) for each query Query :b1 :b2 AP1 AP2 q1 9 33 N1 N2 q2 5 32 q3 2 999 q4 9 999 q5 2 33 22
  • 23. Multiple Optimal Plans for one Query Guesstimate optimal plan (access paths) for each query Query :b1 :b2 AP1 AP2 q1 9 33 N1 N2 q2 5 32 N1 N2 q3 2 999 FTS FTS q4 9 999 N1 FTS q5 2 33 FTS N2 23
  • 24. Multiple Optimal Plans for one Query Execute demos 1-5 and verify access paths Query :b1 :b2 AP1 AP2 q1 9 33 N1 N2 q2 5 32 N1 N2 q3 2 999 FTS FTS q4 9 999 N1 FTS q5 2 33 FTS N2 24
  • 25. Bind Sensitive: Rows Processed Monitor v$sql_cs_statistics.rows_processed §  Data volume manipulated –  Fuzzy representation –  S: few rows –  M: thousands or rows –  L: millions of rows §  v$sql_cs_histogram –  Bucket(0): S –  Bucket(1): M –  Bucket(2): L Rows Processed Query :b1 :b2 Optimal q1 9 33 N1/N2 37,382 q2 5 32 N1/N2 2 q3 2 999 FTS/FTS 8,021,324 q4 9 999 N1/FTS 6,233,815 q5 2 33 FTS/N2 1,825,131 25
  • 27. Demo 6: When Cursor becomes Bind Aware? Obtain rows processed from demo 1-5 then guesstimate aware flag Rows Processed Query :b1 :b2 Optimal Bucket q1 9 33 N1/N2 37,382 q2 5 32 N1/N2 2 q3 2 999 FTS/FTS 8,021,324 q4 9 999 N1/FTS 6,233,815 q5 2 33 FTS/N2 Aware Child Actual 1,825,131 27
  • 28. Demo 6: When Cursor becomes Bind Aware? Obtain rows processed from demo 1-5 then guesstimate aware flag Rows Processed Query :b1 :b2 Optimal Bucket q1 9 33 N1/N2 37,382 1 q2 5 32 N1/N2 2 0 q3 2 999 FTS/FTS 8,021,324 2 q4 9 999 N1/FTS 6,233,815 2 q5 2 33 FTS/N2 1,825,131 Aware Child Actual 2 28
  • 29. Demo 6: When Cursor becomes Bind Aware? Obtain rows processed from demo 1-5 then guesstimate aware flag Query :b1 :b2 Optimal q1 9 33 N1/N2 q2 5 32 N1/N2 q3 2 q4 q5 Rows Processed Bucket Aware 37,382 1 N 2 0 N 999 FTS/FTS 8,021,324 2 Y 9 999 N1/FTS 6,233,815 2 Y 2 33 FTS/N2 1,825,131 2 Child Actual Y 29
  • 30. Demo 6: When Cursor becomes Bind Aware? Obtain rows processed from demo 1-5 then guesstimate aware flag Query :b1 :b2 Optimal q1 9 33 N1/N2 q2 5 32 N1/N2 q3 2 q4 q5 Rows Processed Bucket Aware Child Actual 37,382 1 N 0 N1/N2 2 0 N 0 N1/N2 999 FTS/FTS 8,021,324 2 Y 1 FTS/FTS 9 999 N1/FTS 6,233,815 2 Y 2 N1/FTS 2 33 FTS/N2 1,825,131 2 Y 3 FTS/N2 30
  • 31. Demo 6: When Cursor becomes Bind Aware? Obtain rows processed from demo 1-5 then guesstimate aware flag Query :b1 :b2 Optimal q1 9 33 N1/N2 q2 5 32 N1/N2 q3 2 q4 q5 Rows Processed Bucket Aware Child Actual 37,382 1 N 0 N1/N2 2 0 N 0 N1/N2 999 FTS/FTS 8,021,324 2 Y 1 FTS/FTS 9 999 N1/FTS 6,233,815 2 Y 2 N1/FTS 2 33 FTS/N2 1,825,131 2 Y 3 FTS/N2 31
  • 32. Demo 7: When Cursor becomes Bind Aware? Compute bucket and guesstimate aware flag and actual plan Rows Processed Query :b1 :b2 Optimal Bucket q5 2 33 FTS/N2 1,825,131 q4 9 999 N1/FTS 6,233,815 q3 2 999 FTS/FTS q2 5 32 N1/N2 2 q1 9 33 N1/N2 Aware Child Actual 37,382 8,021,324 32
  • 33. Demo 7: When Cursor becomes Bind Aware? Compute bucket and guesstimate aware flag and actual plan Rows Processed Query :b1 :b2 Optimal Bucket q5 2 33 FTS/N2 1,825,131 2 q4 9 999 N1/FTS 6,233,815 2 q3 2 999 FTS/FTS 8,021,324 2 q2 5 32 N1/N2 2 0 q1 9 33 N1/N2 37,382 Aware Child Actual 1 33
  • 34. Demo 7: When Cursor becomes Bind Aware? Compute bucket and guesstimate aware flag and actual plan Query :b1 :b2 Optimal q5 2 33 FTS/N2 q4 9 999 N1/FTS q3 2 999 FTS/FTS q2 5 32 q1 9 33 Rows Processed Bucket Aware 1,825,131 2 N 6,233,815 2 N 8,021,324 2 N N1/N2 2 0 N N1/N2 37,382 1 Child Actual Y 34
  • 35. Demo 7: When Cursor becomes Bind Aware? Compute bucket and guesstimate aware flag and actual plan Query :b1 :b2 Optimal q5 2 33 FTS/N2 q4 9 999 N1/FTS q3 2 999 FTS/FTS q2 5 32 q1 9 33 Rows Processed Bucket Aware Child Actual 1,825,131 2 N 0 FTS/N2 6,233,815 2 N 0 FTS/N2 8,021,324 2 N 0 FTS/N2 N1/N2 2 0 N 0 FTS/N2 N1/N2 37,382 1 Y 1 N1/N2 35
  • 36. Demo 7: When Cursor becomes Bind Aware? Compute bucket and guesstimate aware flag and actual plan Query :b1 :b2 Optimal q5 2 33 FTS/N2 q4 9 999 N1/FTS q3 2 999 FTS/FTS q2 5 32 q1 9 33 Rows Processed Bucket Aware Child Actual 1,825,131 2 N 0 FTS/N2 6,233,815 2 N 0 FTS/N2 8,021,324 2 N 0 FTS/N2 N1/N2 2 0 N 0 FTS/N2 N1/N2 37,382 1 Y 1 N1/N2 36
  • 37. Demo 8: When Cursor becomes Bind Aware? Guesstimate aware flag and actual plan Rows Processed Query :b1 :b2 Optimal Bucket q5 2 33 FTS/N2 1,825,131 2 q4 9 999 N1/FTS 6,233,815 2 q3 2 999 FTS/FTS 8,021,324 2 q1 9 33 N1/N2 37,382 1 q2 5 32 N1/N2 2 Aware Child Actual 0 37
  • 38. Demo 8: When Cursor becomes Bind Aware? Guesstimate aware flag and actual plan Query :b1 :b2 Optimal q5 2 33 FTS/N2 q4 9 999 N1/FTS q3 2 999 FTS/FTS q1 9 33 q2 5 32 Rows Processed Bucket Aware 1,825,131 2 N 6,233,815 2 N 8,021,324 2 N N1/N2 37,382 1 N N1/N2 2 0 Child Actual N 38
  • 39. Demo 8: When Cursor becomes Bind Aware? Guesstimate aware flag and actual plan Query :b1 :b2 Optimal q5 2 33 FTS/N2 q4 9 999 N1/FTS q3 2 999 FTS/FTS q1 9 33 q2 5 32 Rows Processed Bucket Aware Child Actual 1,825,131 2 N 0 FTS/N2 6,233,815 2 N 0 FTS/N2 8,021,324 2 N 0 FTS/N2 N1/N2 37,382 1 N 0 FTS/N2 N1/N2 2 0 N 0 FTS/N2 39
  • 40. Demo 8: When Cursor becomes Bind Aware? Guesstimate aware flag and actual plan Query :b1 :b2 Optimal q5 2 33 FTS/N2 q4 9 999 N1/FTS q3 2 999 FTS/FTS q1 9 33 q2 5 32 Rows Processed Bucket Aware Child Actual 1,825,131 2 N 0 FTS/N2 6,233,815 2 N 0 FTS/N2 8,021,324 2 N 0 FTS/N2 N1/N2 37,382 1 N 0 FTS/N2 N1/N2 2 0 N 0 FTS/N2 40
  • 41. Real-life Problem with ACS People Soft Payroll Application §  WHERE employee BETWEEN :b1 AND :b2 §  Payroll for one employee –  :b1 = 123456 –  :b2 = 123456 §  Payroll for one company –  :b1 = 000001 –  :b2 = 999999 §  Doing payroll for a few employees first then entire company 41
  • 43. Understanding Selectivity Profile From demo 6 Query :b1 :b2 Child q3 2 999 1 q4 9 999 2 q5 2 33 3 43
  • 44. Understanding Selectivity Profile From demo 6 Query :b1 :b2 Child q3 2 999 1 q4 9 999 2 q5 2 33 3 44
  • 45. Understanding Selectivity Profile From demo 6 Query :b1 :b2 Child q3 2 999 1 q4 9 999 2 q5 2 33 3 45
  • 46. Remarks on Bind Sensitivity Based on experimental observation §  Monitor V$SQL_CS_STATISTICS.rows_processed –  If small number of rows then §  V$SQL_CS_HISTOGRAM.bucket_id(0)++ –  If medium number of rows then §  V$SQL_CS_HISTOGRAM.bucket_id(1)++ –  If large number of rows then §  V$SQL_CS_HISTOGRAM.bucket_id(2)++ 46
  • 47. Remarks on Bind Aware Based on experimental observation §  Some cases where cursor may become bind aware –  bucket_id(0) = bucket_id(1) > 0 –  bucket_id(1) = bucket_id(2) > 0 –  bucket_id(0) > 0 and bucket_id(2) > 0 §  Or use /*+ BIND_AWARE */ CBO Hint –  What if we cannot modify code? 47
  • 48. Conclusions ACS can produce multiple optimal plans for one query §  ACS only applies to a subset of queries with binds §  ACS requires a ramp-up process (few executions) §  In some cases cursor may fail to become bind aware §  To force a cursor become bind aware use CBO Hint §  ACS is not persistent §  ACS works well with SQL Plan Management 48
  • 49. Give Away Script sqlt/utl/coe_gen_sql_patch.sql (MOS 215187.1) §  Creates a SQL Patch for one SQL_ID §  Turns “on” EVENT 10053 for SQL_ID §  Hints on SQL Patch –  GATHER_PLAN_STATISTICS –  MONITOR –  BIND_AWARE §  Consider using and customizing this free script 49
  • 50. References and Contact Info Oracle Optimizer Blog §  https://blogs.oracle.com/optimizer/ –  Insight into the workings of the Optimizer §  carlos.sierra@enkitec.com §  http://carlos-sierra.net §  @csierra_usa 50