SlideShare a Scribd company logo
28/11/15 Mohamed Houri www.hourim.wordpress.com
1
Adaptive Cursor Sharing
Short answer to sharing cursors and optimizing SQL
Mohamed Houri
www.hourim.wordpress.com
Mohamed Houri
www.hourim.wordpress.com
28/11/15 Mohamed Houri www.hourim.wordpress.com
2
Agenda
Set the scene
Expose the performance problem caused by sharing cursors
Literal, bind variable, bind variable peeking and hard parsing
Introduce Adaptive Cursor Sharing feature
Adaptive Cursor Sharing
Explain the cursor bind sensitive property
Explain the cursor bind aware property
Show a simple practical ACS example
Explain the ACS monitoring v$sql views
Uncover the bind aware secret sauce
Show how ACS can introduce a serious perfomance issue
Conclusion
28/11/15 Mohamed Houri www.hourim.wordpress.com
3
WHAT IS THE PROBLEM?
PART 0
Set the scene
28/11/15 Mohamed Houri www.hourim.wordpress.com
4
Syntactic check
Syntax, keywords
Semantic check
Access, right, exist Store parent cursor in
v$sql(SGA)
Logical Optimization
Physical Optimization
Store child cursor in
v$sql(SGA)
Parent
cursor?
Child
cursor?
Execute SQL
No
No
Yes
Yes
Set the scene
Hardparse
Softparse
28/11/15 Mohamed Houri www.hourim.wordpress.com
5
Using Literal variable
➔
hard parsing for each execution
➔
traumatizes the SGA
➔
burns a lot CPU
Set the scene
Using bind variables
➔
avoids hard parsing
➔
makes the SGA attractive
➔
uses less resource - CPU
generates “always“ an optimal plan
sharing plan is not always optimal
28/11/15 Mohamed Houri www.hourim.wordpress.com
6
How to have best-of-both-world?
Set the scene
➔ Attractive SGA + less CPU consumption
➔ Optimal execution plan for each execution
Adaptive Cursor Sharing-ACS
28/11/15 Mohamed Houri www.hourim.wordpress.com
7
ACS - triggering diagram
Invesigate this property
28/11/15 Mohamed Houri www.hourim.wordpress.com
8
WHEN A CURSOR IS BIND SENSITIVE?
PART I
ACS
28/11/15 Mohamed Houri www.hourim.wordpress.com
9
SQL> desc V$SQL
Name Null? Type
------------------------------- -------- -------------
1 SQL_TEXT VARCHAR2(1000)
2 SQL_FULLTEXT CLOB
3 SQL_ID VARCHAR2(13)
45 CHILD_NUMBER NUMBER
63 IS_OBSOLETE VARCHAR2(1)
64 IS_BIND_SENSITIVE VARCHAR2(1)
65 IS_BIND_AWARE VARCHAR2(1)
66 IS_SHAREABLE VARCHAR2(1)
ACS - v$sql
28/11/15 Mohamed Houri www.hourim.wordpress.com
10
ACS – model
SQL> create table t_acs(n1 number, n2 number);
SQL> BEGIN
for j in 1..1200150 loop
if j = 1 then
insert into t_acs values (j, 1);
elsif j>1 and j<=101 then
insert into t_acs values(j, 100);
elsif j>101 and j<=1101 then
insert into t_acs values (j, 1000);
elsif j>10001 and j<= 110001 then
insert into t_acs values(j,10000);
else
insert into t_acs values(j, 1000000);
end if;
end loop;
commit;
END;
Inflexion point
Inflexion point
28/11/15 Mohamed Houri www.hourim.wordpress.com
11
ACS – model
SQL> create index t_acs_i1 on t_acs(n2);
SQL> BEGIN
dbms_stats.gather_table_stats
(user
,'t_acs'
,method_opt => 'for all columns size 1'
,cascade => true
,estimate_percent => dbms_stats.auto_sample_size
);
END;
/
–- declare and affect a value to a bind variable
–- and run a query with range predicate
SQL> var ln2 number;
SQL> exec :ln2 := 100;
Without histogram
28/11/15 Mohamed Houri www.hourim.wordpress.com
12
ACS – bind sensitive : range predicate
SQL> select count(1) from t_acs where n2 <= :ln2;
SQL> select
sql_id
,child_number
,is_bind_sensitive
from
v$sql
where
sql_id = 'ct0yv82p15jdw';
SQL_ID CHILD_NUMBER IS_BIND_SENSITIVE
------------- ------------ -----------------
ct0yv82p15jdw 0 Y
range predicate
cursor is bind sensitive
28/11/15 Mohamed Houri www.hourim.wordpress.com
13
ACS – bind sensitive : equality predicate with histogram
SQL> BEGIN
dbms_stats.gather_table_stats
(user,'t_acs'
,method_opt => 'for all columns size auto'
,cascade => true
,estimate_percent => dbms_stats.auto_sample_size);
END;/
SQL> SELECT
column_name,
histogram
FROM user_tab_col_statistics
WHERE table_name = 'T_ACS'
AND column_name = 'N2';
COLUMN_NAME HISTOGRAM
----------------- -----------
N2 FREQUENCY
with histogram
with histogram
28/11/15 Mohamed Houri www.hourim.wordpress.com
14
ACS – bind sensitive : equality predicate with histogram
SQL> select count(1) from t_acs where n2 = :ln2;
SQL> select
sql_id
,child_number
,is_bind_sensitive
from
v$sql
where
sql_id = 'f2pmwazy1rnfd';
SQL_ID CHILD_NUMBER IS_BIND_SENSITIVE
------------- ------------ –-----------------
f2pmwazy1rnfd 0 Y
equality predicate
with histogram
cursor is bind sensitive
28/11/15 Mohamed Houri www.hourim.wordpress.com
15
ACS – bind sensitive : partition key
SQL> create table t_acs_part(n1 number, n2 number)
partition by range (n2)
( partition p1 values less than (100)
,partition p2 values less than (1000)
,partition p3 values less than (10000)
,partition p4 values less than (100000)
,partition p5 values less than (1000000)
,partition p6 values less than (10000000));
SQL> –- insert data and gather stats without histogram
SQL> select column_name, histogram
FROM user_tab_col_statistics
where table_name = 'T_ACS_PART' AND column_name = 'N2';
COLUMN_NAM HISTOGRAM
---------- ---------
N2 NONE
28/11/15 Mohamed Houri www.hourim.wordpress.com
16
ACS – bind sensitive : partition key
SQL> select count(1) from t_acs where n2 = :ln2;
SQL> select
sql_id
,child_number
,is_bind_sensitive
from
v$sql
where
sql_id = 'byztzuffb65n9';
SQL_ID CHILD_NUMBER IS_BIND_SENSITIVE
------------- ------------ –----------------
byztzuffb65n9 0 Y
partition key
cursor is bind sensitive
28/11/15 Mohamed Houri www.hourim.wordpress.com
17
ACS – bind sensitive : summary
range predicate (with simple statistics)
SQL> select count(1) from t_acs where n2 <= :ln2;
equality predicate (with histogram)
SQL> select count(1) from t_acs where n2 = :ln2;
predicate with partition key (simple stats)
SQL> select count(1) from t_acs where n2 = :ln2;
28/11/15 Mohamed Houri www.hourim.wordpress.com
18
18
PART II
ACS-simple example
A SIMPLE ACS EXAMPLE
28/11/15 Mohamed Houri www.hourim.wordpress.com
19
ACS-simple example
SQL> exec :ln2 := 100
SQL> select count(1) from t_acs where n2 = :ln2;
SQL> select n2,count(1) from t_acs group by n2 order by 2;
N2 COUNT(1)
---------- ----------
1 1
100 100
1000 1000
10000 100000
1000000 1099049
index range scan
full table scan
28/11/15 Mohamed Houri www.hourim.wordpress.com
20
ACS-simple example
SQL_ID f2pmwazy1rnfd, child number 0
-----------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
-----------------------------------------------------
| 0 | SELECT STATEMENT | | | |
| 1 | SORT AGGREGATE | | 1 | 3 |
|* 2 | INDEX RANGE SCAN| T_ACS_I1 | 856 | 2568 |
-----------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("N2"=:LN2)
optimal plan for the first execution.
Plan has been hard parsed
28/11/15 Mohamed Houri www.hourim.wordpress.com
21
ACS-simple example
SQL> exec :ln2 := 1000000
–- 1st
execution with bind variable value = 1000000
SQL> select count(1) from t_acs where n2 = :ln2;
SQL_ID f2pmwazy1rnfd, child number 0
-----------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
-----------------------------------------------------
| 0 | SELECT STATEMENT | | | |
| 1 | SORT AGGREGATE | | 1 | 3 |
|* 2 | INDEX RANGE SCAN| T_ACS_I1 | 856 | 2568 |
-----------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("N2"=:LN2)
sharing plan is bad here
28/11/15 Mohamed Houri www.hourim.wordpress.com
22
ACS-simple example
SQL> exec :ln2 := 1000000
–- 2nd
execution with bind variable value = 1000000
SQL> select count(1) from t_acs where n2 = :ln2;
SQL_ID f2pmwazy1rnfd, child number 1
-----------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
-----------------------------------------------------
| 0 | SELECT STATEMENT | | | |
| 1 | SORT AGGREGATE | | 1 | 3 |
|* 2 | TABLE ACCESS FULL| T_ACS | 1104K| 3235K|
-----------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 – filter("N2"=:LN2) optimal plan at the second
execution
28/11/15 Mohamed Houri www.hourim.wordpress.com
23
ACS-simple example
–- back to the first bind variable value 100
SQL> exec :ln2 := 100
SQL> select count(1) from t_acs where n2 = :ln2;
SQL_ID f2pmwazy1rnfd, child number 2
------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
------------------------------------------------------
| 0 | SELECT STATEMENT | | | |
| 1 | SORT AGGREGATE | | 1 | 3 |
|* 2 | INDEX RANGE SCAN| T_ACS_I1 | 1713 | 5139 |
------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 – access("N2"=:LN2) execution plan is now immediately
optimal
28/11/15 Mohamed Houri www.hourim.wordpress.com
24
SQL> select
sql_id
,child_number
,is_bind_sensitive
,is_bind_aware
from
v$sql
where
sql_id = 'f2pmwazy1rnfd';
SQL_ID CHILD_NUMBER IS_BIND_SENS IS_BIND_AWARE
------------- ------------ –----------- –-------------
f2pmwazy1rnfd 0 Y N → index-RS
f2pmwazy1rnfd 1 Y Y → table-FS
f2pmwazy1rnfd 2 Y Y → index-RS
is that cursor is now bind aware
what happens?
ACS-simple example
28/11/15 Mohamed Houri www.hourim.wordpress.com
25
ACS-simple example
We have gone wrong(index range scan plan shared) during the
first execution with :ln2 := 1000000
It is until the second execution with :ln2 := 1000000 that Oracle has
compiled a new optimal plan (full table scan)
We have to share the “wrong” plan during a certain number of
executions
This “certain number” of executions is strongly related to the number
of executions done at the initial bind variable value :ln2 := 100
This execution-count relationship will be explained later
(BUCKET_ID, COUNT)
28/11/15 Mohamed Houri www.hourim.wordpress.com
26
26
PART III
ACS-bind aware secret sauce
When Oracle decides that it is time to compile
a new execution plan?
28/11/15 Mohamed Houri www.hourim.wordpress.com
27
27
SQL> desc V$SQL_CS_STATISTICS
Name Null? Type
------------------------------- -------- --------------
1 ADDRESS RAW(8)
2 HASH_VALUE NUMBER
3 SQL_ID VARCHAR2(13)
4 CHILD_NUMBER NUMBER
5 BIND_SET_HASH_VALUE NUMBER
6 PEEKED VARCHAR2(1)
7 EXECUTIONS NUMBER
8 ROWS_PROCESSED NUMBER
9 BUFFER_GETS NUMBER
10 CPU_TIME NUMBER
11 CON_ID NUMBER
ACS-bind aware secret sauce
Starting from 12c this
view is obsolete
28/11/15 Mohamed Houri www.hourim.wordpress.com
28
28
SQL> desc V$SQL_CS_HISTOGRAM
Name Null? Type
------------------------------- -------- -------------
1 ADDRESS RAW(8)
2 HASH_VALUE NUMBER
3 SQL_ID VARCHAR2(13)
4 CHILD_NUMBER NUMBER
5 BUCKET_ID NUMBER
6 COUNT NUMBER
7 CON_ID NUMBER
ACS-bind aware secret sauce
number of executions
done at this child_number
linked to the number of
rows processed by
this child_number
28/11/15 Mohamed Houri www.hourim.wordpress.com
29
29
SQL> desc V$SQL_CS_SELECTIVITY
Name Null? Type
----------------------- -------- --------------
1 ADDRESS RAW(8)
2 HASH_VALUE NUMBER
3 SQL_ID VARCHAR2(13)
4 CHILD_NUMBER NUMBER
5 PREDICATE VARCHAR2(40)
6 RANGE_ID NUMBER
7 LOW VARCHAR2(10)
8 HIGH VARCHAR2(10)
9 CON_ID NUMBER
ACS-bind aware secret sauce
This view becomes useful
only when cursor is
bind aware
28/11/15 Mohamed Houri www.hourim.wordpress.com
30
30
ACS-bind aware secret sauce
0 <= ROWS_PROCESSED< 1,000
increments COUNT
of BUCKET_ID n° 0
1,000 <= ROWS_PROCESSED<= 1,000,000
increments COUNT
of BUCKET_ID n° 1
ROWS_PROCESSED> 1,000,000
increments COUNT
of BUCKET_ID n° 2
Inflexion point
Inflexion point
28/11/15 Mohamed Houri www.hourim.wordpress.com
31
SQL> exec :ln2 := 100 –- 1st
execution with this value
SQL> select count(1) from t_acs where n2 = :ln2;
COUNT(1)
----------
100
ACS-bind aware secret sauce
Nbr of rows processed <1000
SQL> select
child_number,bucket_id,count
from
v$sql_cs_histogram
where sql_id = 'f2pmwazy1rnfd' ;
CHILD_NUMBER BUCKET_ID COUNT
------------ ---------- ----------
0 0 1
0 1 0
0 2 0
count(bucket_id n°0)
incremented
28/11/15 Mohamed Houri www.hourim.wordpress.com
32
SQL> exec :ln2 := 100 –- 2nd
execution with this value
SQL> select count(1) from t_acs where n2 = :ln2;
COUNT(1)
----------
100
ACS-bind aware secret sauce
SQL> select
child_number,bucket_id,count
from
v$sql_cs_histogram
where sql_id = 'f2pmwazy1rnfd' ;
CHILD_NUMBER BUCKET_ID COUNT
------------ ---------- ----------
0 0 2
0 1 0
0 2 0
count(bucket_id n°0)
incremented
Nbr of rows processed <1000
28/11/15 Mohamed Houri www.hourim.wordpress.com
33
SQL> exec :ln2 := 100 –- 3rd
execution with this value
SQL> select count(1) from t_acs where n2 = :ln2;
COUNT(1)
----------
100
ACS-bind aware secret sauce
SQL> select
child_number,bucket_id,count
from
v$sql_cs_histogram
where sql_id = 'f2pmwazy1rnfd' ;
CHILD_NUMBER BUCKET_ID COUNT
------------ ---------- ----------
0 0 3
0 1 0
0 2 0
count(bucket_id n°0)
incremented
Nbr of rows processed <1000
28/11/15 Mohamed Houri www.hourim.wordpress.com
34
SQL> exec :ln2 := 1000 –- 1st
execution with this value
SQL> select count(1) from t_acs where n2 = :ln2;
COUNT(1)
-------
1000
ACS-bind aware secret sauce
SQL> select
child_number,bucket_id,count
from
v$sql_cs_histogram
where sql_id = 'f2pmwazy1rnfd' ;
CHILD_NUMBER BUCKET_ID COUNT
------------ ---------- ----------
0 0 3
0 1 1
0 2 0
count(bucket_id n°1)
incremented
1000<= Nbr of rows processed <= 1e6
still sharing same plan
28/11/15 Mohamed Houri www.hourim.wordpress.com
35
SQL> exec :ln2 := 1000 –-2nd
execution with this value
SQL> select count(1) from t_acs where n2 = :ln2;
COUNT(1)
-------
1000
ACS-bind aware secret sauce
SQL> select
child_number,bucket_id,count
from
v$sql_cs_histogram
where sql_id = 'f2pmwazy1rnfd' ;
CHILD_NUMBER BUCKET_ID COUNT
------------ ---------- ----------
0 0 3
0 1 2
0 2 0
count(bucket_id n°1)
incremented
1000<= Nbr of rows processed <= 1e6
still sharing same plan
28/11/15 Mohamed Houri www.hourim.wordpress.com
36
SQL> exec :ln2 := 1000 –-3rd
execution with this value
SQL> select count(1) from t_acs where n2 = :ln2;
COUNT(1)
-------
1000
ACS-bind aware secret sauce
SQL> select
child_number,bucket_id,count
from
v$sql_cs_histogram
where sql_id = 'f2pmwazy1rnfd' ;
CHILD_NUMBER BUCKET_ID COUNT
------------ ---------- ----------
0 0 3
0 1 3
0 2 0
count(bucket_id n°1)
incremented
1000<= Nbr of rows processed <= 1e6
still sharing same plan
28/11/15 Mohamed Houri www.hourim.wordpress.com
37
SQL> exec :ln2 := 1000 –-4th
execution with this value
SQL> select count(1) from t_acs where n2 = :ln2;
ACS-bind aware secret sauce
SQL> select
child_number,bucket_id,count
from
v$sql_cs_histogram
where sql_id = 'f2pmwazy1rnfd' ;
CHILD_NUMBER BUCKET_ID COUNT
------------ ---------- ----------
1 0 0
1 1 1
1 2 0
0 0 3
0 1 3
0 2 0
count(bucket_id n°1)
incremented
new compiled plan
28/11/15 Mohamed Houri www.hourim.wordpress.com
38
SQL> select
sql_id
,child_number
,is_bind_sensitive
,is_bind_aware
from
v$sql
where
sql_id = 'f2pmwazy1rnfd';
SQL_ID CHILD_NUMBER IS_BIND_SENS IS_BIND_AWARE
------------- ------------ –----------- –-------------
f2pmwazy1rnfd 0 Y N
f2pmwazy1rnfd 1 Y Y
cursor n° 1 is now bind aware
ACS-bind aware secret sauce
28/11/15 Mohamed Houri www.hourim.wordpress.com
39
39
ACS-bind aware secret sauce – rule n° 1 : adjacent buckets
COUNT(BUCKET_ID n° 1) = COUNT(BUCKET_ID n° 0)
OR
COUNT(BUCKET_ID n° 2) = COUNT(BUCKET_ID n° 1)
The next execution at BUCKET_ID n°1 (or n°2) will
 mark the cursor bind aware
 and a new execution plan will be compiled
28/11/15 Mohamed Houri www.hourim.wordpress.com
40
SQL> exec :ln2 := 100 –- bucket_id n° 0
SQL> select count(1) from t_acs where n2 = :ln2;
SQL> ../.. 10 executions
ACS-bind aware secret sauce : distant bucket_id
SQL> select
child_number,bucket_id,count
from
v$sql_cs_histogram
where sql_id = 'f2pmwazy1rnfd' ;
CHILD_NUMBER BUCKET_ID COUNT
------------ ---------- ----------
0 0 10
0 1 0
0 2 0
count(bucket_id n°0)
Incremented 10 times
28/11/15 Mohamed Houri www.hourim.wordpress.com
41
SQL> exec :ln2 := 1000000 –- bucket_id n°2
SQL> select count(1) from t_acs where n2 = :ln2;
COUNT(1)
----------
1099049
ACS-bind aware secret sauce : distant bucket_id
SQL> select
child_number,bucket_id,count
from
v$sql_cs_histogram
where sql_id = 'f2pmwazy1rnfd' ;
CHILD_NUMBER BUCKET_ID COUNT
------------ ---------- ----------
0 0 10
0 1 0
0 2 1
count(bucket_id n°2)
Incremented 1 time
still sharing same plan
Nbr of rows > 1e6
28/11/15 Mohamed Houri www.hourim.wordpress.com
42
Question : How many executions at bucket_id n°2 we need to have
before Oracle compile a new optimal plan?
ACS-bind aware secret sauce : distant bucket_id
–- run this 3 times
SQL> select count(1) from t_acs where n2 = :ln2;
SQL> select
child_number,bucket_id,count
from
v$sql_cs_histogram
where sql_id = 'f2pmwazy1rnfd' ;
CHILD_NUMBER BUCKET_ID COUNT
------------ ---------- ----------
0 0 10
0 1 0
0 2 4
count(bucket_id n°2)
incremented 3 times
Answer : 4 executions
still sharing the
same plan
28/11/15 Mohamed Houri www.hourim.wordpress.com
43
SQL> exec :ln2 := 1000000 –-5th
execution at this value
SQL> select count(1) from t_acs where n2 = :ln2;
SQL> select
child_number,bucket_id,count
from
v$sql_cs_histogram
where sql_id = 'f2pmwazy1rnfd' ;
CHILD_NUMBER BUCKET_ID COUNT
------------ ---------- ----------
1 0 0
1 1 0
1 2 1
0 0 10
0 1 0
0 2 4
10 exec at bucket_id n°0
new compiled plan
ACS-bind aware secret sauce : distant bucket_id
4 exec at bucket_id n°2
28/11/15 Mohamed Houri www.hourim.wordpress.com
44
44
4 = ceil (10/3)
The next execution at BUCKET_ID n°2 will
 mark the cursor bind aware
 and a new execution plan will be compiled
ACS-bind aware secret sauce : distant bucket_id
Applies only with distant bucket_id (0 and 2)
COUNT(BUCKET_ID n° 2) = ceil (COUNT(BUCKET_ID n° 0)/3)
28/11/15 Mohamed Houri www.hourim.wordpress.com
45
ACS-bind aware secret sauce : all buckets involved
SQL> select
child_number,bucket_id,count
from
v$sql_cs_histogram
where sql_id = 'f2pmwazy1rnfd' ;
CHILD_NUMBER BUCKET_ID COUNT
------------ ---------- ----------
0 0 10
0 1 3
0 2 1
Question : How many executions at bucket_id n°2 we need to have
before Oracle compiles a new optimal plan?
10 exec at bucket_id n°0
3 exec at bucket_id n°1
1 exec at bucket_id n°2
28/11/15 Mohamed Houri www.hourim.wordpress.com
46
ACS-bind aware secret sauce : all buckets involved
------------------------------------------------------------------------------
-- File name: fv_will_cs_be_bind_aware
-- Author : Mohamed Houri (Mohamed.Houri@gmail.com)
-- Date : 29/08/2015
-- Purpose : When supplied with 3 parameters
-- pin_cnt_bucket_0 : count of bucket_id n°0
-- pin_cnt_bucket_1 : count of bucket_id n°1
-- pin_cnt_bucket_2 : count of bucket_id n°2
-- this function will return a status:
-- 'Y' if the next execution at any bucket_id will mark the cursor bind aware
-- 'N' if the next execution any bucket_id will NOT mark the cursor bind aware
--------------------------------------------------------------------------------
create or replace function fv_will_cs_be_bind_aware
(pin_cnt_bucket_0 in number,pin_cnt_bucket_1 in number,pin_cnt_bucket_2 in number)
return varchar2 is
lv_will_be_bind_aware varchar2(1) := 'N';
ln_least_0_2 number := least(pin_cnt_bucket_0,pin_cnt_bucket_2);
ln_great_0_2 number := greatest(pin_cnt_bucket_0,pin_cnt_bucket_2);
begin
if pin_cnt_bucket_0 + pin_cnt_bucket_2 > = pin_cnt_bucket_1
and ln_least_0_2 >= ceil ((ln_great_0_2-pin_cnt_bucket_1)/3)then
return 'Y';
else
return 'N';
end if;
end fv_will_cs_be_bind_aware;
28/11/15 Mohamed Houri www.hourim.wordpress.com
47
ACS-bind aware secret sauce : all buckets involved
SQL> select
child_number,bucket_id,count
from
v$sql_cs_histogram
where sql_id = 'f2pmwazy1rnfd' ;
CHILD_NUMBER BUCKET_ID COUNT
------------ ---------- ----------
0 0 10
0 1 3
0 2 1
SQL> select fv_will_cs_be_bind_aware(10,3,1) acs from dual;
ACS
----
N
next execution will share the same plan
28/11/15 Mohamed Houri www.hourim.wordpress.com
48
SQL> exec :ln2 := 1000000 –- 2nd
execution at this value
SQL> select count(1) from t_acs where n2 = :ln2;
SQL> select
child_number,bucket_id,count
from
v$sql_cs_histogram
where sql_id = 'f2pmwazy1rnfd' ;
CHILD_NUMBER BUCKET_ID COUNT
------------ ---------- ----------
0 0 10
0 1 3
0 2 2
SQL> select fv_will_cs_be_bind_aware(10,3,2) acs from dual;
ACS
----
N next execution will share the same plan
ACS-bind aware secret sauce : all buckets involved
28/11/15 Mohamed Houri www.hourim.wordpress.com
49
SQL> exec :ln2 := 1000000 –- 3rd
execution at this value
SQL> select count(1) from t_acs where n2 = :ln2;
SQL> select
child_number,bucket_id,count
from
v$sql_cs_histogram
where sql_id = 'f2pmwazy1rnfd' ;
CHILD_NUMBER BUCKET_ID COUNT
------------ ---------- ----------
0 0 10
0 1 3
0 2 3
SQL> select fv_will_cs_be_bind_aware(10,3,3) acs from dual;
ACS
----
Y next execution will compile a new plan
ACS-bind aware secret sauce : all buckets involved
28/11/15 Mohamed Houri www.hourim.wordpress.com
50
SQL> exec :ln2 := 1000000 –- 4th
execution at this value
SQL> select count(1) from t_acs where n2 = :ln2;
SQL> select
child_number,bucket_id,count
from
v$sql_cs_histogram
where sql_id = 'f2pmwazy1rnfd' ;
CHILD_NUMBER BUCKET_ID COUNT
------------ ---------- ----------
1 0 0
1 1 0
1 2 1
0 0 10
0 1 3
0 2 3
new execution plan compiled
ACS-bind aware secret sauce : all buckets involved
28/11/15 Mohamed Houri www.hourim.wordpress.com
51
51
The next exection at any BUCKET will
 mark the cursor bind aware
 and a new execution plan will be
compiled
SQL> select
fv_will_cs_be_bind_aware
(pin_cnt_bucket_0
,pin_cnt_bucket_1
,pin_cnt_bucket_2 )
from dual;
Existing plan will be
shared
N Y
Not extensively tested!!!
ACS-bind aware secret sauce : all buckets involved
28/11/15 Mohamed Houri www.hourim.wordpress.com
52
52
ACS-bind aware secret sauce : summary
COUNT(BUCKET_ID 1) =
COUNT(BUCKET_ID 0)
ADJACENT BUCKET_ID
(0-1 or 1-2)
next execution will compile
a new execution plan
COUNT(BUCKET_ID 2) =
CEIL(COUNT(BUCKET_ID 0)
/3)
next execution will compile
a new execution plan
DISTANT BUCKET_ID
(0-2)
select
fv_will_cs_be_bind_aware
(0,1,2) from dual; → Y
next execution will compile
a new execution plan
ALL BUCKET_ID
involved
28/11/15 Mohamed Houri www.hourim.wordpress.com
53
53
PART IV
Extended Cursor Sharing
Extended Cursor Sharing- ECS
28/11/15 Mohamed Houri www.hourim.wordpress.com
54
54
Extended Cursor Sharing
Adaptive Cursor Sharing
Extended Cursor Sharing
is responsible for marking bind aware
a bind sensitive cursor provided one of
the 3 rules is satisfied
is responsible for checking if an execution
plan of a bind aware cursor has to be
shared or a new plan has to be compiled
according to the bind variable selectivity
it peeks at each execution
28/11/15 Mohamed Houri www.hourim.wordpress.com
55
SQL> select
sql_id
,child_number
,is_bind_sensitive
,is_bind_aware
from
v$sql
where
sql_id = 'f2pmwazy1rnfd';
SQL_ID CHILD_NUMBER IS_BIND_SENS IS_BIND_AWARE
------------- ------------ –----------- –-------------
f2pmwazy1rnfd 0 Y N
f2pmwazy1rnfd 1 Y Y
once a cursor is bind aware a row exists in v$sql_cs_selectivity
Extended Cursor Sharing
28/11/15 Mohamed Houri www.hourim.wordpress.com
56
SQL> select
child_number
,predicate
,low
,high
From v$sql_cs_selectivity
where sql_id = 'f2pmwazy1rnfd';
CHILD_NUMBER PREDICATE LOW HIGH
------------ ------------- ---------- ----------
2 =LN2 0.827448 1.011325
1 =LN2 0.000807 0.000986
Extended Cursor Sharing
for each execution bind variable selectivity is
checked: if it exists in one of the LOW-HIGH
ranges then share plan. If not then compile a new
plan and insert/update a new LOW-HIGH range
this is ECS
28/11/15 Mohamed Houri www.hourim.wordpress.com
57
57
PART V
Extended Cursor Sharing causing a performance issue
When ACS (in fact ECS) becomes a serious
performance threat
28/11/15 Mohamed Houri www.hourim.wordpress.com
58
SQL> select
sql_id
,count(1)
from
v$sql
where executions < 2
group by sql_id
having count(1) > 10
order by 2 desc;
SQL_ID COUNT(1)
------------- ----------
7zwq7z1nj7vga 44217
Extended Cursor Sharing causing a performance issue
Why this high nbr
of versions?
28/11/15 Mohamed Houri www.hourim.wordpress.com
59
SQL> @nonshared 7zwq7z1nj7vga
Show why existing SQL child cursors were not reused(V$SQL_SHARED_CURSOR)
-----------------
SQL_ID : 7zwq7z1nj7vga
ADDRESS : 000000406DBB30F8
CHILD_ADDRESS : 00000042CE36F7E8
CHILD_NUMBER : 99
BIND_EQUIV_FAILURE : Y
REASON :<ChildNode><ChildNumber>0</ChildNumber><ID>40</ID>
<reason>Bindmismatch(33)</reason><size>2x4</size>
<init_ranges_in_first_pass>0</init_ranges_in_first_pass>
<selectivity>1097868685</selectivity>
</ChildNode>
Extended Cursor Sharing causing a performance issue
100 exec plans (0-99)
due to bind_equivalent_failure
28/11/15 Mohamed Houri www.hourim.wordpress.com
60
SQL> select count(1)
from v$sql_shared_cursor
Where sql_id = '7zwq7z1nj7vga';
COUNT(1)
----------
45125
SQL> select count(1)
from v$sql_shared_cursor
Where sql_id = '7zwq7z1nj7vga'
and BIND_EQUIV_FAILURE = 'Y';
COUNT(1)
----------
45121
99% of non shared cursors are due to
BIND_EQUIV_FAILURE
Extended Cursor Sharing causing a performance issue
28/11/15 Mohamed Houri www.hourim.wordpress.com
61
BIND_EQUIV_FAILURE : bind value's selectivity does
not match that used to optimize the existing child
cursor
SQL> select
count(1)
from
v$sql_cs_selectivity
where
sql_id = '7zwq7z1nj7vga';
COUNT(1)
----------
16,847,320 !!!
for each execution ECS
will check this view!!!
Extended Cursor Sharing causing a performance issue
CHILD_NUMBER PREDICATE LOW HIGH
------------ ------------- ---------- ----------
2 =LN2 0.827448 1.011325
28/11/15 Mohamed Houri www.hourim.wordpress.com
62
Extended Cursor Sharing causing a performance issue
Run a query using a bind aware cursor
Oracle (ECS layer code) will do behind the scene:
1. peeks at the bind variable value
2. runs a query against v$sql_cs_selectivity(16M of rows)
3. if low < selectivity < high then share existing plan
4. if selectity not found in low-high range then hard parse a new plan
If another user executes the same query:
1. Oracle will try to do the above 1-4 steps
2. if Oracle is still busy with above 1-4 steps then we start experiencing:
a) cursor: pin S wait on X
b) library cache lock
28/11/15 Mohamed Houri www.hourim.wordpress.com
63
63
PART V
Adaptive-Extended Cursor Sharing
FINAL ACS-ECS DIAGRAM
https://hourim.wordpress.com/2015/08/12/adaptive-cursor-sharing-triggering-mechanism/
28/11/15 Mohamed Houri www.hourim.wordpress.com
64
64
Adaptive Cursor Sharing
•Conclusion
• Literal variables are good for query performance
• very bad for resource and memory
• and they produce a non scalable application
• Bind variables are not always good for query performance
• very good for resource and memory
• and they produce a scalable application
• Adaptive cursor sharing allows query good performance
• even when using bind variable
• but be aware of the extra parsing work it might introduce

More Related Content

PPTX
Ukoug15 SIMD outside and inside Oracle 12c (12.1.0.2)
PPT
Oracle 10g Performance: chapter 09 enqueues
PDF
Rac 12c optimization
PPTX
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
PPT
Ash masters : advanced ash analytics on Oracle
PPT
Rmoug ashmaster
PPTX
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
PPT
OOUG: Oracle transaction locking
Ukoug15 SIMD outside and inside Oracle 12c (12.1.0.2)
Oracle 10g Performance: chapter 09 enqueues
Rac 12c optimization
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Ash masters : advanced ash analytics on Oracle
Rmoug ashmaster
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
OOUG: Oracle transaction locking

What's hot (20)

PPTX
Mark Farnam : Minimizing the Concurrency Footprint of Transactions
PPTX
DBA Commands and Concepts That Every Developer Should Know
PPTX
Flex Cluster e Flex ASM - GUOB Tech Day - OTN TOUR LA Brazil 2014
PPT
UKOUG, Oracle Transaction Locks
PPTX
Indexing in Exadata
PDF
Profiling the logwriter and database writer
PDF
Troubleshooting Complex Oracle Performance Problems with Tanel Poder
PPT
Wait Events 10g
PDF
Mini Session - Using GDB for Profiling
PDF
Tuning SQL for Oracle Exadata: The Good, The Bad, and The Ugly Tuning SQL fo...
PDF
In Memory Database In Action by Tanel Poder and Kerry Osborne
PDF
In Search of Plan Stability - Part 1
PPT
11 Things About11g
PDF
Create your oracle_apps_r12_lab_with_less_than_us1000
PPTX
How oracle 12c flexes its muscles against oracle 11g r2 final
PPTX
Christo kutrovsky oracle, memory & linux
PDF
Drilling Deep Into Exadata Performance
PDF
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2
PPTX
Indexes From the Concept to Internals
PDF
Oracle Exadata 1Z0-485 Certification
Mark Farnam : Minimizing the Concurrency Footprint of Transactions
DBA Commands and Concepts That Every Developer Should Know
Flex Cluster e Flex ASM - GUOB Tech Day - OTN TOUR LA Brazil 2014
UKOUG, Oracle Transaction Locks
Indexing in Exadata
Profiling the logwriter and database writer
Troubleshooting Complex Oracle Performance Problems with Tanel Poder
Wait Events 10g
Mini Session - Using GDB for Profiling
Tuning SQL for Oracle Exadata: The Good, The Bad, and The Ugly Tuning SQL fo...
In Memory Database In Action by Tanel Poder and Kerry Osborne
In Search of Plan Stability - Part 1
11 Things About11g
Create your oracle_apps_r12_lab_with_less_than_us1000
How oracle 12c flexes its muscles against oracle 11g r2 final
Christo kutrovsky oracle, memory & linux
Drilling Deep Into Exadata Performance
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2
Indexes From the Concept to Internals
Oracle Exadata 1Z0-485 Certification
Ad

Viewers also liked (15)

PDF
Webinar Uniworld e Qualitours 2016
PDF
Virtual City Company Profile 26 July VC Highlights
PDF
MyCruise Qualitours - O site que você já conhece, agora pode ser SEU
PPTX
Web 2.0
PDF
cv with portfolio set
PDF
ใบงานที่ 10
DOCX
Av01 gomezperla
PDF
New Farm Africa project to help boost grain trade across East Africa
ODP
Music genre
PDF
Resume- Du Yaqiong
PDF
Leidy
PDF
ContinuousImprovement-certificate
PPTX
GEODI : a Practical Information Management Solution For Construction Sector
PPTX
Understanding How is that Adaptive Cursor Sharing (ACS) produces multiple Opt...
PPS
Teorias del comercio internacional
Webinar Uniworld e Qualitours 2016
Virtual City Company Profile 26 July VC Highlights
MyCruise Qualitours - O site que você já conhece, agora pode ser SEU
Web 2.0
cv with portfolio set
ใบงานที่ 10
Av01 gomezperla
New Farm Africa project to help boost grain trade across East Africa
Music genre
Resume- Du Yaqiong
Leidy
ContinuousImprovement-certificate
GEODI : a Practical Information Management Solution For Construction Sector
Understanding How is that Adaptive Cursor Sharing (ACS) produces multiple Opt...
Teorias del comercio internacional
Ad

Similar to All on Adaptive and Extended Cursor Sharing (20)

PDF
Managing Statistics for Optimal Query Performance
PDF
Oracle 11g caracteristicas poco documentadas 3 en 1
PDF
SQL Macros - Game Changing Feature for SQL Developers?
PDF
12c SQL Plan Directives
PPTX
OpenWorld Sep14 12c for_developers
PPTX
Oracle dbms_xplan.display_cursor format
PPTX
Oracle 12c SPM
PDF
On Seeing Double in V$SQL_Thomas_Kytepdf
PPTX
Writing efficient sql
PPTX
Adapting to Adaptive Plans on 12c
PPT
11thingsabout11g 12659705398222 Phpapp01
PPTX
A few things about the Oracle optimizer - 2013
PPTX
5 Cool Things About SQL
PDF
Demystifying cost based optimization
PPT
Dbms plan - A swiss army knife for performance engineers
PDF
SQLチューニング総合診療Oracle CloudWorld出張所
PDF
EvolveExecutionPlans.pdf
PPT
Do You Know The 11g Plan?
DOCX
MV sql profile and index
PPT
Mod03 linking and accelerating
Managing Statistics for Optimal Query Performance
Oracle 11g caracteristicas poco documentadas 3 en 1
SQL Macros - Game Changing Feature for SQL Developers?
12c SQL Plan Directives
OpenWorld Sep14 12c for_developers
Oracle dbms_xplan.display_cursor format
Oracle 12c SPM
On Seeing Double in V$SQL_Thomas_Kytepdf
Writing efficient sql
Adapting to Adaptive Plans on 12c
11thingsabout11g 12659705398222 Phpapp01
A few things about the Oracle optimizer - 2013
5 Cool Things About SQL
Demystifying cost based optimization
Dbms plan - A swiss army knife for performance engineers
SQLチューニング総合診療Oracle CloudWorld出張所
EvolveExecutionPlans.pdf
Do You Know The 11g Plan?
MV sql profile and index
Mod03 linking and accelerating

Recently uploaded (20)

PPTX
Spectroscopy.pptx food analysis technology
PPT
Teaching material agriculture food technology
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Big Data Technologies - Introduction.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
cuic standard and advanced reporting.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
Spectroscopy.pptx food analysis technology
Teaching material agriculture food technology
“AI and Expert System Decision Support & Business Intelligence Systems”
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Big Data Technologies - Introduction.pptx
Machine learning based COVID-19 study performance prediction
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Agricultural_Statistics_at_a_Glance_2022_0.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Understanding_Digital_Forensics_Presentation.pptx
cuic standard and advanced reporting.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
MYSQL Presentation for SQL database connectivity
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Encapsulation_ Review paper, used for researhc scholars
Digital-Transformation-Roadmap-for-Companies.pptx

All on Adaptive and Extended Cursor Sharing

  • 1. 28/11/15 Mohamed Houri www.hourim.wordpress.com 1 Adaptive Cursor Sharing Short answer to sharing cursors and optimizing SQL Mohamed Houri www.hourim.wordpress.com Mohamed Houri www.hourim.wordpress.com
  • 2. 28/11/15 Mohamed Houri www.hourim.wordpress.com 2 Agenda Set the scene Expose the performance problem caused by sharing cursors Literal, bind variable, bind variable peeking and hard parsing Introduce Adaptive Cursor Sharing feature Adaptive Cursor Sharing Explain the cursor bind sensitive property Explain the cursor bind aware property Show a simple practical ACS example Explain the ACS monitoring v$sql views Uncover the bind aware secret sauce Show how ACS can introduce a serious perfomance issue Conclusion
  • 3. 28/11/15 Mohamed Houri www.hourim.wordpress.com 3 WHAT IS THE PROBLEM? PART 0 Set the scene
  • 4. 28/11/15 Mohamed Houri www.hourim.wordpress.com 4 Syntactic check Syntax, keywords Semantic check Access, right, exist Store parent cursor in v$sql(SGA) Logical Optimization Physical Optimization Store child cursor in v$sql(SGA) Parent cursor? Child cursor? Execute SQL No No Yes Yes Set the scene Hardparse Softparse
  • 5. 28/11/15 Mohamed Houri www.hourim.wordpress.com 5 Using Literal variable ➔ hard parsing for each execution ➔ traumatizes the SGA ➔ burns a lot CPU Set the scene Using bind variables ➔ avoids hard parsing ➔ makes the SGA attractive ➔ uses less resource - CPU generates “always“ an optimal plan sharing plan is not always optimal
  • 6. 28/11/15 Mohamed Houri www.hourim.wordpress.com 6 How to have best-of-both-world? Set the scene ➔ Attractive SGA + less CPU consumption ➔ Optimal execution plan for each execution Adaptive Cursor Sharing-ACS
  • 7. 28/11/15 Mohamed Houri www.hourim.wordpress.com 7 ACS - triggering diagram Invesigate this property
  • 8. 28/11/15 Mohamed Houri www.hourim.wordpress.com 8 WHEN A CURSOR IS BIND SENSITIVE? PART I ACS
  • 9. 28/11/15 Mohamed Houri www.hourim.wordpress.com 9 SQL> desc V$SQL Name Null? Type ------------------------------- -------- ------------- 1 SQL_TEXT VARCHAR2(1000) 2 SQL_FULLTEXT CLOB 3 SQL_ID VARCHAR2(13) 45 CHILD_NUMBER NUMBER 63 IS_OBSOLETE VARCHAR2(1) 64 IS_BIND_SENSITIVE VARCHAR2(1) 65 IS_BIND_AWARE VARCHAR2(1) 66 IS_SHAREABLE VARCHAR2(1) ACS - v$sql
  • 10. 28/11/15 Mohamed Houri www.hourim.wordpress.com 10 ACS – model SQL> create table t_acs(n1 number, n2 number); SQL> BEGIN for j in 1..1200150 loop if j = 1 then insert into t_acs values (j, 1); elsif j>1 and j<=101 then insert into t_acs values(j, 100); elsif j>101 and j<=1101 then insert into t_acs values (j, 1000); elsif j>10001 and j<= 110001 then insert into t_acs values(j,10000); else insert into t_acs values(j, 1000000); end if; end loop; commit; END; Inflexion point Inflexion point
  • 11. 28/11/15 Mohamed Houri www.hourim.wordpress.com 11 ACS – model SQL> create index t_acs_i1 on t_acs(n2); SQL> BEGIN dbms_stats.gather_table_stats (user ,'t_acs' ,method_opt => 'for all columns size 1' ,cascade => true ,estimate_percent => dbms_stats.auto_sample_size ); END; / –- declare and affect a value to a bind variable –- and run a query with range predicate SQL> var ln2 number; SQL> exec :ln2 := 100; Without histogram
  • 12. 28/11/15 Mohamed Houri www.hourim.wordpress.com 12 ACS – bind sensitive : range predicate SQL> select count(1) from t_acs where n2 <= :ln2; SQL> select sql_id ,child_number ,is_bind_sensitive from v$sql where sql_id = 'ct0yv82p15jdw'; SQL_ID CHILD_NUMBER IS_BIND_SENSITIVE ------------- ------------ ----------------- ct0yv82p15jdw 0 Y range predicate cursor is bind sensitive
  • 13. 28/11/15 Mohamed Houri www.hourim.wordpress.com 13 ACS – bind sensitive : equality predicate with histogram SQL> BEGIN dbms_stats.gather_table_stats (user,'t_acs' ,method_opt => 'for all columns size auto' ,cascade => true ,estimate_percent => dbms_stats.auto_sample_size); END;/ SQL> SELECT column_name, histogram FROM user_tab_col_statistics WHERE table_name = 'T_ACS' AND column_name = 'N2'; COLUMN_NAME HISTOGRAM ----------------- ----------- N2 FREQUENCY with histogram with histogram
  • 14. 28/11/15 Mohamed Houri www.hourim.wordpress.com 14 ACS – bind sensitive : equality predicate with histogram SQL> select count(1) from t_acs where n2 = :ln2; SQL> select sql_id ,child_number ,is_bind_sensitive from v$sql where sql_id = 'f2pmwazy1rnfd'; SQL_ID CHILD_NUMBER IS_BIND_SENSITIVE ------------- ------------ –----------------- f2pmwazy1rnfd 0 Y equality predicate with histogram cursor is bind sensitive
  • 15. 28/11/15 Mohamed Houri www.hourim.wordpress.com 15 ACS – bind sensitive : partition key SQL> create table t_acs_part(n1 number, n2 number) partition by range (n2) ( partition p1 values less than (100) ,partition p2 values less than (1000) ,partition p3 values less than (10000) ,partition p4 values less than (100000) ,partition p5 values less than (1000000) ,partition p6 values less than (10000000)); SQL> –- insert data and gather stats without histogram SQL> select column_name, histogram FROM user_tab_col_statistics where table_name = 'T_ACS_PART' AND column_name = 'N2'; COLUMN_NAM HISTOGRAM ---------- --------- N2 NONE
  • 16. 28/11/15 Mohamed Houri www.hourim.wordpress.com 16 ACS – bind sensitive : partition key SQL> select count(1) from t_acs where n2 = :ln2; SQL> select sql_id ,child_number ,is_bind_sensitive from v$sql where sql_id = 'byztzuffb65n9'; SQL_ID CHILD_NUMBER IS_BIND_SENSITIVE ------------- ------------ –---------------- byztzuffb65n9 0 Y partition key cursor is bind sensitive
  • 17. 28/11/15 Mohamed Houri www.hourim.wordpress.com 17 ACS – bind sensitive : summary range predicate (with simple statistics) SQL> select count(1) from t_acs where n2 <= :ln2; equality predicate (with histogram) SQL> select count(1) from t_acs where n2 = :ln2; predicate with partition key (simple stats) SQL> select count(1) from t_acs where n2 = :ln2;
  • 18. 28/11/15 Mohamed Houri www.hourim.wordpress.com 18 18 PART II ACS-simple example A SIMPLE ACS EXAMPLE
  • 19. 28/11/15 Mohamed Houri www.hourim.wordpress.com 19 ACS-simple example SQL> exec :ln2 := 100 SQL> select count(1) from t_acs where n2 = :ln2; SQL> select n2,count(1) from t_acs group by n2 order by 2; N2 COUNT(1) ---------- ---------- 1 1 100 100 1000 1000 10000 100000 1000000 1099049 index range scan full table scan
  • 20. 28/11/15 Mohamed Houri www.hourim.wordpress.com 20 ACS-simple example SQL_ID f2pmwazy1rnfd, child number 0 ----------------------------------------------------- | Id | Operation | Name | Rows | Bytes | ----------------------------------------------------- | 0 | SELECT STATEMENT | | | | | 1 | SORT AGGREGATE | | 1 | 3 | |* 2 | INDEX RANGE SCAN| T_ACS_I1 | 856 | 2568 | ----------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("N2"=:LN2) optimal plan for the first execution. Plan has been hard parsed
  • 21. 28/11/15 Mohamed Houri www.hourim.wordpress.com 21 ACS-simple example SQL> exec :ln2 := 1000000 –- 1st execution with bind variable value = 1000000 SQL> select count(1) from t_acs where n2 = :ln2; SQL_ID f2pmwazy1rnfd, child number 0 ----------------------------------------------------- | Id | Operation | Name | Rows | Bytes | ----------------------------------------------------- | 0 | SELECT STATEMENT | | | | | 1 | SORT AGGREGATE | | 1 | 3 | |* 2 | INDEX RANGE SCAN| T_ACS_I1 | 856 | 2568 | ----------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("N2"=:LN2) sharing plan is bad here
  • 22. 28/11/15 Mohamed Houri www.hourim.wordpress.com 22 ACS-simple example SQL> exec :ln2 := 1000000 –- 2nd execution with bind variable value = 1000000 SQL> select count(1) from t_acs where n2 = :ln2; SQL_ID f2pmwazy1rnfd, child number 1 ----------------------------------------------------- | Id | Operation | Name | Rows | Bytes | ----------------------------------------------------- | 0 | SELECT STATEMENT | | | | | 1 | SORT AGGREGATE | | 1 | 3 | |* 2 | TABLE ACCESS FULL| T_ACS | 1104K| 3235K| ----------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 – filter("N2"=:LN2) optimal plan at the second execution
  • 23. 28/11/15 Mohamed Houri www.hourim.wordpress.com 23 ACS-simple example –- back to the first bind variable value 100 SQL> exec :ln2 := 100 SQL> select count(1) from t_acs where n2 = :ln2; SQL_ID f2pmwazy1rnfd, child number 2 ------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | ------------------------------------------------------ | 0 | SELECT STATEMENT | | | | | 1 | SORT AGGREGATE | | 1 | 3 | |* 2 | INDEX RANGE SCAN| T_ACS_I1 | 1713 | 5139 | ------------------------------------------------------ Predicate Information (identified by operation id): --------------------------------------------------- 2 – access("N2"=:LN2) execution plan is now immediately optimal
  • 24. 28/11/15 Mohamed Houri www.hourim.wordpress.com 24 SQL> select sql_id ,child_number ,is_bind_sensitive ,is_bind_aware from v$sql where sql_id = 'f2pmwazy1rnfd'; SQL_ID CHILD_NUMBER IS_BIND_SENS IS_BIND_AWARE ------------- ------------ –----------- –------------- f2pmwazy1rnfd 0 Y N → index-RS f2pmwazy1rnfd 1 Y Y → table-FS f2pmwazy1rnfd 2 Y Y → index-RS is that cursor is now bind aware what happens? ACS-simple example
  • 25. 28/11/15 Mohamed Houri www.hourim.wordpress.com 25 ACS-simple example We have gone wrong(index range scan plan shared) during the first execution with :ln2 := 1000000 It is until the second execution with :ln2 := 1000000 that Oracle has compiled a new optimal plan (full table scan) We have to share the “wrong” plan during a certain number of executions This “certain number” of executions is strongly related to the number of executions done at the initial bind variable value :ln2 := 100 This execution-count relationship will be explained later (BUCKET_ID, COUNT)
  • 26. 28/11/15 Mohamed Houri www.hourim.wordpress.com 26 26 PART III ACS-bind aware secret sauce When Oracle decides that it is time to compile a new execution plan?
  • 27. 28/11/15 Mohamed Houri www.hourim.wordpress.com 27 27 SQL> desc V$SQL_CS_STATISTICS Name Null? Type ------------------------------- -------- -------------- 1 ADDRESS RAW(8) 2 HASH_VALUE NUMBER 3 SQL_ID VARCHAR2(13) 4 CHILD_NUMBER NUMBER 5 BIND_SET_HASH_VALUE NUMBER 6 PEEKED VARCHAR2(1) 7 EXECUTIONS NUMBER 8 ROWS_PROCESSED NUMBER 9 BUFFER_GETS NUMBER 10 CPU_TIME NUMBER 11 CON_ID NUMBER ACS-bind aware secret sauce Starting from 12c this view is obsolete
  • 28. 28/11/15 Mohamed Houri www.hourim.wordpress.com 28 28 SQL> desc V$SQL_CS_HISTOGRAM Name Null? Type ------------------------------- -------- ------------- 1 ADDRESS RAW(8) 2 HASH_VALUE NUMBER 3 SQL_ID VARCHAR2(13) 4 CHILD_NUMBER NUMBER 5 BUCKET_ID NUMBER 6 COUNT NUMBER 7 CON_ID NUMBER ACS-bind aware secret sauce number of executions done at this child_number linked to the number of rows processed by this child_number
  • 29. 28/11/15 Mohamed Houri www.hourim.wordpress.com 29 29 SQL> desc V$SQL_CS_SELECTIVITY Name Null? Type ----------------------- -------- -------------- 1 ADDRESS RAW(8) 2 HASH_VALUE NUMBER 3 SQL_ID VARCHAR2(13) 4 CHILD_NUMBER NUMBER 5 PREDICATE VARCHAR2(40) 6 RANGE_ID NUMBER 7 LOW VARCHAR2(10) 8 HIGH VARCHAR2(10) 9 CON_ID NUMBER ACS-bind aware secret sauce This view becomes useful only when cursor is bind aware
  • 30. 28/11/15 Mohamed Houri www.hourim.wordpress.com 30 30 ACS-bind aware secret sauce 0 <= ROWS_PROCESSED< 1,000 increments COUNT of BUCKET_ID n° 0 1,000 <= ROWS_PROCESSED<= 1,000,000 increments COUNT of BUCKET_ID n° 1 ROWS_PROCESSED> 1,000,000 increments COUNT of BUCKET_ID n° 2 Inflexion point Inflexion point
  • 31. 28/11/15 Mohamed Houri www.hourim.wordpress.com 31 SQL> exec :ln2 := 100 –- 1st execution with this value SQL> select count(1) from t_acs where n2 = :ln2; COUNT(1) ---------- 100 ACS-bind aware secret sauce Nbr of rows processed <1000 SQL> select child_number,bucket_id,count from v$sql_cs_histogram where sql_id = 'f2pmwazy1rnfd' ; CHILD_NUMBER BUCKET_ID COUNT ------------ ---------- ---------- 0 0 1 0 1 0 0 2 0 count(bucket_id n°0) incremented
  • 32. 28/11/15 Mohamed Houri www.hourim.wordpress.com 32 SQL> exec :ln2 := 100 –- 2nd execution with this value SQL> select count(1) from t_acs where n2 = :ln2; COUNT(1) ---------- 100 ACS-bind aware secret sauce SQL> select child_number,bucket_id,count from v$sql_cs_histogram where sql_id = 'f2pmwazy1rnfd' ; CHILD_NUMBER BUCKET_ID COUNT ------------ ---------- ---------- 0 0 2 0 1 0 0 2 0 count(bucket_id n°0) incremented Nbr of rows processed <1000
  • 33. 28/11/15 Mohamed Houri www.hourim.wordpress.com 33 SQL> exec :ln2 := 100 –- 3rd execution with this value SQL> select count(1) from t_acs where n2 = :ln2; COUNT(1) ---------- 100 ACS-bind aware secret sauce SQL> select child_number,bucket_id,count from v$sql_cs_histogram where sql_id = 'f2pmwazy1rnfd' ; CHILD_NUMBER BUCKET_ID COUNT ------------ ---------- ---------- 0 0 3 0 1 0 0 2 0 count(bucket_id n°0) incremented Nbr of rows processed <1000
  • 34. 28/11/15 Mohamed Houri www.hourim.wordpress.com 34 SQL> exec :ln2 := 1000 –- 1st execution with this value SQL> select count(1) from t_acs where n2 = :ln2; COUNT(1) ------- 1000 ACS-bind aware secret sauce SQL> select child_number,bucket_id,count from v$sql_cs_histogram where sql_id = 'f2pmwazy1rnfd' ; CHILD_NUMBER BUCKET_ID COUNT ------------ ---------- ---------- 0 0 3 0 1 1 0 2 0 count(bucket_id n°1) incremented 1000<= Nbr of rows processed <= 1e6 still sharing same plan
  • 35. 28/11/15 Mohamed Houri www.hourim.wordpress.com 35 SQL> exec :ln2 := 1000 –-2nd execution with this value SQL> select count(1) from t_acs where n2 = :ln2; COUNT(1) ------- 1000 ACS-bind aware secret sauce SQL> select child_number,bucket_id,count from v$sql_cs_histogram where sql_id = 'f2pmwazy1rnfd' ; CHILD_NUMBER BUCKET_ID COUNT ------------ ---------- ---------- 0 0 3 0 1 2 0 2 0 count(bucket_id n°1) incremented 1000<= Nbr of rows processed <= 1e6 still sharing same plan
  • 36. 28/11/15 Mohamed Houri www.hourim.wordpress.com 36 SQL> exec :ln2 := 1000 –-3rd execution with this value SQL> select count(1) from t_acs where n2 = :ln2; COUNT(1) ------- 1000 ACS-bind aware secret sauce SQL> select child_number,bucket_id,count from v$sql_cs_histogram where sql_id = 'f2pmwazy1rnfd' ; CHILD_NUMBER BUCKET_ID COUNT ------------ ---------- ---------- 0 0 3 0 1 3 0 2 0 count(bucket_id n°1) incremented 1000<= Nbr of rows processed <= 1e6 still sharing same plan
  • 37. 28/11/15 Mohamed Houri www.hourim.wordpress.com 37 SQL> exec :ln2 := 1000 –-4th execution with this value SQL> select count(1) from t_acs where n2 = :ln2; ACS-bind aware secret sauce SQL> select child_number,bucket_id,count from v$sql_cs_histogram where sql_id = 'f2pmwazy1rnfd' ; CHILD_NUMBER BUCKET_ID COUNT ------------ ---------- ---------- 1 0 0 1 1 1 1 2 0 0 0 3 0 1 3 0 2 0 count(bucket_id n°1) incremented new compiled plan
  • 38. 28/11/15 Mohamed Houri www.hourim.wordpress.com 38 SQL> select sql_id ,child_number ,is_bind_sensitive ,is_bind_aware from v$sql where sql_id = 'f2pmwazy1rnfd'; SQL_ID CHILD_NUMBER IS_BIND_SENS IS_BIND_AWARE ------------- ------------ –----------- –------------- f2pmwazy1rnfd 0 Y N f2pmwazy1rnfd 1 Y Y cursor n° 1 is now bind aware ACS-bind aware secret sauce
  • 39. 28/11/15 Mohamed Houri www.hourim.wordpress.com 39 39 ACS-bind aware secret sauce – rule n° 1 : adjacent buckets COUNT(BUCKET_ID n° 1) = COUNT(BUCKET_ID n° 0) OR COUNT(BUCKET_ID n° 2) = COUNT(BUCKET_ID n° 1) The next execution at BUCKET_ID n°1 (or n°2) will  mark the cursor bind aware  and a new execution plan will be compiled
  • 40. 28/11/15 Mohamed Houri www.hourim.wordpress.com 40 SQL> exec :ln2 := 100 –- bucket_id n° 0 SQL> select count(1) from t_acs where n2 = :ln2; SQL> ../.. 10 executions ACS-bind aware secret sauce : distant bucket_id SQL> select child_number,bucket_id,count from v$sql_cs_histogram where sql_id = 'f2pmwazy1rnfd' ; CHILD_NUMBER BUCKET_ID COUNT ------------ ---------- ---------- 0 0 10 0 1 0 0 2 0 count(bucket_id n°0) Incremented 10 times
  • 41. 28/11/15 Mohamed Houri www.hourim.wordpress.com 41 SQL> exec :ln2 := 1000000 –- bucket_id n°2 SQL> select count(1) from t_acs where n2 = :ln2; COUNT(1) ---------- 1099049 ACS-bind aware secret sauce : distant bucket_id SQL> select child_number,bucket_id,count from v$sql_cs_histogram where sql_id = 'f2pmwazy1rnfd' ; CHILD_NUMBER BUCKET_ID COUNT ------------ ---------- ---------- 0 0 10 0 1 0 0 2 1 count(bucket_id n°2) Incremented 1 time still sharing same plan Nbr of rows > 1e6
  • 42. 28/11/15 Mohamed Houri www.hourim.wordpress.com 42 Question : How many executions at bucket_id n°2 we need to have before Oracle compile a new optimal plan? ACS-bind aware secret sauce : distant bucket_id –- run this 3 times SQL> select count(1) from t_acs where n2 = :ln2; SQL> select child_number,bucket_id,count from v$sql_cs_histogram where sql_id = 'f2pmwazy1rnfd' ; CHILD_NUMBER BUCKET_ID COUNT ------------ ---------- ---------- 0 0 10 0 1 0 0 2 4 count(bucket_id n°2) incremented 3 times Answer : 4 executions still sharing the same plan
  • 43. 28/11/15 Mohamed Houri www.hourim.wordpress.com 43 SQL> exec :ln2 := 1000000 –-5th execution at this value SQL> select count(1) from t_acs where n2 = :ln2; SQL> select child_number,bucket_id,count from v$sql_cs_histogram where sql_id = 'f2pmwazy1rnfd' ; CHILD_NUMBER BUCKET_ID COUNT ------------ ---------- ---------- 1 0 0 1 1 0 1 2 1 0 0 10 0 1 0 0 2 4 10 exec at bucket_id n°0 new compiled plan ACS-bind aware secret sauce : distant bucket_id 4 exec at bucket_id n°2
  • 44. 28/11/15 Mohamed Houri www.hourim.wordpress.com 44 44 4 = ceil (10/3) The next execution at BUCKET_ID n°2 will  mark the cursor bind aware  and a new execution plan will be compiled ACS-bind aware secret sauce : distant bucket_id Applies only with distant bucket_id (0 and 2) COUNT(BUCKET_ID n° 2) = ceil (COUNT(BUCKET_ID n° 0)/3)
  • 45. 28/11/15 Mohamed Houri www.hourim.wordpress.com 45 ACS-bind aware secret sauce : all buckets involved SQL> select child_number,bucket_id,count from v$sql_cs_histogram where sql_id = 'f2pmwazy1rnfd' ; CHILD_NUMBER BUCKET_ID COUNT ------------ ---------- ---------- 0 0 10 0 1 3 0 2 1 Question : How many executions at bucket_id n°2 we need to have before Oracle compiles a new optimal plan? 10 exec at bucket_id n°0 3 exec at bucket_id n°1 1 exec at bucket_id n°2
  • 46. 28/11/15 Mohamed Houri www.hourim.wordpress.com 46 ACS-bind aware secret sauce : all buckets involved ------------------------------------------------------------------------------ -- File name: fv_will_cs_be_bind_aware -- Author : Mohamed Houri (Mohamed.Houri@gmail.com) -- Date : 29/08/2015 -- Purpose : When supplied with 3 parameters -- pin_cnt_bucket_0 : count of bucket_id n°0 -- pin_cnt_bucket_1 : count of bucket_id n°1 -- pin_cnt_bucket_2 : count of bucket_id n°2 -- this function will return a status: -- 'Y' if the next execution at any bucket_id will mark the cursor bind aware -- 'N' if the next execution any bucket_id will NOT mark the cursor bind aware -------------------------------------------------------------------------------- create or replace function fv_will_cs_be_bind_aware (pin_cnt_bucket_0 in number,pin_cnt_bucket_1 in number,pin_cnt_bucket_2 in number) return varchar2 is lv_will_be_bind_aware varchar2(1) := 'N'; ln_least_0_2 number := least(pin_cnt_bucket_0,pin_cnt_bucket_2); ln_great_0_2 number := greatest(pin_cnt_bucket_0,pin_cnt_bucket_2); begin if pin_cnt_bucket_0 + pin_cnt_bucket_2 > = pin_cnt_bucket_1 and ln_least_0_2 >= ceil ((ln_great_0_2-pin_cnt_bucket_1)/3)then return 'Y'; else return 'N'; end if; end fv_will_cs_be_bind_aware;
  • 47. 28/11/15 Mohamed Houri www.hourim.wordpress.com 47 ACS-bind aware secret sauce : all buckets involved SQL> select child_number,bucket_id,count from v$sql_cs_histogram where sql_id = 'f2pmwazy1rnfd' ; CHILD_NUMBER BUCKET_ID COUNT ------------ ---------- ---------- 0 0 10 0 1 3 0 2 1 SQL> select fv_will_cs_be_bind_aware(10,3,1) acs from dual; ACS ---- N next execution will share the same plan
  • 48. 28/11/15 Mohamed Houri www.hourim.wordpress.com 48 SQL> exec :ln2 := 1000000 –- 2nd execution at this value SQL> select count(1) from t_acs where n2 = :ln2; SQL> select child_number,bucket_id,count from v$sql_cs_histogram where sql_id = 'f2pmwazy1rnfd' ; CHILD_NUMBER BUCKET_ID COUNT ------------ ---------- ---------- 0 0 10 0 1 3 0 2 2 SQL> select fv_will_cs_be_bind_aware(10,3,2) acs from dual; ACS ---- N next execution will share the same plan ACS-bind aware secret sauce : all buckets involved
  • 49. 28/11/15 Mohamed Houri www.hourim.wordpress.com 49 SQL> exec :ln2 := 1000000 –- 3rd execution at this value SQL> select count(1) from t_acs where n2 = :ln2; SQL> select child_number,bucket_id,count from v$sql_cs_histogram where sql_id = 'f2pmwazy1rnfd' ; CHILD_NUMBER BUCKET_ID COUNT ------------ ---------- ---------- 0 0 10 0 1 3 0 2 3 SQL> select fv_will_cs_be_bind_aware(10,3,3) acs from dual; ACS ---- Y next execution will compile a new plan ACS-bind aware secret sauce : all buckets involved
  • 50. 28/11/15 Mohamed Houri www.hourim.wordpress.com 50 SQL> exec :ln2 := 1000000 –- 4th execution at this value SQL> select count(1) from t_acs where n2 = :ln2; SQL> select child_number,bucket_id,count from v$sql_cs_histogram where sql_id = 'f2pmwazy1rnfd' ; CHILD_NUMBER BUCKET_ID COUNT ------------ ---------- ---------- 1 0 0 1 1 0 1 2 1 0 0 10 0 1 3 0 2 3 new execution plan compiled ACS-bind aware secret sauce : all buckets involved
  • 51. 28/11/15 Mohamed Houri www.hourim.wordpress.com 51 51 The next exection at any BUCKET will  mark the cursor bind aware  and a new execution plan will be compiled SQL> select fv_will_cs_be_bind_aware (pin_cnt_bucket_0 ,pin_cnt_bucket_1 ,pin_cnt_bucket_2 ) from dual; Existing plan will be shared N Y Not extensively tested!!! ACS-bind aware secret sauce : all buckets involved
  • 52. 28/11/15 Mohamed Houri www.hourim.wordpress.com 52 52 ACS-bind aware secret sauce : summary COUNT(BUCKET_ID 1) = COUNT(BUCKET_ID 0) ADJACENT BUCKET_ID (0-1 or 1-2) next execution will compile a new execution plan COUNT(BUCKET_ID 2) = CEIL(COUNT(BUCKET_ID 0) /3) next execution will compile a new execution plan DISTANT BUCKET_ID (0-2) select fv_will_cs_be_bind_aware (0,1,2) from dual; → Y next execution will compile a new execution plan ALL BUCKET_ID involved
  • 53. 28/11/15 Mohamed Houri www.hourim.wordpress.com 53 53 PART IV Extended Cursor Sharing Extended Cursor Sharing- ECS
  • 54. 28/11/15 Mohamed Houri www.hourim.wordpress.com 54 54 Extended Cursor Sharing Adaptive Cursor Sharing Extended Cursor Sharing is responsible for marking bind aware a bind sensitive cursor provided one of the 3 rules is satisfied is responsible for checking if an execution plan of a bind aware cursor has to be shared or a new plan has to be compiled according to the bind variable selectivity it peeks at each execution
  • 55. 28/11/15 Mohamed Houri www.hourim.wordpress.com 55 SQL> select sql_id ,child_number ,is_bind_sensitive ,is_bind_aware from v$sql where sql_id = 'f2pmwazy1rnfd'; SQL_ID CHILD_NUMBER IS_BIND_SENS IS_BIND_AWARE ------------- ------------ –----------- –------------- f2pmwazy1rnfd 0 Y N f2pmwazy1rnfd 1 Y Y once a cursor is bind aware a row exists in v$sql_cs_selectivity Extended Cursor Sharing
  • 56. 28/11/15 Mohamed Houri www.hourim.wordpress.com 56 SQL> select child_number ,predicate ,low ,high From v$sql_cs_selectivity where sql_id = 'f2pmwazy1rnfd'; CHILD_NUMBER PREDICATE LOW HIGH ------------ ------------- ---------- ---------- 2 =LN2 0.827448 1.011325 1 =LN2 0.000807 0.000986 Extended Cursor Sharing for each execution bind variable selectivity is checked: if it exists in one of the LOW-HIGH ranges then share plan. If not then compile a new plan and insert/update a new LOW-HIGH range this is ECS
  • 57. 28/11/15 Mohamed Houri www.hourim.wordpress.com 57 57 PART V Extended Cursor Sharing causing a performance issue When ACS (in fact ECS) becomes a serious performance threat
  • 58. 28/11/15 Mohamed Houri www.hourim.wordpress.com 58 SQL> select sql_id ,count(1) from v$sql where executions < 2 group by sql_id having count(1) > 10 order by 2 desc; SQL_ID COUNT(1) ------------- ---------- 7zwq7z1nj7vga 44217 Extended Cursor Sharing causing a performance issue Why this high nbr of versions?
  • 59. 28/11/15 Mohamed Houri www.hourim.wordpress.com 59 SQL> @nonshared 7zwq7z1nj7vga Show why existing SQL child cursors were not reused(V$SQL_SHARED_CURSOR) ----------------- SQL_ID : 7zwq7z1nj7vga ADDRESS : 000000406DBB30F8 CHILD_ADDRESS : 00000042CE36F7E8 CHILD_NUMBER : 99 BIND_EQUIV_FAILURE : Y REASON :<ChildNode><ChildNumber>0</ChildNumber><ID>40</ID> <reason>Bindmismatch(33)</reason><size>2x4</size> <init_ranges_in_first_pass>0</init_ranges_in_first_pass> <selectivity>1097868685</selectivity> </ChildNode> Extended Cursor Sharing causing a performance issue 100 exec plans (0-99) due to bind_equivalent_failure
  • 60. 28/11/15 Mohamed Houri www.hourim.wordpress.com 60 SQL> select count(1) from v$sql_shared_cursor Where sql_id = '7zwq7z1nj7vga'; COUNT(1) ---------- 45125 SQL> select count(1) from v$sql_shared_cursor Where sql_id = '7zwq7z1nj7vga' and BIND_EQUIV_FAILURE = 'Y'; COUNT(1) ---------- 45121 99% of non shared cursors are due to BIND_EQUIV_FAILURE Extended Cursor Sharing causing a performance issue
  • 61. 28/11/15 Mohamed Houri www.hourim.wordpress.com 61 BIND_EQUIV_FAILURE : bind value's selectivity does not match that used to optimize the existing child cursor SQL> select count(1) from v$sql_cs_selectivity where sql_id = '7zwq7z1nj7vga'; COUNT(1) ---------- 16,847,320 !!! for each execution ECS will check this view!!! Extended Cursor Sharing causing a performance issue CHILD_NUMBER PREDICATE LOW HIGH ------------ ------------- ---------- ---------- 2 =LN2 0.827448 1.011325
  • 62. 28/11/15 Mohamed Houri www.hourim.wordpress.com 62 Extended Cursor Sharing causing a performance issue Run a query using a bind aware cursor Oracle (ECS layer code) will do behind the scene: 1. peeks at the bind variable value 2. runs a query against v$sql_cs_selectivity(16M of rows) 3. if low < selectivity < high then share existing plan 4. if selectity not found in low-high range then hard parse a new plan If another user executes the same query: 1. Oracle will try to do the above 1-4 steps 2. if Oracle is still busy with above 1-4 steps then we start experiencing: a) cursor: pin S wait on X b) library cache lock
  • 63. 28/11/15 Mohamed Houri www.hourim.wordpress.com 63 63 PART V Adaptive-Extended Cursor Sharing FINAL ACS-ECS DIAGRAM https://hourim.wordpress.com/2015/08/12/adaptive-cursor-sharing-triggering-mechanism/
  • 64. 28/11/15 Mohamed Houri www.hourim.wordpress.com 64 64 Adaptive Cursor Sharing •Conclusion • Literal variables are good for query performance • very bad for resource and memory • and they produce a non scalable application • Bind variables are not always good for query performance • very good for resource and memory • and they produce a scalable application • Adaptive cursor sharing allows query good performance • even when using bind variable • but be aware of the extra parsing work it might introduce