Upload
danghuong
View
226
Download
0
Embed Size (px)
Citation preview
www.sagecomputing.com.au
New Optimizer Features
in Oracle 12c
Penny Cookson SAGE Computing Services
SAGE Computing Services
Customised Oracle Training Workshops and Consulting
SAGE Computing Services
Customised Oracle Training Workshops and Consulting
Penny Cookson
Managing Director and Principal Consultant
Working with Oracle products since 1987
Oracle Magazine Educator of the Year 2004
www.sagecomputing.com.au
A long time ago in
a distant galaxy
And finally….
Oracle 12c
is here!
the evil emperor
promised to create
a new version of
his weapon
Agenda
Adaptive Optimisation
Adaptive Plans
Dynamic Sampling
Cardinality Feedback
SQL Plan directives
Other Stuff
VARCHAR2
Optimizer Statistics
Better histograms
Bulk Loads
Automatic creation of column
statistics groups
Session-private statistics for
global temporary tables
Reporting Mode
Reporting on Past Operations
X X X X X X X X X X X Dynamic Statistics
Stopping the worst
stuff ups (1st time)
X X X X X X X X X X X Statistics Feedback
Now witness the firepower of
this fully ARMED and
OPERATIONAL battle station!
You know that moment when you realise
that Plan A is not going to work
And you really need to try Plan B
That’s Adaptive Optimisation
During optimization – not re-optimization
Join methods (Hash and NL) and Parallel distribution methods
Adaptive Optimization – Adaptive Plans
Sub Plan (B)
Sub Plan (A)
Hash
Nested
Loop
You will find that it is you who
are mistaken, about a great
many things
Adaptive Optimization – Adaptive Plans
Sub Plan (B)
Sub Plan (A)
Hash
Nested
Loop Start
reading
rows
<threshold
>=threshold
Collector gathers statistics during execution
During execution you
realise you have
underestimated the
power of the Hash Side
Adaptive Optimization – Adaptive Plans
Sub Plan (B)
Sub Plan (A)
Hash
Nested
Loop Read
rows
<threshold
>=threshold
Next time it just chooses the same plan Everything is
proceeding as I
have foreseen
Organisations
Bookings
_Large Events
Resources
name = 'Australian Medical Systems'
description = 'Buffet Lunch'
comments = 'TEST'
This IS the join we are
looking for
Adaptive Plans - Example
What is the Threshold – 10053 trace
Join order[4]: ORGANISATIONS[O]#0 EVENTS_LARGE[E]#2 BOOKINGS_LARGE[B]#3
RESOURCES[R]#1
………………………………………………………………………………………………………………………………………………………………………….
Outer table: ORGANISATIONS Alias: O
resc: 3.00 card 1.00 bytes: 26 deg: 1 resp: 3.00
Inner table: EVENTS_LARGE Alias: E
resc: 273.01 card: 75243.00 bytes: 17 deg: 1 resp: 273.01
using dmeth: 2 #groups: 1
Cost per ptn: 0.21 #ptns: 1
hash_area: 203 (max=25600) buildfrag: 1 probefrag: 267 ppasses: 1
Hash join: Resc: 276.22 Resp: 276.22 [multiMatchCost=0.00]
HA Join
HA cost: 276.22
resc: 276.22 resc_io: 275.00 resc_cpu: 47387417
resp: 276.22 resp_io: 275.00 resp_cpu: 47387417
Best:: JoinMethod: Hash
Cost: 276.22 Degree: 1 Resp: 276.22 Card: 12540.50 Bytes: 43
How many
Events are
we expecting
What is the Threshold – 10053 trace
***************
Now joining: BOOKINGS_LARGE[B]#3
***************
Outer table: EVENTS_LARGE Alias: E
resc: 276.22 card 12540.50 bytes: 43 deg: 1 resp: 276.22
Inner table: BOOKINGS_LARGE Alias: B
resc: 9695.37 card: 5767168.00 bytes: 19 deg: 1 resp: 9695.37
………………………………………………………………………………………………………………………………………………………………………….
…………………………………………… works out the best join order ……………………………………….
………………………………………………………………………………………………………………………………………………………………………….
*********************************
Number of join permutations tried: 20
*********************************
………………………………………………………………………………………………………………………………………………………………………….
Searching for inflection point (join #1)
What if there are less events than we
expect?
Searching for inflection point (join #2) between 0.00 and 12540.50
AP: Computing costs for inflection point at min value 0.00
DP: Using binary search for inflection point search
DP: Costing Nested Loops Join for inflection point at card 0.00
………………………………………………………………………………………………………………………………………………………………………….
DP: Costing Hash Join for inflection point at card 0.00
………………………………………………………………………………………………………………………………………………………………………….
DP: Costing Nested Loops Join for inflection point at card 12540.50
………………………………………………………………………………………………………………………………………………………………………….
DP: Costing Hash Join for inflection point at card 12540.50
………………………………………………………………………………………………………………………………………………………………………….
DP: Costing Nested Loops Join for inflection point at card 9695.37
………………………………………………………………………………………………………………………………………………………………………….
DP: Costing Hash Join for inflection point at card 9695.37
………………………………………………………………………………………………………………………………………………………………………….
………………………………………………………………………………………………………………………………………………………………………….
DP: Found point of inflection for NLJ vs. HJ: card = 164.56
What if there are less Events than we
expect?
BEGIN
dbms_spd.flush_sql_plan_directive;
END;
/
SELECT d.directive_id, d.type, d.state, d.reason, d.created,
o.object_name, o.subobject_name, o.notes, o.owner
FROM dba_sql_plan_directives d, dba_sql_plan_dir_objects o
WHERE o.directive_id = d.directive_id
AND o.owner NOT IN ('XDB','SYS','SYSTEM')
ORDER BY directive_id desc;
Is the information
saved?
Adaptive Optimisation
OPTIMIZER_FEATURES_ENABLE >= 12.1.0.1
OPTIMIZER_ADAPTIVE_FEATURES = true
OPTIMIZER_ADAPTIVE_REPORTING_ONLY = false
Always in motion is
the Oracle version
Adaptive Optimisation
SELECT
DBMS_XPLAN.DISPLAY_CURSOR ('89xrxq7gghfdm',0, FORMAT=>'+REPORT')
FROM dual;
Storm Trooper Conference
Base it on our existing statistics
How many chairs do
we need in the main
room?
Storm Trooper Conference
Base it on our existing statistics and the
feedback from this morning
How many chairs do
we need in the main
room?
Dynamic Statistics
Dynamic stats considered when:
OPTIMIZER_DYNAMIC_SAMPLING = default (2)
DYNAMIC_SAMPLING hint
Parallel
No/old statistics
Expressions
Complex predicates (OR or AND on 1 table)
Joins/Group By
(12) Shareable
(12) Automatic dynamic sampling for level 11
Dynamic Statistics
When should we use them?
Stats not right
Stable table Volatile table
Get a new DBA TP or DWH
database?
Unknown conditions
Dynamic stats at
session/task level
TP
Dynamic stats at
DB level
DWH
Get a new DBA
TP DWH
TP or DWH
database?
Adaptive Optimisation Summary
During Execution
Adaptive Plans
NL or Hash
Parallel
distribution
Dynamic
statistics Adaptive Statistics
SQL Plan
directives
Cardinality
Adaptive Optimisation Summary
Re-optimisation
Statistics
feedback
SQL Plan
directives
Next hard
parse
Only SQL Plan Management
deals in absolutes
Dynamic
Statistics
Adaptive Optimisation Summary
Feature Bind Vars
/Literals
Conditions When
Adaptive Plan Literals and
bind variables
Join method, Parallelisation During
Statistics
Feedback
Literals but
works with
Adaptive
cursors for
bind variables
Complex conditions
joins
Re-Opt but stores as SPD
Adaptive cursor Bind variables Skewed data and histogram During - /*+BIND_AWARE */
Or Re-opt
Dynamic
Statistics
Literals and
Bind Variables
Dependent on level
no stats, old stats, complex
conditions
During
Optimisation Enhancements
Adaptive optimisation is good for the multi table
dependencies that statistics cannot help with
Need for some statistics feedback can be removed
by correct statistics – watch the plan directives
Dynamic stats can help with weird query
combinations and volatile tables
Improved Statistics
Size matters not. Look at me.
Judge me by my size, do you?
Male Jedis always say that.
It matters to the optimizer
12g -Histograms
Top Frequency Histogram
7 distinct values
5 buckets
Top 5 values occurs >= (1 – 1/5)*100 pct = 80%
estimate_percent = AUTO_SAMPLE_SIZE
Hybrid Histogram
12g -Histograms
2 4 6 3 Repeat Count
7 distinct values
5 buckets
Top 5 values occurs < (1 – 1/5)*100 pct = 80%
3
12g -Histograms
Height balanced histograms
stop using you should
Estimate_percent = integer
do not use
11g – Create Statistics on a
Column Group
dbms_stats.create_extended_stats
('TRAIN',‘ORG','(STATE, POSTCODE)');
Running Statistics in Reporting Mode
SET LINES 100 PAGES 0
SET LONG 100000
COLUMN REPORT FORMAT A200
VARIABLE stats_report CLOB;
BEGIN
:stats_report :=
dbms_stats.report_gather_schema_stats
(ownname=>'TRAIN',
detail_level=>'ALL',
format=>'HTML');
END;
Reporting on Past Statistics
SET LINES 100 PAGES 0
SET LONG 100000
COLUMN REPORT FORMAT A200
VARIABLE stats_report CLOB;
BEGIN
:stats_report := dbms_stats.report_stats_operations
(since=>sysdate-2,
until=>sysdate,
detail_level=>'ALL',
format=>'HTML');
END;
Session specific statistics for global
temporary tables
Session specific statistics
on global temporary
tables
Increase in Limit for VARCHAR2
ID COMMENTS
13 XXXX XXXX
14 XXXX XXXX
15 XXXX XXXX
ID COMMENTS
13 XXXX XXXX XXXXXXX XXXXXXX XX
14 XXXX XXXX XXXXXXX XXXXXXX XX
15 XXXX XXXX XXXXXXX XXXXXXX XX
VARCHAR2(4000) VARCHAR2(32767)