12c Adaptive OptimizationV2
12c Adaptive OptimizationV2
Blog: kerryosborne.oracle-guy.com
Twitter: @KerryOracleGuy
3
Top Secret Feature of BDA
4
What I Did Last Week
5
What’s the Point?
6
How Does the Optimizer Mess Up?
Cardinality – Misunderestimate
mostly …
and it’s pretty easy to recognize …
7
Cardinality – Misunderestimate
8
Cardinality – Misunderestimate
9
Optimizer Evolution
10
11
Adaptive Optimization
Improve Improve
Initial Adaptive Query Subsequent
Execution Optimization Executions
Join Parallel At At
Methods Distribution Compile Run Time
Methods Time
Cardinality Feedback
Dynamic Sampling
12
But First – Some New Terms
13
Adaptive Execution Plans
Join Methods
Adaptive Query
Optimization
Join Parallel At At
Methods Distribution Compile Run Time
Methods Time
14
Adaptive Execution Plans
Join Methods
• 2 Join Methods
• Nested Loop
• Hash Join
15
Adaptive Optimization
Controls
optimizer_adaptive_features = false
- big switch - controls all adaptive stuff
optimizer_adaptive_reporting_only = true
_optimizer_adaptive_plans=false
- individual control for adaptive plans
_optimizer_use_feedback=false
- individual control for cardinality feedback
optimizer_dynamic_sampling=0
- individual control for dynamic sampling
16
Adaptive Execution Plans
17
Adaptive Execution Plans
18
Adaptive Execution Plans
Finding Them (is easy)
19
Digression - OTHER_XML
20
Digression - OTHER_XML
21
Adaptive Execution Plans
Displaying Default & Final Plans
Produces plan which shows steps which were abandoned in final plan.
Abandoned steps are marked with a “-”
22
Adaptive Execution Plans
Displaying Default Plan
23
Adaptive Execution Plans
Displaying Final Plan
24
Adaptive Execution Plans
Displaying Adaptive Plans
Abandoned
25
Adaptive Execution Plans
Displaying Adaptive Plans (+report)
26
Adaptive Execution Plans
Displaying Adaptive Plans (+report)
27
Adaptive Execution Plans
SPM Interaction
28
Adaptive Execution Plans
SPM Interaction
29
Adaptive Execution Plans
Parallel Distribution Methods
Adaptive Query
Optimization
Join Parallel At At
Methods Distribution Compile Run Time
Methods Time
30
Adaptive Distribution Methods
New adaptive distribution method HYBRID-HASH
Statistic collectors inserted in front of PX process
If actual number of rows less than threshold, switch from HASH to Broadcast
Threshold number of total rows < 2x DOP
Enabled by default
31
Adaptive Distribution Methods
Distribution
Statistics
method decision
based on
expected number p1 p5
of rows
Cardinality based
p2 p6
distribution skew
is common p3 p7
Can result in very
uneven p4 p8
distribution
Hybrid-
Hash
Broadcast
32
Adaptive Statistics
Dynamic Statistics (Sampling)
Adaptive Query
Optimization
Join Parallel At At
Methods Distribution Compile Run Time
Methods Time
Dynamic Sampling
33
Dynamic Statistics
Dynamic statistics are used to compensate for missing,
stale, or incomplete statistics
They can be used for table scans, index access, and joins
34
Dynamic Statistics
35
Adaptive Statistics
Dynamic Statistics (Sampling)
Adaptive Query
Optimization
Join Parallel At At
Methods Distribution Compile Run Time
Methods Time
Cardinality Feedback
36
Adaptive Statistics
Re-optimization
37
Cardinality Feedback – 11g
Statistics gathered about data volume and data type seen during execution
Statements are only monitored once if they don’t show significant differences
initially they won’t change in the future
Only individual table cardinalities and group by estimates examined – not joins
Information is stored in the cursor only and is lost if cursor ages out
38
Adaptive Statistics
New Re-optimization
39
SQL Plan Directives
“SPD are objects generated automatically by Oracle. For example, if Oracle detects
that the single table cardinality estimated made by the optimizer is different from the
actual number of rows returned when accessing the table, it will automatically create
a directive to perform dynamic statistics for the table. When any SQL statement
referencing the table is compiled, the optimizer will perform dynamic statistics for
the table to get a more accurate estimate.”
40
SQL Plan Directives
41
SQL Plan Directives
42
SQL Plan Directives
43
SQL Plan Directives
44
SQL Plan Directives
States
NEW - 1st pass
45
SQL Plan Directives
Management
46
Well, How Did We Get Here?
47
Wrap Up
48
Questions?
Contact Information : Kerry Osborne
kerry.osborne@enkitec.com
kerryosborne.oracle-guy.com
www.enkitec.com
49