SQL Plan Management with
Oracle Database
Who Am I ?
Oracle OCP 12c
OCE 11g PT
OCE 11g RAC
Senior Specialist at RT Labs
The guy on the right ^_^
SPM
Stability
SQL Profiles
Stored
Outlines
SQL Patches SQL Baselines
Instability
Statistics
Cardinality
Feedback
Bind Variable
Peeking
Adaptive
Cursor Sharing
12 New
Features
Adaptive plans
Adaptive
statistics
Presentation plan
E-ROWS !=A-ROWS
• When estimated rows != actual rows
----------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| A-Rows | A-Time | Buffers | Reads |
----------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 1049 (100)| 0 |00:00:00.36 | 11000 | 6588 |
| 1 | NESTED LOOPS | | 1 | 100 | 1049 (3)| 0 |00:00:00.36 | 11000 | 6588 |
| 2 | NESTED LOOPS | | 1 | 100 | 1049 (3)| 2000 |00:00:00.35 | 9000 | 6552 |
|* 3 | TABLE ACCESS FULL | T1 | 1 | 100 | 849 (4)| 2000 |00:00:00.30 | 6554 | 6551 |
|* 4 | INDEX UNIQUE SCAN | T2_PK | 2000 | 1 | 1 (0)| 2000 |00:00:00.02 | 2446 | 1 |
|* 5 | TABLE ACCESS BY INDEX ROWID| T2 | 2000 | 1 | 2 (0)| 0 |00:00:00.01 | 2000 | 36 |
----------------------------------------------------------------------------------------------------------------------
Presentation plan
SPM
Stability
SQL Profiles
Stored
Outlines
SQL Patches SQL Baselines
Instability
Statistics
Cardinality
Feedback
Bind Variable
Peeking
Adaptive
Cursor Sharing
12 New
Features
Adaptive plans
Adaptive
statistics
SQL Profiles
• created by SQL Tunning Advisor
• enabled by default
• can be applied to multiple statements ( force_matching )
• using OPT_ESTIMATE hints
• invalid hints silently ignored
• has procedure to import hints ( import_sql_profile )
• uses categories (default by default )
Profiles, what is inside ?
OUTLINE_HINTS
------------------------------------------------------------------------------------------------------------
OPT_ESTIMATE(@"SEL$4C54F62B", NLJ_INDEX_FILTER, "THIS_"@"SEL$2", ("THIS_1_"@"SEL$2"), "FDC_LOT_PK",
SCALE_ROWS=0.4164795196)
OPT_ESTIMATE(@"SEL$4C54F62B", NLJ_INDEX_SCAN, "THIS_"@"SEL$2", ("THIS_1_"@"SEL$2"), "FDC_LOT_PK",
SCALE_ROWS=0.4164795196)
OPT_ESTIMATE(@"SEL$4C54F62B", NLJ_INDEX_FILTER, "THIS_1_"@"SEL$2", ("NOTIFICATI1_"@"SEL$3",
"THIS_"@"SEL$2", "P"@"SEL$7"), "FDC_LOT_SHARED_BASE_I", SCALE_ROWS=5.662569566e-06)
OPT_ESTIMATE(@"SEL$4C54F62B", JOIN, ("NOTIFICATI1_"@"SEL$3", "P"@"SEL$7"),
SCALE_ROWS=0.4236734421)
OPTIMIZER_FEATURES_ENABLE(default)
Wolfgang Breitling: Tunning by cardinality feedback
Presentation plan
SPM
Stability
SQL Profiles
Stored
Outlines
SQL Patches SQL Baselines
Instability
Statistics
Cardinality
Feedback
Bind Variable
Peeking
Adaptive
Cursor Sharing
12 New
Features
Adaptive plans
Adaptive
statistics
Stored Outlines
• not enabled in every session by default
• need to use use_stored_outlines=true
• Overrides (disables ) Profiles,Patches and Bselines
• need logon trigger to enable on startup
• invalid hints silently ignored
• work in 11c,12c but deprecated
• uses categories
Presentation plan
SPM
Stability
SQL Profiles
Stored
Outlines
SQL Patches SQL Baselines
Instability
Statistics
Cardinality
Feedback
Bind Variable
Peeking
Adaptive
Cursor Sharing
12 New
Features
Adaptive plans
Adaptive
statistics
SQL Patches
• Created by SQL Repair Advisor ( dbms_sqldiag )
• MOS Note 215187.1 SQLT has a script to generate manual SQL Profiles
• enabled by default
• No force matching
• Invalid hints silently ignored
• Can import hints
• dbms_sqldiag_internal.i_create_patch
• Capable of applying any valid hints
• Hints can be merged with Profiles and Baselines
Hints can be merged with Profiles and Baselines
SQL_ID c7q8y75rh36sc, child number 1
-------------------------------------
select /* test */ avg(pk_col) from skew where col1 = 23489
Plan hash value: 3723858078
------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 36 (100) | |
| 1 | SORTAGGREGATE | | 1 | 11 | | |
| 2 | TABLE ACCESS BY INDEX ROWID | SKEW | 35 | 385 | 36 (0) |00:00:01 |
|* 3 | INDEX RANGE SCAN | SKEW_COL1 | 37 | | 3 (0) |00:00:01 |
------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("COL1"=23489)
Note -----
- SQL profile PROF_c7q8y75rh36sc_3723858078 used for this statement
- SQL patch "KSO_c7q8y75rh36sc_MANUAL" used for this statement
- SQL plan baseline SQLID_C7Q8Y75RH36SC_3723858078 used for this statement
Presentation plan
SPM
Stability
SQL Profiles
Stored
Outlines
SQL Patches SQL Baselines
Instability
Statistics
Cardinality
Feedback
Bind Variable
Peeking
Adaptive
Cursor Sharing
12 New
Features
Adaptive plans
Adaptive
statistics
SQL Baselines
• Overriden by Outlines
• Provides procedure to import plans ( dbms_spm.load_plans_from_cursor_cache )
• Invalid hints NOT silently ignored
• Has associated plan_hash_value
• Capable to apply any valid hints
• Enabled by default
• Closer to outlines than to SQL Profiles
• Goal was to prevent performance regression
• Can have multiple Baselines per statement
• Can work with Profiles and Patches ( merges hints )
• Can be bulk loaded from
• Outlines
• SQL Tunning Set
• via optimizer_capture_sql_plan_baselines=true
• the cursor cache
What’s inside?
• A plan hash value
• hints to reproduce the plan
• Signature ( no sql_id )
SQL_PLAN_61c4s16v476sm308a34f6
NO HINTS
HINTS
Presentation plan
SPM
Stability
SQL Profiles
Stored
Outlines
SQL Patches SQL Baselines
Instability
Statistics
Cardinality
Feedback
Bind Variable
Peeking
Adaptive
Cursor Sharing
12 New
Features
Adaptive plans
Adaptive
statistics
Cardinality Feedback
• Was introduced in Oracle Database 11gR2
• Cardinality feedback monitoring may be enabled in the following
cases:
• tables with no statistics
• multiple conjunctive or disjunctive filter predicates on a table
• predicates containing complex operators that the optimizer cannot accurately
compute selectivity estimates for
• dynamic sampling or multi-column statistics allow the optimizer to more
accurately estimate selectivity of conjunctive predicates. In cases where
these techniques apply, cardinality feedback is not enabled.
@Desktop/Card_feedback_demo.sql
Presentation plan
SPM
Stability
SQL Profiles
Stored
Outlines
SQL Patches SQL Baselines
Instability
Statistics
Cardinality
Feedback
Bind Variable
Peeking
Adaptive
Cursor Sharing
12 New
Features
Adaptive plans
Adaptive
statistics
Bind Variable Peeking
Upgrade to 11g and let Adaptive Cursor Sharing take care of all your problems
Adaptive Cursor Sharing: Overview (Doc ID
740052.1)
SELECT child_number,
bucket_id,
count
FROM v$sql_cs_histogram
WHERE sql_id = '04pq01r0y8208'
ORDER BY child_number, bucket_id;
CHILD_NUMBER | BUCKET_ID | COUNT
------------ | ---------- | ----------
0 | 0 | 742
0 | 1 | 19
0 | 2 | 0
1 | 0 | 1031
1 | 1 | 51
1 | 2 | 0
2 | 0 | 1774
2 | 1 | 34
2 | 2 | 0
The first one (bucket_id equal 0) is associated
with the executions that are considered efficient
the second one (bucket_id equal 1) with the
executions that are considered inefficient
and the third one (bucket_id equal 2)
with the very inefficient executions
Adaptive Query Optimization
Adaptive
Plans
Join Methods
Parallel
Distribution
Methods
Adaptive
Statistics
Dynamic
Statistics
SQL Plan
Directives
12c New Features
Adaptive Query Optimization
Adaptive
Plans
Join Methods
Parallel
Distribution
Methods
Adaptive
Statistics
Dynamic
Statistics
SQL Plan
Directives
12c New Features
Join methods
• Nested Loops Joins
• Hash Joins
• Sort Merge Joins
• Cartesian Joins
• Purpose of Adaptive
Plans
How to find adaptive plans ?
• It’s easy
• select sql_id,child_number,substr ( replace(replace (sql_text,chr(10),' '),chr(13),' '),1,100)
text,IS_RESOLVED_ADAPTIVE_PLAN,IS_REOPTIMIZABLE from v$sql where IS_RESOLVED_ADAPTIVE_PLAN='Y';
Adaptive Query Optimization
Adaptive
Plans
Join Methods
Parallel
Distribution
Methods
Adaptive
Statistics
Dynamic
Statistics
SQL Plan
Directives
12c New Features
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 < 2xDOP
• Enabled by default
• If you want more read the articles of Randolf Geist ( link )
Adaptive Query Optimization
Adaptive
Plans
Join Methods
Parallel
Distribution
Methods
Adaptive
Statistics
Dynamic
Statistics
SQL Plan
Directives
12c New Features
Optimizer Dynamic Statistics (OPTIMIZER_DYNAMIC_SAMPLING)
(Doc ID 336267.1)
Level When Optimizer Uses Dynamic Statistis Sample Size (
blocks )
0 Do not use dynamic statistics 0
1 Use dynamic statistics for all tables that do not have statistics, but only if the
following criteria are met: There is at least 1 non partitioned table in the query that
does not have statistics. This table has no indexes. This table has more blocks than
the number of blocks that would be used for dynamic statistics of this table.
32
2 Use dynamic statistics if at least one table in the statement has no statistics. This is
the default setting.
64
3 As per Level 2, plus all tables for which standard selectivity estimates used a guess
for some predicate that is a potential dynamic sampling predicate.
64
4 As per Level 3, plus all tables that have complex predicate expressions (for example
single-table predicates that reference 2 or more columns or non-equality where
clause predicates on two correlated columns).
64
5 As per Level 4 with a larger sample size each time. 128
6 As per Level 4 with a larger sample size each time. 256
7 As per Level 4 with a larger sample size each time. 512
8 As per Level 4 with a larger sample size each time. 1024
9 As per Level 4 with a larger sample size each time. 4096
10 Use dynamic sampling for all statements sampling All blocks All
11 (11gR2 11.2.0.4 and above) The Optimizer will automatically decide if dynamic
statistics will be useful, and what dynamic sampling level will be used for SQL
statements.
Automagical
stuff
Dynamic statistics 12c version. What’s New
• Join statistics are monitored
• Works with adaptive cursor sharing for statement with binds
• New Column in V$SQL IS_REOPTIMIZABLE
• Information found at execution time is persisted as SQL Plan
Directives
• Dynamic statistics (Doc ID 2002108.1)
Adaptive Query Optimization
Adaptive
Plans
Join Methods
Parallel
Distribution
Methods
Adaptive
Statistics
Dynamic
Statistics
SQL Plan
Directives
12c New Features
SQL Plan Directives
What was already there in 11g :
• Cardinality feedback
• Estimated cardinalities are checked at execution time
• Actual cardinalities are stored with cursor for future re-optimization
• Not persistent
• Extended statistics
• Gathers statistics on group of columns, or functions
• Defined manually or from through ā€˜seed column usage’
• Dynamic sampling
SQL Plan Directives
A 12c new features
sql plan directive might instruct the optimizer to :
• Collect missing statistics
• Create column group statistics
• Perform dynamic statistics (Dynamic Sampling).
• Only when we know that more statistics can help
• SPD is created when statement is marked as reoptimizable
SPD Persistent
• In memory
• Are not used by optimizer when only in memory (shared pool)
• Are not exported when only in memory: must flush before
• Flushed every 15 minutes
• Stored in SYSAUX
• Flushed manually
• exec dbms_spd.flush_sql_plan_directive;
SQL Plan Directives States Internal States
NEW
MiSSING STATS
HAS STATS
PERMANENT
Statement reoptimizable
Dynamic sampling
Extented stats
misestimates
good estimation
SPD_TEXT
• Additional information dba_sql_plan_directives
Description Notation
equality_predicates_only E (SCHEMA.TABLE) [COL, COL]
simple_column_predicates_only C (SCHEMA.TABLE) [COL, COL]
index_access_by_join_predicates J (SCHEMA.TABLE) [COL, COL]
filter_on_joining_object F (SCHEMA.TABLE) [COL, COL]
@Desktop/SPD_demo.sql
Summarize changes in terminology
• Adaptive Optimization – any dynamic change to plan
• Adaptive Plans – changed from default on 1st execution
• Automatic Re-optimization – 2nd execution
• Statistics Feedback = Cardinality Feedback
• Dynamic Statistics = Dynamic Sampling
• SQL Plan Directives = Persisted Dynamic Sampling (for now)
Scary slide for those who want to upgrade
wright now
All of this features have some overhead
• parameter recommendations for oracle database 12c part 1
• parameter recommendations for oracle database 12c part2
• https://iusoltsev.wordpress.com/2016/02/18/12c-automatic-
dynamic-sampling/
• https://iusoltsev.wordpress.com/2016/02/18/12c-automatic-
dynamic-sampling/
Plus Knows bugs:
• NOTE:20978266.8 — Bug 20978266 — SQL not using plan in plan baselines and plans showing as
not reproducible — superseded
• NOTE:21075138.8 — Bug 21075138 — SPM does not reproduce plan with SORT UNIQUE
• NOTE:21463894.8 — Bug 21463894 — Failure to reproduce plan with fix for bug 20978266
• NOTE:19141838.8 — Bug 19141838 — ORA-600 [qksanGetTextStr:1] from SQL Plan Management
after Upgrade to 12.1
• NOTE:18961555.8 — Bug 18961555 — Static PL/SQL baseline reproduction broken by fix for bug
18020394
• NOTE:18747342.8 — Bug 18747342 — Plan reproduction fails for SQL statement with a [NOT]
EXISTS select list subquery
Adaptive optimisation controls
• optimizer_adaptive_features = false
• big switch - controls all adaptive stuff
• optimizer_features_enable <= 12.1.0.1
• even bigger switch – please don’t use this one!
• optimizer_adaptive_reporting_only = true
• _optimizer_adaptive_plans=false
• individual control for adaptive plans
• optimizer_dynamic_sampling=0
• individual control for dynamic sampling
• _optimizer_use_feedback=false
• individual control for cardinality feedback
Used materials:
• White Papers and Blog Entries for Oracle Optimizer (Doc ID
1337116.1)
• 12c Adaptive Optimization - Kerry Osborne
• Articles of Franck Pachot
• Articles of Igor Usoltsev
Questions ?
Mail_to:bushmelev.aa@gmail.com

Oracle 12c SPM

  • 1.
    SQL Plan Managementwith Oracle Database
  • 2.
    Who Am I? Oracle OCP 12c OCE 11g PT OCE 11g RAC Senior Specialist at RT Labs The guy on the right ^_^
  • 3.
    SPM Stability SQL Profiles Stored Outlines SQL PatchesSQL Baselines Instability Statistics Cardinality Feedback Bind Variable Peeking Adaptive Cursor Sharing 12 New Features Adaptive plans Adaptive statistics Presentation plan
  • 4.
    E-ROWS !=A-ROWS • Whenestimated rows != actual rows ---------------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| A-Rows | A-Time | Buffers | Reads | ---------------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | | 1049 (100)| 0 |00:00:00.36 | 11000 | 6588 | | 1 | NESTED LOOPS | | 1 | 100 | 1049 (3)| 0 |00:00:00.36 | 11000 | 6588 | | 2 | NESTED LOOPS | | 1 | 100 | 1049 (3)| 2000 |00:00:00.35 | 9000 | 6552 | |* 3 | TABLE ACCESS FULL | T1 | 1 | 100 | 849 (4)| 2000 |00:00:00.30 | 6554 | 6551 | |* 4 | INDEX UNIQUE SCAN | T2_PK | 2000 | 1 | 1 (0)| 2000 |00:00:00.02 | 2446 | 1 | |* 5 | TABLE ACCESS BY INDEX ROWID| T2 | 2000 | 1 | 2 (0)| 0 |00:00:00.01 | 2000 | 36 | ----------------------------------------------------------------------------------------------------------------------
  • 5.
    Presentation plan SPM Stability SQL Profiles Stored Outlines SQLPatches SQL Baselines Instability Statistics Cardinality Feedback Bind Variable Peeking Adaptive Cursor Sharing 12 New Features Adaptive plans Adaptive statistics
  • 6.
    SQL Profiles • createdby SQL Tunning Advisor • enabled by default • can be applied to multiple statements ( force_matching ) • using OPT_ESTIMATE hints • invalid hints silently ignored • has procedure to import hints ( import_sql_profile ) • uses categories (default by default )
  • 7.
    Profiles, what isinside ? OUTLINE_HINTS ------------------------------------------------------------------------------------------------------------ OPT_ESTIMATE(@"SEL$4C54F62B", NLJ_INDEX_FILTER, "THIS_"@"SEL$2", ("THIS_1_"@"SEL$2"), "FDC_LOT_PK", SCALE_ROWS=0.4164795196) OPT_ESTIMATE(@"SEL$4C54F62B", NLJ_INDEX_SCAN, "THIS_"@"SEL$2", ("THIS_1_"@"SEL$2"), "FDC_LOT_PK", SCALE_ROWS=0.4164795196) OPT_ESTIMATE(@"SEL$4C54F62B", NLJ_INDEX_FILTER, "THIS_1_"@"SEL$2", ("NOTIFICATI1_"@"SEL$3", "THIS_"@"SEL$2", "P"@"SEL$7"), "FDC_LOT_SHARED_BASE_I", SCALE_ROWS=5.662569566e-06) OPT_ESTIMATE(@"SEL$4C54F62B", JOIN, ("NOTIFICATI1_"@"SEL$3", "P"@"SEL$7"), SCALE_ROWS=0.4236734421) OPTIMIZER_FEATURES_ENABLE(default) Wolfgang Breitling: Tunning by cardinality feedback
  • 8.
    Presentation plan SPM Stability SQL Profiles Stored Outlines SQLPatches SQL Baselines Instability Statistics Cardinality Feedback Bind Variable Peeking Adaptive Cursor Sharing 12 New Features Adaptive plans Adaptive statistics
  • 9.
    Stored Outlines • notenabled in every session by default • need to use use_stored_outlines=true • Overrides (disables ) Profiles,Patches and Bselines • need logon trigger to enable on startup • invalid hints silently ignored • work in 11c,12c but deprecated • uses categories
  • 10.
    Presentation plan SPM Stability SQL Profiles Stored Outlines SQLPatches SQL Baselines Instability Statistics Cardinality Feedback Bind Variable Peeking Adaptive Cursor Sharing 12 New Features Adaptive plans Adaptive statistics
  • 11.
    SQL Patches • Createdby SQL Repair Advisor ( dbms_sqldiag ) • MOS Note 215187.1 SQLT has a script to generate manual SQL Profiles • enabled by default • No force matching • Invalid hints silently ignored • Can import hints • dbms_sqldiag_internal.i_create_patch • Capable of applying any valid hints • Hints can be merged with Profiles and Baselines
  • 12.
    Hints can bemerged with Profiles and Baselines SQL_ID c7q8y75rh36sc, child number 1 ------------------------------------- select /* test */ avg(pk_col) from skew where col1 = 23489 Plan hash value: 3723858078 ------------------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | | | 36 (100) | | | 1 | SORTAGGREGATE | | 1 | 11 | | | | 2 | TABLE ACCESS BY INDEX ROWID | SKEW | 35 | 385 | 36 (0) |00:00:01 | |* 3 | INDEX RANGE SCAN | SKEW_COL1 | 37 | | 3 (0) |00:00:01 | ------------------------------------------------------------------------------------------ Predicate Information (identified by operation id): --------------------------------------------------- 3 - access("COL1"=23489) Note ----- - SQL profile PROF_c7q8y75rh36sc_3723858078 used for this statement - SQL patch "KSO_c7q8y75rh36sc_MANUAL" used for this statement - SQL plan baseline SQLID_C7Q8Y75RH36SC_3723858078 used for this statement
  • 13.
    Presentation plan SPM Stability SQL Profiles Stored Outlines SQLPatches SQL Baselines Instability Statistics Cardinality Feedback Bind Variable Peeking Adaptive Cursor Sharing 12 New Features Adaptive plans Adaptive statistics
  • 14.
    SQL Baselines • Overridenby Outlines • Provides procedure to import plans ( dbms_spm.load_plans_from_cursor_cache ) • Invalid hints NOT silently ignored • Has associated plan_hash_value • Capable to apply any valid hints • Enabled by default • Closer to outlines than to SQL Profiles • Goal was to prevent performance regression • Can have multiple Baselines per statement • Can work with Profiles and Patches ( merges hints ) • Can be bulk loaded from • Outlines • SQL Tunning Set • via optimizer_capture_sql_plan_baselines=true • the cursor cache
  • 15.
    What’s inside? • Aplan hash value • hints to reproduce the plan • Signature ( no sql_id ) SQL_PLAN_61c4s16v476sm308a34f6 NO HINTS HINTS
  • 16.
    Presentation plan SPM Stability SQL Profiles Stored Outlines SQLPatches SQL Baselines Instability Statistics Cardinality Feedback Bind Variable Peeking Adaptive Cursor Sharing 12 New Features Adaptive plans Adaptive statistics
  • 17.
    Cardinality Feedback • Wasintroduced in Oracle Database 11gR2 • Cardinality feedback monitoring may be enabled in the following cases: • tables with no statistics • multiple conjunctive or disjunctive filter predicates on a table • predicates containing complex operators that the optimizer cannot accurately compute selectivity estimates for • dynamic sampling or multi-column statistics allow the optimizer to more accurately estimate selectivity of conjunctive predicates. In cases where these techniques apply, cardinality feedback is not enabled.
  • 18.
  • 19.
    Presentation plan SPM Stability SQL Profiles Stored Outlines SQLPatches SQL Baselines Instability Statistics Cardinality Feedback Bind Variable Peeking Adaptive Cursor Sharing 12 New Features Adaptive plans Adaptive statistics
  • 20.
    Bind Variable Peeking Upgradeto 11g and let Adaptive Cursor Sharing take care of all your problems
  • 21.
    Adaptive Cursor Sharing:Overview (Doc ID 740052.1) SELECT child_number, bucket_id, count FROM v$sql_cs_histogram WHERE sql_id = '04pq01r0y8208' ORDER BY child_number, bucket_id; CHILD_NUMBER | BUCKET_ID | COUNT ------------ | ---------- | ---------- 0 | 0 | 742 0 | 1 | 19 0 | 2 | 0 1 | 0 | 1031 1 | 1 | 51 1 | 2 | 0 2 | 0 | 1774 2 | 1 | 34 2 | 2 | 0 The first one (bucket_id equal 0) is associated with the executions that are considered efficient the second one (bucket_id equal 1) with the executions that are considered inefficient and the third one (bucket_id equal 2) with the very inefficient executions
  • 22.
    Adaptive Query Optimization Adaptive Plans JoinMethods Parallel Distribution Methods Adaptive Statistics Dynamic Statistics SQL Plan Directives 12c New Features
  • 23.
    Adaptive Query Optimization Adaptive Plans JoinMethods Parallel Distribution Methods Adaptive Statistics Dynamic Statistics SQL Plan Directives 12c New Features
  • 24.
    Join methods • NestedLoops Joins • Hash Joins • Sort Merge Joins • Cartesian Joins • Purpose of Adaptive Plans
  • 25.
    How to findadaptive plans ? • It’s easy • select sql_id,child_number,substr ( replace(replace (sql_text,chr(10),' '),chr(13),' '),1,100) text,IS_RESOLVED_ADAPTIVE_PLAN,IS_REOPTIMIZABLE from v$sql where IS_RESOLVED_ADAPTIVE_PLAN='Y';
  • 26.
    Adaptive Query Optimization Adaptive Plans JoinMethods Parallel Distribution Methods Adaptive Statistics Dynamic Statistics SQL Plan Directives 12c New Features
  • 27.
    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 < 2xDOP • Enabled by default • If you want more read the articles of Randolf Geist ( link )
  • 28.
    Adaptive Query Optimization Adaptive Plans JoinMethods Parallel Distribution Methods Adaptive Statistics Dynamic Statistics SQL Plan Directives 12c New Features
  • 29.
    Optimizer Dynamic Statistics(OPTIMIZER_DYNAMIC_SAMPLING) (Doc ID 336267.1) Level When Optimizer Uses Dynamic Statistis Sample Size ( blocks ) 0 Do not use dynamic statistics 0 1 Use dynamic statistics for all tables that do not have statistics, but only if the following criteria are met: There is at least 1 non partitioned table in the query that does not have statistics. This table has no indexes. This table has more blocks than the number of blocks that would be used for dynamic statistics of this table. 32 2 Use dynamic statistics if at least one table in the statement has no statistics. This is the default setting. 64 3 As per Level 2, plus all tables for which standard selectivity estimates used a guess for some predicate that is a potential dynamic sampling predicate. 64 4 As per Level 3, plus all tables that have complex predicate expressions (for example single-table predicates that reference 2 or more columns or non-equality where clause predicates on two correlated columns). 64 5 As per Level 4 with a larger sample size each time. 128 6 As per Level 4 with a larger sample size each time. 256 7 As per Level 4 with a larger sample size each time. 512 8 As per Level 4 with a larger sample size each time. 1024 9 As per Level 4 with a larger sample size each time. 4096 10 Use dynamic sampling for all statements sampling All blocks All 11 (11gR2 11.2.0.4 and above) The Optimizer will automatically decide if dynamic statistics will be useful, and what dynamic sampling level will be used for SQL statements. Automagical stuff
  • 30.
    Dynamic statistics 12cversion. What’s New • Join statistics are monitored • Works with adaptive cursor sharing for statement with binds • New Column in V$SQL IS_REOPTIMIZABLE • Information found at execution time is persisted as SQL Plan Directives • Dynamic statistics (Doc ID 2002108.1)
  • 31.
    Adaptive Query Optimization Adaptive Plans JoinMethods Parallel Distribution Methods Adaptive Statistics Dynamic Statistics SQL Plan Directives 12c New Features
  • 32.
    SQL Plan Directives Whatwas already there in 11g : • Cardinality feedback • Estimated cardinalities are checked at execution time • Actual cardinalities are stored with cursor for future re-optimization • Not persistent • Extended statistics • Gathers statistics on group of columns, or functions • Defined manually or from through ā€˜seed column usage’ • Dynamic sampling
  • 33.
    SQL Plan Directives A12c new features sql plan directive might instruct the optimizer to : • Collect missing statistics • Create column group statistics • Perform dynamic statistics (Dynamic Sampling). • Only when we know that more statistics can help • SPD is created when statement is marked as reoptimizable
  • 34.
    SPD Persistent • Inmemory • Are not used by optimizer when only in memory (shared pool) • Are not exported when only in memory: must flush before • Flushed every 15 minutes • Stored in SYSAUX • Flushed manually • exec dbms_spd.flush_sql_plan_directive;
  • 35.
    SQL Plan DirectivesStates Internal States NEW MiSSING STATS HAS STATS PERMANENT Statement reoptimizable Dynamic sampling Extented stats misestimates good estimation
  • 36.
    SPD_TEXT • Additional informationdba_sql_plan_directives Description Notation equality_predicates_only E (SCHEMA.TABLE) [COL, COL] simple_column_predicates_only C (SCHEMA.TABLE) [COL, COL] index_access_by_join_predicates J (SCHEMA.TABLE) [COL, COL] filter_on_joining_object F (SCHEMA.TABLE) [COL, COL]
  • 37.
  • 38.
    Summarize changes interminology • Adaptive Optimization – any dynamic change to plan • Adaptive Plans – changed from default on 1st execution • Automatic Re-optimization – 2nd execution • Statistics Feedback = Cardinality Feedback • Dynamic Statistics = Dynamic Sampling • SQL Plan Directives = Persisted Dynamic Sampling (for now)
  • 39.
    Scary slide forthose who want to upgrade wright now
  • 40.
    All of thisfeatures have some overhead • parameter recommendations for oracle database 12c part 1 • parameter recommendations for oracle database 12c part2 • https://iusoltsev.wordpress.com/2016/02/18/12c-automatic- dynamic-sampling/ • https://iusoltsev.wordpress.com/2016/02/18/12c-automatic- dynamic-sampling/
  • 41.
    Plus Knows bugs: •NOTE:20978266.8 — Bug 20978266 — SQL not using plan in plan baselines and plans showing as not reproducible — superseded • NOTE:21075138.8 — Bug 21075138 — SPM does not reproduce plan with SORT UNIQUE • NOTE:21463894.8 — Bug 21463894 — Failure to reproduce plan with fix for bug 20978266 • NOTE:19141838.8 — Bug 19141838 — ORA-600 [qksanGetTextStr:1] from SQL Plan Management after Upgrade to 12.1 • NOTE:18961555.8 — Bug 18961555 — Static PL/SQL baseline reproduction broken by fix for bug 18020394 • NOTE:18747342.8 — Bug 18747342 — Plan reproduction fails for SQL statement with a [NOT] EXISTS select list subquery
  • 42.
    Adaptive optimisation controls •optimizer_adaptive_features = false • big switch - controls all adaptive stuff • optimizer_features_enable <= 12.1.0.1 • even bigger switch – please don’t use this one! • optimizer_adaptive_reporting_only = true • _optimizer_adaptive_plans=false • individual control for adaptive plans • optimizer_dynamic_sampling=0 • individual control for dynamic sampling • _optimizer_use_feedback=false • individual control for cardinality feedback
  • 43.
    Used materials: • WhitePapers and Blog Entries for Oracle Optimizer (Doc ID 1337116.1) • 12c Adaptive Optimization - Kerry Osborne • Articles of Franck Pachot • Articles of Igor Usoltsev
  • 44.

Editor's Notes

  • #3 Коллеги, Гоброго Š“Š½Ń, Ń‡Š°ŃŃ‚ŃŒ ŠøŠ· ŠæŃ€ŠøŃŃƒŃ‚ŃŃ‚Š²ŃƒŃŽŃ‰ŠøŃ… Š·Š½Š°ŃŽŃ‚ Š¼ŠµŠ½Ń. Š§Š°ŃŃ‚ŃŒ нет. Š”Š»Ń второй Š³Ń€ŃƒŠæŠæŃ‹ Ń€Š°ŃŃŠŗŠ°Š¶Ńƒ немного о себе, почти Гва гоГа Ń€Š°Š±Š¾Ń‚Š°ŃŽ в РТ Лабс ŃŃ‚Š°Ń€ŃˆŠøŠ¼ специалистом в отГеле ŃŠŗŃŠæŠ»ŃƒŠ°Ń‚Š°Ń†ŠøŠø субГ . Š£Š¼ŃƒŠ“Ń€ŠøŠ»ŃŃ ŃŠ“Š°Ń‚ŃŒ на сертификаты: ( клац клац Š¼Ń‹ŃˆŠŗŠ¾Š¹ ) А так же ŠæŠ¾Š²ŠøŠ“Š°Ń‚ŃŒ в Š¶ŠøŠ²ŃƒŃŽ Том кайта 
  • #4Ā ŠŠ°Ń‡Š°Š»Š¾ŃŃŒ все с того, что нам стало ŃŠŗŃƒŃ‡Š½Š¾ Šø чтобы ŠæŠ¾Ń€Š°Š“Š¾Š²Š°Ń‚ŃŒŃŃ новым Š²Š¾Š·Š¼Š¾Š¶Š½Š¾ŃŃ‚ŃŠ¼ ( багам ) мы Ń€ŠµŃˆŠøŠ»Šø Š¾Š±Š½Š¾Š²ŠøŃ‚ŃŒ что-то ŠøŠ· ŠæŃ€Š¾Š“ŃƒŠŗŃ‚ŠøŠ²Š° на 12с Š’ хоГе ŠøŠ·ŃƒŃ‡ŠµŠ½ŠøŃ новых возможностей стало ŠæŠ¾Š½ŃŃ‚Š½Š¾, что необхоГимо ŃƒŠæŠ¾Ń€ŃŠ“Š¾Ń‡ŠøŃ‚ŃŒ Ń‚ŠµŠŗŃƒŃ‰ŠøŠµ Š·Š½Š°Š½ŠøŃ Šø уже Šŗ ним Š“Š¾Š±Š°Š²ŠøŃ‚ŃŒ новые ŠšŠ»Š°Ń† Š’ планах быстро ŠæŃ€Š¾Š±ŠµŠ¶Š°Ń‚ŃŒŃŃ по Ń‚Š¾Š¼Ńƒ что было в 11г клац Šø более Š“ŠµŃ‚Š°Š»ŃŒŠ½Š¾ Š¾Š·Š½Š°ŠŗŠ¾Š¼ŠøŃ‚ŃŒŃŃ с новыми Š²Š¾Š·Š¼Š¾Š¶Š½Š¾ŃŃ‚ŃŠ¼Šø ГвенаГцатой версии
  • #5Ā ŠŸŠ¾Ń‡ŠµŠ¼Ńƒ оптимизатор выбирает не Š¾ŠæŃ‚ŠøŠ¼Š°Š»ŃŒŠ½Ń‹Šµ планы ? ŠŸŠ¾Ń‚Š¾Š¼Ńƒ что не ŠæŃ€Š°Š²ŠøŠ»ŃŒŠ½Š¾ считает ŠŗŠ°Ń€Š“ŠøŠ½Š°Š»ŃŒŠ½Š¾ŃŃ‚ŃŒ. Это легко Š¾ŠæŃ€ŠµŠ“ŠµŠ»ŠøŃ‚ŃŒ, когГа estimated rows != actual rows
  • #7Ā  ŠŠ°Ń‡Š½ŠµŠ¼ с того что в базе ŠµŃŃ‚ŃŒ Гва поГхоГа Šŗ ŃƒŠæŃ€Š°Š²Š»ŠµŠ½ŠøŃŽ планами запроса: ŃŃ‚Š¾ ŃŃ‚Š°Š±ŠøŠ»ŠøŠ·Š°Ń†ŠøŃ плана Šø поГсказки Š“Š»Ń того чтобы более точно Ń€Š°ŃŃ‡ŠøŃ‚Š°Ń‚ŃŒ план запроса ŠŠ°Ń‡Š½ŠµŠ¼ с профилей запроса: клац
  • #8Ā ŠŸŃ€Š¾Ń„ŠøŠ»Šø запросов клац ŃŠ¾Š·Š“Š°ŃŽŃ‚ŃŃ Ń‚ŃŒŃŽŠ½ŠøŠ½Š³ аГвизором клац по ŃƒŠ¼Š¾Š»Ń‡Š°Š½ŠøŃŽ Š²ŠŗŠ»ŃŽŃ‡ŠµŠ½Ń‹ клац Š¼Š¾Š³ŃƒŃ‚ ŠæŃ€ŠøŠ¼ŠµŠ½ŃŃ‚ŃŒŃŃ на несколько выражений ( в v$SQL ŠµŃŃ‚ŃŒ ŠæŠ¾Š»Ń ) 73 EXACT_MATCHING_SIGNATURE NUMBER 74 FORCE_MATCHING_SIGNATURE NUMBER клац
  • #11Ā ŠžŃŠ½Š¾Š²Š½Š°Ń ŠøŠ“ŠµŃ в том чтобы Š·Š°Ń„ŠøŠŗŃŠøŃ€Š¾Š²Š°Ń‚ŃŒ план, совсем.. ВиГел оГин раз, Šø слава богу 
  • #17 Что Š²Š½ŃƒŃ‚ри ? Š•ŃŃ‚ŃŒ значение Ń…ŠµŃˆŠ° плана хинты чтобы ŃŃ‚Š¾Ń‚ план воспроизвести ŃŠøŠ³Š½Š°Ń‚ŃƒŃ€Š° запроса ( не sql_id ) клац ŠŸŠ¾ŃŠ¼Š¾Ń‚Ń€ŠøŠ¼ на примере: Š²Š¾ŃŠæŠ¾Š»ŃŒŠ·ŃƒŠµŠ¼ŃŃ пакетом dbms_xplan Šø снимем Ń‚Ń€Š°ŃŃŠøŃ€Š¾Š²ŠŗŃƒ клац запомним поле sql_plan* в трассировке нашли запрос, выполнили его Šø посмотрели что же Гостает ŠæŃ€Š¾Ń†ŠµŠ“ŃƒŃ€Š° display_sql_plan_baseline клац на выхоГе ŠæŠ¾Š»ŃƒŃ‡ŠøŠ»Šø хинты в виГе xml клац Если Š²Ń‹ŠæŠ¾Š»Š½ŠøŃ‚ŃŒ запрос без ŃŃ‚ŠøŃ… хинтов, то отпимизатор построит план ŠøŃŃ…Š¾Š“Ń ŠøŠ· Ń‚ŠµŠŗŃƒŃ‰ŠµŠ¹ статистики клац Если ŠæŠ¾Š“ŃŃ‚Š°Š²ŠøŃ‚ŃŒ ŠøŃ… Šŗ Š·Š°ŠæŃ€Š¾ŃŃƒ то ŠæŠ¾Š»ŃƒŃ‡ŠøŠ¼ план который в нашем ŃŠ»ŃƒŃ‡Š°Šµ не был ŠæŃ€ŠøŠ½ŃŃ‚ ( ACCEPTED NO )
  • #19Ā  До статистикой Š½Š°Š“ŠµŃŽŃŃŒ что все ŠæŠ¾Š½ŃŃ‚Š½Š¾, перейГем Šŗ карГиналити Ń„ŠøŠ“Š±ŃŠŗ
  • #20 Был преГставлен в 11 версии клац ŠšŠ°Ń€Š“ŠøŠ½Š°Š»ŠøŃ‚Šø фиГбек может ŃŃ€Š°Š±Š¾Ń‚Š°Ń‚ŃŒ в ŃŠ»ŠµŠ“ŃƒŃŽŃ‰ŠøŃ… ŃŠ»ŃƒŃ‡Š°ŃŃ…: таблицы без статистики множественные Ń„ŠøŠ»ŃŒŃ‚Ń€Ń‹ ŃŠ²ŃŠ·ŠŗŠø или Ń€Š°Š·Š¾Š±Ń‰ŠµŠ½ŠøŃ ŠŸŃ€ŠµŠ“ŠøŠŗŠ°Ń‚Ń‹ соГержащие сложные операции Š“Š»Ń которых оптимизатор не может точно Š²Ń‹Ń‡ŠøŃŠ»ŠøŃ‚ŃŒ Š¾Ń†ŠµŠ½ŠŗŃƒ селективности Dynamic sampling или Ń€Š°ŃŃˆŠøŃ€ŠµŠ½Š½Š°Ń статистика ŠæŠ¾Š·Š²Š¾Š»ŃŠµŃ‚ Š¾ŠæŃ‚ŠøŠ¼ŠøŠ·Š°Ń‚Š¾Ń€Ńƒ более точно Š²Ń‹Ń‡ŠøŃŠ»ŃŃ‚ŃŒ ŃŠµŠ»ŠµŠŗŃ‚ŠøŠ²Š½Š¾ŃŃ‚ŃŒ преГикатов Š¾Š±ŃŠŠµŠ“ŠøŠ½ŠµŠ½ŠøŃ, в ŃŠ»ŃƒŃ‡Š°ŃŃ… когГа они ŠæŃ€ŠøŠ¼ŠµŠ½ŃŃŽŃ‚ся карГиналити фиГбек не ŠøŃŠæŠ¾Š»ŃŒŠ·ŃƒŠµŃ‚ся.
  • #22Ā  Гальше Ń€ŠµŃ‡ŃŒ пойГет про наш Š»ŃŽŠ±ŠøŠ¼Ń‹Š¹ бинГ пикинг..
  • #23Ā Ā ŠžŃ€Š°ŠŗŠ» в 9 версии выкатил Ń„ŠøŃ‡Ńƒ Гав ей название Bind Variable Peeking. ŠžŠ½Š° ŠæŠ¾Š·Š²Š¾Š»ŃŠ»Š° Š¾ŠæŃ‚ŠøŠ¼ŠøŠ·Š°Ń‚Š¾Ń€Ńƒ ŃŃ‡ŠøŃ‚Š°Ń‚ŃŒ байнГ ŠæŠµŃ€ŠµŠ¼ŠµŠ½Š½ŃƒŃŽ Šø затем ŠøŃŠæŠ¾Š»ŃŒŠ·Š¾Š²Š°Ń‚ŃŒ гистограммы чтобы Š²Ń‹Š±Ń€Š°Ń‚ŃŒ ŠæŠ¾Š“Ń…Š¾Š“ŃŃ‰ŠøŠ¹ план, точно так же как Š±ŃƒŠ“то использовались литералы. ŠŸŃ€Š¾Š±Š»ŠµŠ¼Š° в том, что он считавал ŠæŠµŃ€ŠµŠ¼ŠµŠ½Š½ŃƒŃŽ Ń‚Š¾Š»ŃŒŠŗŠ¾ раз, во Š²Ń€ŠµŠ¼Ń hard parce.
  • #24Ā Š˜Š“ŠµŃ в том что после Š²Ń‹ŠæŠ¾Š»Š½ŠµŠ½ŠøŃ механизм ДУБД ( SQL engine ) сравнивает Š¾Ń†ŠµŠ½Š¾Ń‡Š½ŃƒŃŽ ŠŗŠ°Ń€Š“ŠøŠ½Š°Š»ŃŒŠ½Š¾ŃŃ‚ŃŒ с фактической. После, в зависимости от как сильно они Š¾Ń‚Š»ŠøŃ‡Š°ŃŽŃ‚ŃŃ, происхоГит инкремент оГиного ŠøŠ· бакетов ( count ŃƒŠ²ŠµŠ»ŠøŃ‡ŠøŠ²Š°ŠµŃ‚ŃŃ ). клац первый ( бакет айГи равен Š½ŃƒŠ»ŃŽ ) ŃƒŠ²ŠµŠ»ŠøŃ‡ŠøŠ²Š°ŠµŃ‚ŃŃ если выполение было ŃŃ„Ń„ŠµŠŗŃ‚ŠøŠ²Š½Ń‹Š¼ клац второй ( бакет айГи равен еГинице ) ŃƒŠ²ŠµŠ»ŠøŃ‡ŠøŠ²Š°ŠµŃ‚ŃŃ если выполнение было не ŃŃ„Ń„ŠµŠŗŃ‚ŠøŠ²Š½Ń‹Š¼ клац третий ( бакет айГи равен Гвум ) ŃƒŠ²ŠµŠ»ŠøŃ‡ŠøŠ²Š°ŠµŃ‚ŃŃ в ŃŠ»ŃƒŃ‡Š°Šµ крайне не ŃŃ„Ń„ŠµŠŗŃ‚ŠøŠ²Š½Š¾Š³Š¾ Š²Ń‹ŠæŠ¾Š»Š½ŠµŠ½ŠøŃ клац Во Š²Ń€ŠµŠ¼Ń ŃŠ»ŠµŠ“ŃƒŃŽŃ‰ŠµŠ³Š¾ разбора ŃŃ‚Š¾Š³Š¾-же ŠŗŃƒŃ€ŃŠ¾Ń€Š°, Šø в зависимости от Ń€Š°ŃŠæŃ€ŠµŠ“ŠµŠ»ŠµŠ½ŠøŃ значений межГу ŃŃ‚ŠøŠ¼Šø Ń‚Ń€ŠµŠ¼Ń бакетами, ŠŗŃƒŃ€ŃŠ¾Ń€ ŃŃ‚Š°Š½Š¾Š²ŠøŃ‚ŃŒŃŃ bind aware. К ŠæŃ€ŠøŠ¼ŠµŃ€Ńƒ, когГа количество Š½ŠµŃŃ„фективных ŠŗŃƒŃ€ŃŠ¾Š² так же велико как Šø кол-во ŃŃ„Ń„ŠµŠŗŃ‚ŠøŠ²Š½Ń‹Ń…, ŠŗŃƒŃ€ŃŠ¾Ń€ ŃŃ‚Š°Š½Š¾Š²ŠøŃ‚ŃŒŃŃ bind aware ( в Ганном ŃŠ»ŃƒŃ‡Š°Šµ он IS_BIND_SENSITIVE ) Let's see what the columns mean. Oracle observes the cursors for a while and sees how the values differ. If the different values can potentially alter the plan, the cursor is labeled "Bind-Sensitive" and the column IS_BIND_SENSITIVE shows "Y". After a few executions, the database knows more about the cursors and the values and decides if the cursor should be made to change plans based on the values. If that is the case, the cursor is called "Bind-Aware" and the column IS_BIND_AWARE shows "Y". In summary: Bind-Sensitive cursors are potential candidates for changed plans and Bind-Aware ones are where the plans actually change. The idea is that after an execution, the SQL engine compares the estimated cardinalities with the actual cardinalities. Then, depending on how close the two cardinalities are, the execution is associated (that is, the count column is incremented) to one of the three buckets. Later on, while executing the next parse operation involving the same cursor, and depending on how the executions are distributed among the three buckets, a cursor might become bind aware or not. For example, when the number of inefficient executions is as high as the number of efficient ones, the cursor is made bind aware
  • #27Ā Š’Š¾Š·Š¼Š¾Š¶Š½Š¾ŃŃ‚ŃŒ оптимизатора Š°Š“Š°ŠæŃ‚ŠøŃ€Š¾Š²Š°Ń‚ŃŒ план, в зависимости от информации ŠæŠ¾Š»ŃƒŃ‡ŠµŠ½Š½Š¾Š¹ во Š²Ń€ŠµŠ¼Ń Š²Ń‹ŠæŠ¾Š»Š½ŠµŠ½ŠøŃ, может сильно ŃƒŠ»ŃƒŃ‡ŃˆŠøŃ‚ŃŒ Š²Ń€ŠµŠ¼Ń Š²Ń‹ŠæŠ¾Š»Š½ŠµŠ½ŠøŃ запроса. АГаптивные планы полезны, т.Šŗ оптимизатор изреГка выбирает не Š¾ŠæŃ‚ŠøŠ¼Š°Š»ŃŒŠ½Ń‹Š¹ Гефолтный план ŠøŠ·-за ошибок в расчетах ŠŗŠ°Ń€Š“ŠøŠ½Š°Š»ŃŒŠ½Š¾ŃŃ‚Šø. Š’Š¾Š·Š¼Š¾Š¶Š½Š¾ŃŃ‚ŃŒ Š°Š“Š°ŠæŃ‚ŠøŃ€Š¾Š²Š°Ń‚ŃŒ план Š¾ŃŠ½Š¾Š²Ń‹Š²Š°ŃŃŃŒ на статистике Š²Ń‹ŠæŠ¾Š»Š½ŠµŠ½ŠøŃ ŠæŠ¾Š·Š²Š¾Š»ŃŠµŃ‚ Š²Ń‹Š±Ń€Š°Ń‚ŃŒ более Š¾ŠæŃ‚ŠøŠ¼Š°Š»ŃŒŠ½Ń‹Š¹ Ń„ŠøŠ½Š°Š»ŃŒŠ½Ń‹Š¹ план. После того как оптимизатор выбрал Ń„ŠøŠ½Š°Š»ŃŒŠ½Ń‹Š¹ план он ŠøŃŠæŠ¾Š»ŃŒŠ·ŃƒŠµŃ‚ся Š“Š»Ń ŠæŠ¾ŃŠ»ŠµŠ“ŃƒŃŽŃ‰ŠøŃ… выполнений. ŠšŠ»Š°Ń† ŠžŃ€Š°ŠŗŠ» может ŃŠ¾ŠµŠ“ŠøŠ½ŃŃ‚ŃŒ таблицы Ń‡ŠµŃ‚Ń‹Ń€ŃŒŠ¼Ń способами: клац ŠŠ¾ Ń‚Š¾Š»ŃŒŠŗŠ¾ 2 ŠøŠ· них ŠøŃŠæŠ¾Š»ŃŒŠ·ŃƒŃŽŃ‚ŃŃ в аГаптивном выборе ŃŠ¾ŠµŠ“ŠøŠ½ŠµŠ½ŠøŃ таблиц, ŃŃ‚Š¾ NJ + HJ Дборщик статистики ŠæŠ¾Š“ŃŃ‚Š°Š²Š»ŃŠµŃ‚ŃŃ переГ Гжойном Šø Š¾ŃŠ½Š¾Š²Ń‹Š²Š°ŃŃŃŒ на количестве ŠæŠ¾Š»ŃƒŃ‡ŠµŠ½Š½Ń‹Ń… Ганных выбирает Ń„ŠøŠ½Š°Š»ŃŒŠ½Ń‹Š¹ план.
  • #28 Как найти что ŠøŃŠ¾ŠæŠ»ŃŒŠ·ŃƒŃŽŃ‚ся аГаптивные планы ? легко :) клац Гелаем запрос Šŗ vql ищем гГе резолвеГ аГаптив равно Y
  • #30Ā BROADCAST distribution was used for rows coming from the DEPT table, the rows coming from the EMP table will distributed via ROUND- ROBIN.
  • #33Ā ŠŠ“Š°ŠæŃ‚ŠøŠ²Š½Š°Ń статистика ŃŃ‚Š¾ новое название Š“Š»Ń dynamic sampling
  • #34Ā ŠŠ¾ Гобавилось ŃŠ»ŠµŠ“ŃƒŃŽŃ‰ŠµŠµ: Automatic Dynamic Statistics are enabled by default in Oracle Database 12c OPTIMIZER_DYNAMIC_SAMPLING =2 OPTIMIZER_DYNAMIC_SAMPLING =11
  • #37Ā  sql plan directive Š¼Š¾Š³ŃƒŃ‚ ŠæŠ¾Š“ŃŠŗŠ°Š·Š°Ń‚ŃŒ Š¾ŠæŃ‚ŠøŠ¼ŠøŠ·Š°Ń‚Š¾Ń€Ńƒ Create column group statistics When extended statistics can’t be created, they instruct the query optimizer to use dynamic sampling. Perform dynamic statistics (Dynamic Sampling). Sql plan directives are persisted to disk in the SYSAUX tablespace; a plan directive is created and purged to disk (SYSXAUX) every 15 minutes. In 12.1 only one reason to create a SQL Plan Directives > Optimizer bad decision (misestimate) In 12.1 only one type of SQL Plan Directives > Dynamic sampling
  • #39 во Š²Ń€ŠµŠ¼Ń первого запуска ŠŗŃƒŃ€ŃŠ¾Šŗ ŠæŠ¾Š¼ŠµŃ‡Š°ŠµŃ‚ŃŃ как реоптимайзбл, а SPD ŃŠ¾Š·Š“Š°ŠµŃ‚ŃŃ со ŃŃ‚Š°Ń‚ŃƒŃŠ¾Š¼ NEW во Š²Ń€ŠµŠ¼Ń второго Š²Ń‹ŠæŠ¾Š»Š½ŠµŠ½ŠøŃ statistic feedback ŠøŃŠæŃ€Š°Š²Š»ŃŠµŃ‚ Š¾Ń†ŠµŠ½ŠŗŃƒ стоимости, SPD в ŃŃ‚Š°Ń‚ŃƒŃŠµ missing stats Во Š²Ń€ŠµŠ¼Ń Ń‚Ń€ŠµŃ‚ŃŒŠµŠ³Š¾ Š²Ń‹ŠæŠ¾Š»Š½ŠµŠ½ŠøŃ SPD ŠøŃŠæŠ¾Š»ŃŒŠ·ŃƒŠµŃ‚ŃŃ в качестве dynamic sampling 1)Ā 1st query Cursor marked as REOPTIMIZABLE > SPD in NEW state 2) Ā 2nd query Statistics feedback to correct the estimations > SPD in MISSING STATS state 3)Ā 3rd query SPD is used to correct estimations with dynamic sampling > Ā Gather statistics on table 4) Extended statistics are created to correct the estimations > SPD is still in MISSING STATS state 5) Ā Next queries > SPD has been verified and changed to HAS STATS state
  • #40Ā Š’ Ганном примере имеем ошибку в оценке ŃŃ€Š°Š²Š½ŠµŠ½ŠøŃ простых преГикатов
  • #45Ā Long parse time > Ā Lot of directives are created on dictionary tables > Ā Parse spend long time on them > High dynamic sampling activity > Latch on result cache misses (non shared SQL)