Dig into details on how Oracle has implemented Adaptive Cursor Sharing feature to make using bind variables and having optimal plans at each query execution possible
Troubleshooting Complex Oracle Performance Problems with Tanel PoderTanel Poder
Troubleshooting Complex Oracle Performance Problems hacking session & presentation by Tanel Poder.
This presentation is about a complex performance issue where the initial symptoms pointed somewhere else than the root cause. Only when systematically following through the troubleshooting drilldown method, we get to the root cause of the problem. This session aims to help you understand (and reason about) the Oracle’s multi-process & multi-layer system behavior, preparing you for independent troubleshooting of such complex performance issues in the future.
Video recordings of this presentation are in my YouTube channel:
1) Hacking Session: https://www.youtube.com/watch?v=INQewGJMdCI
2) Presentation: https://www.youtube.com/watch?v=aaHZ8A8Ygdg
Tanel's blog and training information: https://blog.tanelpoder.com/seminar
Troubleshooting Complex Oracle Performance Problems with Tanel PoderTanel Poder
Troubleshooting Complex Oracle Performance Problems hacking session & presentation by Tanel Poder.
This presentation is about a complex performance issue where the initial symptoms pointed somewhere else than the root cause. Only when systematically following through the troubleshooting drilldown method, we get to the root cause of the problem. This session aims to help you understand (and reason about) the Oracle’s multi-process & multi-layer system behavior, preparing you for independent troubleshooting of such complex performance issues in the future.
Video recordings of this presentation are in my YouTube channel:
1) Hacking Session: https://www.youtube.com/watch?v=INQewGJMdCI
2) Presentation: https://www.youtube.com/watch?v=aaHZ8A8Ygdg
Tanel's blog and training information: https://blog.tanelpoder.com/seminar
Farm Africa has received a new £3 million grant from the UK Government, through the FoodTrade East and Southern Africa trade enhancement and promotion programme.
GEODI : a Practical Information Management Solution For Construction Sectorserdarak2
GEODI is an Innovative Solution which reads and Interprets any kind of content from many different sources by using Natural Language Processing and Machine Learning.
Understanding How is that Adaptive Cursor Sharing (ACS) produces multiple Opt...Carlos Sierra
Adaptive Cursor Sharing (ACS) is a feature available since 11g. It is enabled by default. ACS can help to generate multiple non-persistent Optimal Execution Plans for a given SQL. But it requires a sequence of events for it to get truly activated. This presentation describes what is ACS, when it is used and when it is not. Then it demonstrates ACS capabilities and limitations with a live demo.
This session is about: How Adaptive Cursor Sharing (ACS) actually works. How a bind sensitive cursor becomes bind aware. What are those "ACS buckets". How the "Selectivity Profile" works. Why sometimes your SQL becomes bind aware and why sometimes it does not. How is that ACS interacts with SQL Plan Management (SPM). These and other questions about ACS are answered in detail.
Some live demonstrations are used to illustrate the ramp-up process on ACS and how some child cursors are created then flagged as non-shareable. You will also "see" how the ACS Selectivity Profile is adapted as new executions make use of predicates with new Selectivities. ACS promotes Plan Flexibility while SPM promotes Plan Stability. Understanding how these duo interacts becomes of great value when some gentle intervention is needed to restore this delicate balance.
This session is for those Developers and DBAs that "need" to understand how things work. ACS can be seen as a back-box; or you can "look" inside and understand how it actually works. If you are curious about the ACS functionality, then this Session brings some light. Consider this session only if you are pretty familiar with Cursor Sharing, Binds, Plan Stability and Plan Flexibility.
Managing Statistics for Optimal Query PerformanceKaren Morton
Half the battle of writing good SQL is in understanding how the Oracle query optimizer analyzes your code and applies statistics in order to derive the “best” execution plan. The other half of the battle is successfully applying that knowledge to the databases that you manage. The optimizer uses statistics as input to develop query execution plans, and so these statistics are the foundation of good plans. If the statistics supplied aren’t representative of your actual data, you can expect bad plans. However, if the statistics are representative of your data, then the optimizer will probably choose an optimal plan.
This paper describes the evolution of the Plan table and DBMSX_PLAN in 11g and some of the features that can be used to troubelshoot SQL performance effectively and efficiently.
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
Climate Impact of Software Testing at Nordic Testing DaysKari Kakkonen
My slides at Nordic Testing Days 6.6.2024
Climate impact / sustainability of software testing discussed on the talk. ICT and testing must carry their part of global responsibility to help with the climat warming. We can minimize the carbon footprint but we can also have a carbon handprint, a positive impact on the climate. Quality characteristics can be added with sustainability, and then measured continuously. Test environments can be used less, and in smaller scale and on demand. Test techniques can be used in optimizing or minimizing number of tests. Test automation can be used to speed up testing.
Securing your Kubernetes cluster_ a step-by-step guide to success !KatiaHIMEUR1
Today, after several years of existence, an extremely active community and an ultra-dynamic ecosystem, Kubernetes has established itself as the de facto standard in container orchestration. Thanks to a wide range of managed services, it has never been so easy to set up a ready-to-use Kubernetes cluster.
However, this ease of use means that the subject of security in Kubernetes is often left for later, or even neglected. This exposes companies to significant risks.
In this talk, I'll show you step-by-step how to secure your Kubernetes cluster for greater peace of mind and reliability.
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Albert Hoitingh
In this session I delve into the encryption technology used in Microsoft 365 and Microsoft Purview. Including the concepts of Customer Key and Double Key Encryption.
Essentials of Automations: The Art of Triggers and Actions in FMESafe Software
In this second installment of our Essentials of Automations webinar series, we’ll explore the landscape of triggers and actions, guiding you through the nuances of authoring and adapting workspaces for seamless automations. Gain an understanding of the full spectrum of triggers and actions available in FME, empowering you to enhance your workspaces for efficient automation.
We’ll kick things off by showcasing the most commonly used event-based triggers, introducing you to various automation workflows like manual triggers, schedules, directory watchers, and more. Plus, see how these elements play out in real scenarios.
Whether you’re tweaking your current setup or building from the ground up, this session will arm you with the tools and insights needed to transform your FME usage into a powerhouse of productivity. Join us to discover effective strategies that simplify complex processes, enhancing your productivity and transforming your data management practices with FME. Let’s turn complexity into clarity and make your workspaces work wonders!
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
PHP Frameworks: I want to break free (IPC Berlin 2024)Ralf Eggert
In this presentation, we examine the challenges and limitations of relying too heavily on PHP frameworks in web development. We discuss the history of PHP and its frameworks to understand how this dependence has evolved. The focus will be on providing concrete tips and strategies to reduce reliance on these frameworks, based on real-world examples and practical considerations. The goal is to equip developers with the skills and knowledge to create more flexible and future-proof web applications. We'll explore the importance of maintaining autonomy in a rapidly changing tech landscape and how to make informed decisions in PHP development.
This talk is aimed at encouraging a more independent approach to using PHP frameworks, moving towards a more flexible and future-proof approach to PHP development.
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionAggregage
Join Maher Hanafi, VP of Engineering at Betterworks, in this new session where he'll share a practical framework to transform Gen AI prototypes into impactful products! He'll delve into the complexities of data collection and management, model selection and optimization, and ensuring security, scalability, and responsible use.
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...Neo4j
Leonard Jayamohan, Partner & Generative AI Lead, Deloitte
This keynote will reveal how Deloitte leverages Neo4j’s graph power for groundbreaking digital twin solutions, achieving a staggering 100x performance boost. Discover the essential role knowledge graphs play in successful generative AI implementations. Plus, get an exclusive look at an innovative Neo4j + Generative AI solution Deloitte is developing in-house.
Communications Mining Series - Zero to Hero - Session 1DianaGray10
This session provides introduction to UiPath Communication Mining, importance and platform overview. You will acquire a good understand of the phases in Communication Mining as we go over the platform with you. Topics covered:
• Communication Mining Overview
• Why is it important?
• How can it help today’s business and the benefits
• Phases in Communication Mining
• Demo on Platform overview
• Q/A
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
Dr. Sean Tan, Head of Data Science, Changi Airport Group
Discover how Changi Airport Group (CAG) leverages graph technologies and generative AI to revolutionize their search capabilities. This session delves into the unique search needs of CAG’s diverse passengers and customers, showcasing how graph data structures enhance the accuracy and relevance of AI-generated search results, mitigating the risk of “hallucinations” and improving the overall customer journey.
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfPeter Spielvogel
Building better applications for business users with SAP Fiori.
• What is SAP Fiori and why it matters to you
• How a better user experience drives measurable business benefits
• How to get started with SAP Fiori today
• How SAP Fiori elements accelerates application development
• How SAP Build Code includes SAP Fiori tools and other generative artificial intelligence capabilities
• How SAP Fiori paves the way for using AI in SAP apps
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
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
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
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