Con8622 Oracle Optimizer What To Expect in 12c Part2 PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 29

1 Copyright © 2013, Oracle and/or its affiliates. All rights reserved.

d. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
Oracle Optimizer: What’s
New in Oracle Database 12c?
Maria Colgan
Master Product Manager
PART 2

3 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
Adaptive Query Optimization

Adaptive Query
Optimization
Adaptive Plans
Join methods
Parallel distribution methods
Adaptive
Adaptive Statistics Adaptive Plans
Statistics
Discovered at compile time
Discovered at run time
Join Parallel At At run
Methods distribution compile time
Methods time

4 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
Dynamic Statistics

 Dynamic statistics were formally known as dynamic sampling


 During compilation optimizer decides if statistics are sufficient to
generate a good plan or not
 Dynamic statistics are used to compensate for missing, stale, or
incomplete statistics
 They can be used for table scans, index access, joins and group bys

5 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
Dynamic Statistics

New dynamic sampling


level 11(AUTO)
Decision to use dynamic
sampling depends on the
complexity of predicate,
existing statistics and
total execution time
Dynamic statistics shared
among queries

6 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
Dynamic Statistics
SGA
SHARED DYNAMIC STATISTICS
Select *
Table cardinality estimate for prod_info
From product_information
Where list_price-min_price=29
5 Optimizer determines
plan using dynamic SHARED_POOL
And category_id not in (11,22)
statistics
And prod_name like ‘Smart%’; Cursor 0: Select * from product_information …

SQL statement
1 is submitted
4 Dynamic sampling
occurs on small number of
blocks from table
Resulting dynamic statistics
are stored in cache
2 Optimizer checks
for existing statistics
in data dictionary

DATA DICTIONARY
3 Statistics found but need to be
augmented due to complex predicates

7 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
Dynamic Statistics
SGA
SHARED DYNAMIC STATISTICS
Select supplier_id, prod_name
Table cardinality estimate for prod_info
From product_information
Where list_price-min_price=29
10 Optimizer determines
plan using dynamic SHARED_POOL
And category_id not in (11,22)
statistics
And prod_name like ‘Smart%’; Cursor 0: Select supplier_id, prod_name …

Different SQL
6 statement is
9 Necessary Dynamic
statistics found in shared
submitted with
cache
same predicates

7 Optimizer checks
for existing statistics
in data dictionary

DATA DICTIONARY
8 Statistics found but need to be
augmented due to complex predicates

8 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
Adaptive Statistics
Re-optimization

 During execution optimizer estimates are compared to execution


statistics
 If statistics vary significantly then a new plan will be chosen for
subsequent executions based on execution statistics
 Re-optimization uses statistics gathered from previous executions

 First introduced as Cardinality Feedback in 11.2

9 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
Adaptive Statistics
Cardinality Feedback in 11g

 Statistics gathered about data types and volume during execution


 If execution statistics vary significantly statement will be hard parsed
on the next execution using the execution statistics instead
 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
 Information is stored in the cursor only and is lost if cursor ages out

10 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
Cardinality Feedback In 11g

Initial execution of a
query is monitored
Example shows initial
plan is hash join between
sales and customers
Cardinality estimates 8X
off

Initial Cardinality estimates are more than 8X off

11 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
Cardinality Feedback In 11g

Execution statistics used Execution Plan after the second execution


to reparse the statement
on the second execution
Estimates
New plan shows correct are now
cardinality estimates and correct

a new join order


Information learnt is
stored in the cursor only
and is lost if cursor ages
out

12 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
Re-optimization
Cardinality Feedback Evolution

 Join statistics are also 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

13 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
Re-optimization – Indicator In V$SQL

New column in V$SQL


IS_REOPTIMIZABLE

Indicates that the


statement will be re-
parsed on the next
execution

14 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
Adaptive Plans & Re-Optimization Working
Together
Adapt join method
example showed the join
change from nested
loops to hash join
But cursor is also marked
IS_REOPTIMIZABLE
Why?

15 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
Adaptive Plans & Re-Optimization Working
Together
Adapt join method
example showed the join
change from nested
loops to hash join
But cursor is also marked
IS_REOPTIMIZABLE
Why?
Re-optimization will occur
on second execution
because cardinality
estimates off Initial Cardinality estimates are off

16 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
Adaptive Plans & Re-Optimization Working
Together

On second execution
statement is re-parsed
using execution statistics
New child cursor created
with new plan
New plan changes the
join order

17 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
Adaptive Statistics
SQL Plan Directives

 Directives are additional information used during optimization to


generate a better plan
– For example, when table T1 is joined to T2 use dynamic statistics to get
accurate cardinality estimate
– Directives are collected on query expressions not at a statement level
 Allows for directives to be used for multiple statements
– Persisted on disk in the SYSAUX tablespace
– Directives will be automatically maintained
– Managed using the new package DBMS_SPD

18 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
SQL Plan Directives
SGA
DIRECTIVE CACHE
Directive: Use DS for customers table
Select * when column city, country are used
FROM customers 2 Optimizer determines
SHARED_POOL
where state =‘CA’ plan
AND country=‘USA’;
Cursor 0: Select * from customers
…….. IS_REOPTIMIZABLE = Y
SQL statement
1 is submitted
3 During execution
cardinality estimate
discovered to be wrong
and directive created

Sysaux Tablespace

19 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
SQL Plan Directives
SGA
DIRECTIVE CACHE
Directive: Use DS for customer table
when column city, country are used
Select *
FROM customers
5 Optimizer determines
new plan using SHARED_POOL
where state=‘CA’ execution statistics
AND country=‘USA’;
Cursor 0: Select * from customers …..
IS_REOPTIMIZABLE = Y
Same SQL Cursor 1: Select * from customers …..
4
statement is
6 This execution and IS_REOPTIMIZABLE = N
subsequent execution
submitted use child cursor 1
again

Sysaux Tablespace
Directives periodically
Extension Binds Stats Sqlid persisted to disk in the
sysaux tablespace
SQL Directives
SQL Directives

20 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
SQL Plan Directives
SGA
DIRECTIVE CACHE

Select email 9 Optimizer determines


FROM customers plan with help of
where state=‘MA’ directive SHARED_POOL
AND country=‘USA’; Cursor 0: Select email from customers

10Optimizer adds
7 New SQL
column group creation
statement is
for state & country
submitted on
columns to next statistics
customers table
gather on customer table
8 Optimizer Sysaux Tablespace
checks for
directives on Extension Binds Stats Sqlid
customers table
and finds one on SQL Directives
the columns state
and country

21 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
SQL Plan Directives

Number of SQL Plan


Directives used for a
statement is displayed in
the notes section of the
execution plan
In this case one SQL
Plan Directive was used

22 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
Monitoring SQL Plan Directives

Auto flushed every 15 minutes

23 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
Monitoring SQL Plan Directives

Auto flushed every 15 minutes

24 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
Extended Statistics Automatically Created From
SQL Plan Directives
SQL Plan Directive state
was “MISSING_STATS”
Indicates Oracle can
automatically gather
statistics to improve the
original mis-estimation
In this case a column
group on STATE and
COUNTRY will address
the problem

25 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
SQL Plan Directives
Monitoring

26 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
SQL Plan Directives No Longer Needed

Correct statistics in place


Optimizer uses statistics
instead of directives
Accurate cardinality
estimate seen in the plan
Statement not marked for
re-optimization

27 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
Adaptive Query Optimization

Adaptive Plans Adaptive Query


Join methods Optimization
Parallel distribution methods

Adaptive Statistics
Discovered at compile time
Adaptive
Discovered at run time Adaptive Plans
Statistics
Controlled by
OPTIMIZER_ADAPTIVE_FEATURES
Join Parallel At At run
Methods distribution compile time
Methods time

28 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template
END OF PART 2

29 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate presentation template

You might also like