Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Taming the beast
The 12c Optimizer
Connor McDonald
1
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
Connor McDonald
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
3
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
4
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. |
Stuff
youtube bit.ly/youtube-connor
blog bit.ly/blog-connor
twitter bit.ly/twitter-connor
400+ posts mainly on database & development
250 technical videos, new uploads every week
rants and raves on tech and the world :-)
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
etc...
facebook bit.ly/facebook-connor
linkedin bit.ly/linkedin-connor
instagram bit.ly/instagram-connor
slideshare bit.ly/slideshare-connor
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
7https://asktom.oracle.com
Copyright © 2018, Oracle and/or its affiliates. All rights reserved.
https://asktom.oracle.com/officehours
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
150 hours free access so far
9
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
this session
10
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
3 things
11
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
12c optimizer …
better performance
12
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
12c optimizer …
worse performance
13
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
worse performance …
14
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
15
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
16
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
goal of the optimizer
17
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
simple
18
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
good execution plan
19
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
so how did we end up here ?
20
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Hi, I'm the
optimizer. How
I can help ?
21
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Hi, I'm the
optimizer. How
I can help ?
What I would
really like …
22
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Hi, I'm the
optimizer. How
I can help ?
What I would
really like …
… is for you to
suffer like I do
23
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
PROBLEM #1
24
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
missing or poor statistics
25
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
cardinality mis-estimates
26
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
cardinality is everything
27
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
28
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
better stats
29
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
missing or poor statistics
30
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
1) better histograms
31
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> create table T
2 as select * from dba_objects;
Table created.
SQL> exec dbms_stats.gather_table_stats('','T');
PL/SQL procedure successfully completed.
32
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select COLUMN_NAME,NUM_DISTINCT,
2 ( select count(*)
3 from all_tab_histograms
4 where owner = a.owner
5 and table_name = a.table_name
6 and column_name = a.column_name )
7 from all_tab_cols a
8 where table_name = 'T'
9 order by column_id;
COLUMN_NAME NUM_DISTINCT HIST_CNT
------------------------------ ------------ ----------
OWNER 25 2
OBJECT_NAME 53000 2
SUBOBJECT_NAME 230 2
OBJECT_ID 90808 2 33
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
34
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
35
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select intcol#,equality_preds,
2 range_preds,timestamp
3 from sys.col_usage$
4 where obj# = (select object_id
5 from obj
6 where object_name = 'T' );
INTCOL# EQUALITY_PREDS RANGE_PREDS TIMESTAMP
---------- -------------- ----------- ---------
1 1 0 24-SEP-17
36
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> exec dbms_stats.gather_table_stats('','T');
SQL> select COLUMN_NAME,NUM_DISTINCT,
2 ( select count(*)
3 from all_tab_histograms
4 where owner = a.owner
5 and table_name = a.table_name
6 and column_name = a.column_name )
7 from all_tab_cols a
8 where table_name = 'T'
9 order by column_id;
COLUMN_NAME NUM_DISTINCT HIST_CNT
------------------------------ ------------ ----------
OWNER 25 25
OBJECT_NAME 53000 2
SUBOBJECT_NAME 230 2
OBJECT_ID 90808 2
37
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
we don't know what your "app" is
38
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
still requires care
39
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
12c improvements
40
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select status, count(*)
2 from orders
3 group by status
4 order by 1;
STATUS COUNT(*)
-------------------- ----------
1-New 1000
2-Assigned 10
3-InProgress 4000
4-Processed 3
5-Shipped 800
6-Received 5000
7-Completed 15000
8-Archived 20000
41
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
skewed ...
42
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
... need histogram
43
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
11g
44
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> begin
2 dbms_stats.gather_table_stats('','ORDERS',
3 method_opt=>'for all columns size 15');
4 end;
5 /
PL/SQL procedure successfully completed.
SQL> select histogram from USER_TAB_COL_STATISTICS
2 where table_name = 'ORDERS';
HISTOGRAM
---------------
FREQUENCY
45
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select
2 endpoint_number,
3 substr(
4 utl_raw.cast_to_varchar2(
5 hextoraw(to_char(endpoint_value,rpad('FM',65,'X')))),1,5),
6 endpoint_number -
7 nvl(lag(endpoint_number) over ( order by endpoint_number),0)
8 from user_histograms
9 where table_name = 'ORDERS'
10 order by 1;
ENDPOINT_NUMBER END_VAL FREQ
--------------- -------------------- ----------
1000 1-Nev 1000
1010 2-Ass 10
5010 3-InP 4000
5013 4-Pro 3
5813 5-Shi 800
10813 6-Rec 5000
25813 7-Com 15000
45813 8-Arc 20000
46
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select
2 endpoint_number,
3 substr(
4 utl_raw.cast_to_varchar2(
5 hextoraw(to_char(endpoint_value,rpad('FM',65,'X')))),1,5),
6 endpoint_number -
7 nvl(lag(endpoint_number) over ( order by endpoint_number),0)
8 from user_histograms
9 where table_name = 'ORDERS'
10 order by 1;
ENDPOINT_NUMBER END_VAL FREQ
--------------- -------------------- ----------
1000 1-Nev 1000
1010 2-Ass 10
5010 3-InP 4000
5013 4-Pro 3
5813 5-Shi 800
10813 6-Rec 5000
25813 7-Com 15000
45813 8-Arc 20000
47
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select
2 endpoint_number,
3 substr(
4 utl_raw.cast_to_varchar2(
5 hextoraw(to_char(endpoint_value,rpad('FM',65,'X')))),1,5),
6 endpoint_number -
7 nvl(lag(endpoint_number) over ( order by endpoint_number),0)
8 from user_histograms
9 where table_name = 'ORDERS'
10 order by 1;
ENDPOINT_NUMBER END_VAL FREQ
--------------- -------------------- ----------
1000 1-Nev 1000
1010 2-Ass 10
5010 3-InP 4000
5013 4-Pro 3
5813 5-Shi 800
10813 6-Rec 5000
25813 7-Com 15000
45813 8-Arc 20000
48
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select * from orders
2 where status = '5-Shipped';
----------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
----------------------------------------------------
| 0 | SELECT STATEMENT | | 800 | 8800 |
|* 1 | TABLE ACCESS FULL| ORDERS | 800 | 8800 |
----------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("STATUS"='5-Shipped')
49
true = 800
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
so far … so good
50
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
NDV > 254*
51
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> begin
2 dbms_stats.gather_table_stats('','ORDERS',
3 method_opt=>'for all columns size 6');
4 end;
5 /
PL/SQL procedure successfully completed.
SQL> select histogram from USER_TAB_COL_STATISTICS
2 where table_name = 'ORDERS';
HISTOGRAM
---------------
HEIGHT BALANCED
52
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select
2 endpoint_number,
3 substr(
4 utl_raw.cast_to_varchar2(
5 hextoraw(to_char(endpoint_value,rpad('FM',65,'X')))),1,5),
6 endpoint_number -
7 nvl(lag(endpoint_number) over ( order by endpoint_number),0)
8 from user_histograms
9 where table_name = 'ORDERS'
10 order by 1;
ENDPOINT_NUMBER END_VAL BKTS
--------------- -------------------- ----------
0 1-Nev 0
1 6-Rec 1
3 7-Com 2
6 8-Arc 3
53
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
1-New
6-Received
7-Complete
8-Archived
8-Archived
8-Archived
7-Complete
54
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select * from orders
2 where status = '8-Archived';
----------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
----------------------------------------------------
| 0 | SELECT STATEMENT | | 19089 | 205K|
|* 1 | TABLE ACCESS FULL| ORDERS | 19089 | 205K|
----------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("STATUS"='8-Archived')
true = 20000
55
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select * from orders
2 where status = '7-Completed';
-----------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
-----------------------------------------------------
| 0 | SELECT STATEMENT | | 15271 | 164K|
|* 1 | TABLE ACCESS FULL| ORDERS | 15271 | 164K|
-----------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("STATUS"='7-Completed')
true = 10000
56
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
57
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
1-New
6-Received
7-Complete
8-Archived
8-Archived
8-Archived
7-Completetotal ~ 45,000 ~7000 per bucket 58
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
1-New
6-Received
7-Complete
8-Archived
8-Archived
8-Archived
7-Completetotal = 45,000 ~7000 per bucket 59
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select * from orders
2 where status = '2-Assigned';
----------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
----------------------------------------------------
| 0 | SELECT STATEMENT | | 1273 | 14003 |
|* 1 | TABLE ACCESS FULL| ORDERS | 1273 | 14003 |
----------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("STATUS"='2-Assigned')
true = 3
60
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
height balanced means ...
61
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
bucket spanning = dramas
62
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
bucket swallowing = dramas
63
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
11g
HEIGHT-BALANCED
FREQUENCY
64
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Footnote: 11g
FOR ALL COLUMNS SIZE 25AUTO
65
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
66
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> begin
2 dbms_stats.gather_table_stats('','ORDERS',
3 method_opt=>'for all columns size 15');
4 end;
5 /
PL/SQL procedure successfully completed.
SQL> select histogram from USER_TAB_COL_STATISTICS
2 where table_name = 'ORDERS';
HISTOGRAM
---------------
FREQUENCY
67
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> begin
2 dbms_stats.gather_table_stats('','ORDERS',
3 method_opt=>'for all columns size 6');
4 end;
5 /
PL/SQL procedure successfully completed.
SQL> select histogram from USER_TAB_COL_STATISTICS
2 where table_name = 'ORDERS';
HISTOGRAM
---------------
TOP-FREQUENCY
68
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select
2 endpoint_number,
3 substr(
4 utl_raw.cast_to_varchar2(
5 hextoraw(to_char(endpoint_value,rpad('FM',65,'X')))),1,5)
6 endpoint_number -
7 nvl(lag(endpoint_number) over ( order by endpoint_number),0)
8 from user_histograms
9 where table_name = 'ORDERS'
10 order by 1;
ENDPOINT_NUMBER END_VAL FREQ
--------------- -------------------- ----------
1000 1-Nev 1000
5000 3-InP 4000
5800 5-Shi 800
10800 6-Rec 5000
25800 7-Com 15000
45800 8-Arc 20000 69
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
1-New
6-Received
3-InProgress
5-Shipped
8-Archived
7-Completed
70
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
other values ?
71
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select num_rows
2 from user_tables
3 where table_name = 'ORDERS';
NUM_ROWS
----------
45813
SQL> select num_distinct
2 from user_tab_cols
3 where table_name = 'ORDERS';
NUM_DISTINCT
------------
8
FREQ
----------
800
1000
4000
5000
15000
20000
========
45800
( 45813 - 45800 ) / ( 8 - 6 ) =
72
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select * from orders
2 where status = '4-Processed';
-----------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
-----------------------------------------------------
| 0 | SELECT STATEMENT | | 7 | 77 |
|* 1 | TABLE ACCESS FULL| ORDERS | 7 | 77 |
-----------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("STATUS"='4-Processed')
73
true = 3
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
what defines "TOP"
% top values > ((bkt-1)/bkt)* num
eg 1000 rows/ 12 bucket
12 most frequent > 11/12 * 1000
~920 rows
74
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
what if TOP FREQ not possible ?
75
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> insert into orders select '1-New'
2 from dual connect by level <= 9000;
SQL> insert into orders select '2-Assigned'
2 from dual connect by level <= 9500;
SQL> insert into orders select '3-InProgress'
2 from dual connect by level <= 6000;
SQL> insert into orders select '4-Processed'
2 from dual connect by level <= 9500;
SQL> insert into orders select '5-Shipped'
2 from dual connect by level <= 8800;
SQL> insert into orders select '6-Received'
2 from dual connect by level <= 4500;
76
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select status, count(*)
2 from orders
3 group by status
4 order by 1;
STATUS COUNT(*)
-------------------- ----------
1-New 10000
2-Assigned 9510
3-InProgress 10000
4-Processed 9503
5-Shipped 9600
6-Received 9500
7-Completed 15000
8-Archived 20000
77
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> begin
2 dbms_stats.gather_table_stats('','ORDERS',
3 method_opt=>'for all columns size 6');
4 end;
5 /
PL/SQL procedure successfully completed.
SQL> select histogram from USER_TAB_COL_STATISTICS
2 where table_name = 'ORDERS';
HISTOGRAM
---------------
HYBRID
78
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select
2 endpoint_number,
3 substr(
4 utl_raw.cast_to_varchar2(
5 hextoraw(to_char(endpoint_value,rpad('FM',65,'X')))),1,5),
6 endpoint_number -
7 nvl(lag(endpoint_number) over ( order by endpoint_number),0),
8 endpoint_repeat_count
9 from user_histograms
10 where table_name = 'ORDERS'
11 order by 1;
ENDPOINT_NUMBER END_VAL FREQ ENDPOINT_REPEAT_COUNT
--------------- -------------------- ---------- ---------------------
590 1-Nev 590 590
1743 3-InP 1153 626
2314 4-Pro 571 571
2895 5-Shi 581 581
3449 6-Rec 554 554
5547 8-Arc 2098 1213 79
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
1-New
6-Received
3-InProgress
5-Shipped
8-Archived
4-Processed
ENDPOINT_NUMBER END_VAL FREQ ENDPOINT_REPEAT_COUNT
--------------- -------------------- ---------- ---------------------
590 1-Nev 590 590
1743 3-InP 1153 626
2314 4-Pro 571 571
2895 5-Shi 581 581
3449 6-Rec 554 554
5547 8-Arc 2098 1213
2-Assigned
590 1153 571 581 554 2098
7-Completed
80
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
8-Archived
END_VAL FREQ ENDPOINT_REPEAT_COUNT
---------------- -------- ---------------------
1-Nev 590 590
3-InP 1153 626
4-Pro 571 571
5-Shi 581 581
6-Rec 554 554
8-Arc 2098 1213
2098
7-Completed
"Bucket 8-Arc has 2098 occurrences...
1213 of them are the end value 8-Arc...
therefore 885 are > 6-Rec and < 8-Arc"
81
6-Received
554
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
no bucket spanning
82
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
key point
83
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
must use auto sample size
84
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
still need care
85
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
representative values
86
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
87
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
"today's hot deals"
88
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
gather statistics
SQL> select count(*)
2 from items
3 where type = 'HOT_DEAL'
COUNT(*)
----------
0
89
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
activate "deals of the day"
SQL> update items
2 set type = 'HOT_DEAL'
3 where ...
SQL> select count(*)
2 from items
3 where type = 'HOT_DEAL'
COUNT(*)
----------
14
90
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
biggest day of the year !
SQL> select min(discount)
2 from items
3 where type = 'HOT_DEAL'
4 and ...
where type = 'HOT_DEAL'
SQL> select free_shipping
2 from items
3 where hot_deal = 'Y'
4 and ...
SQL> select ...
2 from ...
SQL> select ...
2 from ...
SQL> select ...
2 from ...
SQL> select ...
2 from ...SQL> select ...
2 from ...
91
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
92
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
where type = 'HOT_DEAL'
93
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
94
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select type, count(*)
2 from items
3 group by type;
TYPE COUNT(*)
------ ----------
ORDERED 21353
ARCHIVED 4213
NORMAL 513234
SOLD 528291
HOT_DEAL 0
95
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
normally...
96
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
"ok... I got 1,000,000 total rows...
and 7 distinct values.
I got a frequency histogram...
There's 4 popular values,
adding up to 910,000
That's 3 values left to cover the rest
3 / ( 1,000,000 - 910,000) = density
... I'm done!"
97
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SINGLE TABLE ACCESS PATH
Single Table Cardinality Estimation for ITEMS[ITEMS]
SPD: Return code in qosdDSDirSetup: NOCTX, estType = TABLE
kkecdn: Single Table Predicate:"ITEMS"."TYPE"='HOT_DEAL'
Column (#2):
NewDensity:0.001974, OldDensity:0.000000 BktCnt:1067091.000000,
PopBktCnt:1067091.000000, PopValCnt:4, NDV:4
Column (#2): TYPE(VARCHAR2)
AvgLen: 7 NDV: 4 Nulls: 0 Density: 0.001974
Histogram: Freq #Bkts: 4 UncompBkts: 1067091 EndPtVals: 4
Using density:
0.001974 of col #2 as selectivity of pred having unreasonably low value
NDV / (1067091 - 1067091)"Aaggghhhh!"
98
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select * from items where type = 'HOT_DEAL';
----------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
----------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2107 | 23177 | 672 (2)|
|* 1 | TABLE ACCESS FULL| ITEMS | 2107 | 23177 | 672 (2)|
----------------------------------------------------------------
TYPE COUNT(*)
------ ----------
ORDERED 21353
ARCHIVED 4213 * 50%
NORMAL 513234
SOLD 528291
99
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
representative values
... at the right time
100
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
2) extensions
101
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
11g
102
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
"extended" statistics
103
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
aka "column groups"
104
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
solve GIGO
105
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select *
2 from ADDRESS
3 where CITY = 'Bangalore'
4 and COUNTRY = 'Australia';
106
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
107
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
automatic column groups
108
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
12.2
109
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
expression tracking
110
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select s.item_id,
2 s.category,
3 p.prod_list_price - p.prod_min_price
4 from products p,
5 sales s
6 where ....;
SQL> select expression_text, evaluation_count, fixed_cost
2 from user_expression_statistics
2 where table_name = 'PRODUCTS';
EXPRESSION_TEXT EVALUATION_COUNT FIXED_COST
---------------------------------- ---------------- ----------
"PROD_LIST_PRICE"-"PROD_MIN_PRICE" 766 .000041667
111
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
missing or poor statistics
112
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
3) online gather
113
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
the old problem
114
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> insert /*+ APPEND */ into MY_TABLE
2 select *
3 from MY_WHOPPING_GREAT_FAT_TABLE;MY_WHOPPING_GREAT_FAT_TABLE;
115
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
116
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
117
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
118
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
119
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
120
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> insert /*+ APPEND */ into MY_TABLE
2 select *
3 from MY_WHOPPING_GREAT_FAT_TABLE
4 ...
7102984123 rows created.
Elapsed: 06:12:34.00
121
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
and then...
122
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select num_rows from user_tables
2 where table_name = 'MY_TABLE';
NUM_ROWS
----------
123
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
so ...
124
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> begin
2 dbms_stats.gather_table_stats('',
3 tname=>'MY_TABLE'
4 ...
5 ...
6 end;
7 /
Elapsed: a bloody long time
125
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
126
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
on load
127
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> create table T (
2 ...
3 ...
4 ... );
Table created.
SQL> select num_rows
2 from user_tables
3 where table_name = 'T';
NUM_ROWS
----------
SQL> insert /*+ APPEND */ into T
2 select * from dba_objects;
78876 rows created.
SQL> commit;
Commit complete.
SQL> select num_rows
2 from user_tables
3 where table_name = 'T';
NUM_ROWS
----------
78876 128
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
things to note
129
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
must be direct
insert /*+ APPEND */
create table as select
130
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> insert into T select * from dba_objects;
78876 rows created.
SQL> commit;
SQL> select num_rows from user_tables
2 where table_name = 'T';
NUM_ROWS
----------
131
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
must be empty
132
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> insert into T values (....)
1 row created.
SQL> insert /*+ APPEND */ into T select * from dba_objects;
78876 rows created.
SQL> commit;
SQL> select num_rows from user_tables
2 where table_name = 'T';
NUM_ROWS
----------
133
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
execution plan
134
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> insert /*+ APPEND */ into T
2 select * from t_src;
------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
------------------------------------------------------------------------------
| 0 | INSERT STATEMENT | | 78877 | 9M| 428 (1)|
| 1 | LOAD AS SELECT | T | | | |
| 2 | OPTIMIZER STATISTICS GATHERING | | 78877 | 9M| 428 (1)|
| 3 | TABLE ACCESS FULL | T_SRC| 78877 | 9M| 428 (1)|
------------------------------------------------------------------------------
135
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select column_name, notes
2 from user_tab_col_statistics
3 where table_name = 'T';
COLUMN_NAME NOTES
------------------------------ -------------
OWNER STATS_ON_LOAD
OBJECT_NAME STATS_ON_LOAD
SUBOBJECT_NAME STATS_ON_LOAD
OBJECT_ID STATS_ON_LOAD
DATA_OBJECT_ID STATS_ON_LOAD
OBJECT_TYPE STATS_ON_LOAD
CREATED STATS_ON_LOAD
...
...
136
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
note: no histograms
137
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
3) session GTT
138
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
11g
139
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> create global temporary table t ( x int, y int )
2 on commit preserve rows;
Table created.
SQL> insert into t
2 select rownum, rownum
3 from dual
4 connect by level <= 10000;
10000 rows created.
140
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> exec dbms_stats.gather_table_stats('','T');
SQL> set autotrace traceonly explain
SQL> select * from t;
---------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
---------------------------------------------------------------
| 0 | SELECT STATEMENT | | 10000 | 80000 | 7 (0)|
| 1 | TABLE ACCESS FULL| T | 10000 | 80000 | 7 (0)|
---------------------------------------------------------------
141
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
looks great until ...
142
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> connect scott/tiger
Connected.
SQL> select count(*) from t;
COUNT(*)
----------
0
SQL> set autotrace traceonly explain
SQL> select * from t;
---------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
---------------------------------------------------------------
| 0 | SELECT STATEMENT | | 10000 | 80000 | 7 (0)|
| 1 | TABLE ACCESS FULL| T | 10000 | 80000 | 7 (0)|
---------------------------------------------------------------
143
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
144
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> create global temporary table t ( x int, y int )
2 on commit preserve rows;
Table created.
SQL> insert into t
2 select rownum, rownum
3 from dual
4 connect by level <= 10000;
10000 rows created.
145
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> exec dbms_stats.gather_table_stats('','T');
SQL> set autotrace traceonly explain
SQL> select * from t;
---------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
---------------------------------------------------------------
| 0 | SELECT STATEMENT | | 10000 | 80000 | 7 (0)|
| 1 | TABLE ACCESS FULL| T | 10000 | 80000 | 7 (0)|
---------------------------------------------------------------
as before
146
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> connect scott/tiger
Connected.
SQL> insert into t
2 select rownum, rownum
3 from dual
4 connect by level <= 50;
50 rows created.
SQL> exec dbms_stats.gather_table_stats('','T');
147
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> set autotrace traceonly explain
SQL> select * from t;
---------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
---------------------------------------------------------------
| 0 | SELECT STATEMENT | | 50 | 300 | 2 (0)|
| 1 | TABLE ACCESS FULL| T | 50 | 300 | 2 (0)|
---------------------------------------------------------------
Note
-----
- Global temporary table session private statistics used
148
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
back to session 1
149
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> set autotrace traceonly explain
SQL> select * from t;
---------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
---------------------------------------------------------------
| 0 | SELECT STATEMENT | | 10000 | 80000 | 7 (0)|
| 1 | TABLE ACCESS FULL| T | 10000 | 80000 | 7 (0)|
---------------------------------------------------------------
150
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
note: default = private
151
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
so far ...
152
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
missing or poor statistics
153
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
improved optimizer "inputs"
histograms
gather on load
private GTT
154
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
PROBLEM #2
155
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
statistics needed = "∞"
156
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
learn ... as we go
157
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
learn ... from experiences
158
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Adaptive Query Optimization #1
159
learn as we go
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
"Find all of the products with
a unit price of 15 that we have
sold more than 1 unit"
160
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> set autotrace traceonly explain
SQL> select ...
2 from order_iterms o,
3 product_info p
4 where o.unit_price = 15
5 and o.quantity > 1
6 and o.product_id = p.product_id
-----------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
-----------------------------------------------------------------
| 0 | SELECT STATEMENT | | 12 | 200 |
| 1 | NESTED LOOPS | | 12 | 200 |
| 2 | NESTED LOOPS | | 12 | 200 |
| 3 | TABLE ACCESS FULL | ORDER_ITEMS | 12 | 800 |
| 4 | INDEX UNIQUE SCAN | PRODUCT_PK | 1 | 40 |
| 5 | TABLE ACCESS BY ROWID | PRODUCT_INFO | 1 | 10 |
-----------------------------------------------------------------
161
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
162
what if there's 5000 ?
4 where o.unit_price = 15
5 and o.quantity > 1
6 and o.product_id = p.product_id
-----------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
-----------------------------------------------------------------
| 0 | SELECT STATEMENT | | 12 | 200 |
| 1 | NESTED LOOPS | | 12 | 200 |
| 2 | NESTED LOOPS | | 12 | 200 |
| 3 | TABLE ACCESS FULL | ORDER_ITEMS | 12 | 800 |
| 4 | INDEX UNIQUE SCAN | PRODUCT_PK | 1 | 40 |
| 5 | TABLE ACCESS BY ROWID | PRODUCT_INFO | 1 | 10 |
-----------------------------------------------------------------
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
the runtime plan ?
163
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select * from table(
2 dbms_xplan.display_cursor('...'));
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2000 | 16000 | 7 (0)|
| 1 | HASH JOIN | | 2000 | 16000 | 7 (0)|
| 2 | TABLE ACCESS FULL | ORDER_ITEMS | 10000 | 80000 | 7 (0)|
| 3 | TABLE ACCESS FULL | PRODUCT_INFO | 10000 | 80000 | 7 (0)|
--------------------------------------------------------------------------
164
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> desc V$SQL
Name Null? Type
----------------------------------------- -------- ----------------------------
SQL_TEXT VARCHAR2(1000)
SQL_FULLTEXT CLOB
SQL_ID VARCHAR2(13)
SHARABLE_MEM NUMBER
PERSISTENT_MEM NUMBER
...
IS_BIND_SENSITIVE VARCHAR2(1)
IS_BIND_AWARE VARCHAR2(1)
...
IS_REOPTIMIZABLE VARCHAR2(1)
IS_RESOLVED_ADAPTIVE_PLAN VARCHAR2(1)
...
SQL>
165
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
cool
166
"dodged a bullet"
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Adaptive Query Optimization #2
167
learn from experience
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select /*+ gather_plan_statistics */ ...
2 from order_iterms o,
3 product_info p
4 where o.sales_date > date '2017-01-01'
5 and o.amt > 50
6 and o.product_id = p.product_id
-------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows |
-------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 7500 | 250 |
| 1 | HASH JOIN | | 1 | 7500 | 250 |
| 2 | TABLE ACCESS FULL | ORDER_ITEMS | 1 | 7500 | 250 |
| 3 | TABLE ACCESS FULL | PRODUCT_INFO | 1 | 200 | 212 |
-------------------------------------------------------------------------
168
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> desc V$SQL
Name Null? Type
----------------------------------------- -------- ----------------------------
SQL_TEXT VARCHAR2(1000)
SQL_FULLTEXT CLOB
SQL_ID VARCHAR2(13)
SHARABLE_MEM NUMBER
PERSISTENT_MEM NUMBER
...
IS_BIND_SENSITIVE VARCHAR2(1)
IS_BIND_AWARE VARCHAR2(1)
...
IS_REOPTIMIZABLE VARCHAR2(1)
IS_RESOLVED_ADAPTIVE_PLAN VARCHAR2(1)
...
SQL>
169
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select /*+ gather_plan_statistics */ ...
2 from order_iterms o,
3 product_info p
4 where o.sales_date > date '2017-01-01'
5 and o.amt > 50
6 and o.product_id = p.product_id
-------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows |
-------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 250 | 250 |
| 1 | HASH JOIN | | 1 | 250 | 250 |
| 2 | TABLE ACCESS FULL | ORDER_ITEMS | 1 | 250 | 250 |
| 3 | TABLE ACCESS FULL | PRODUCT_INFO | 1 | 212 | 212 |
-------------------------------------------------------------------------
Note:
- statistics feedback used for this statement
170
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
seems cool
171
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
we mightta got carried away :-(
172
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select
2 directive_id,
3 type,
4 reason
5 from DBA_SQL_PLAN_DIRECTIVES;
DIRECTIVE_ID TYPE REASON
---------------------- ----------------------- ------------------------------------
14774885086507357845 DYNAMIC_SAMPLING JOIN CARDINALITY MISESTIMATE
3814111798494124542 DYNAMIC_SAMPLING JOIN CARDINALITY MISESTIMATE
14157928931483804012 DYNAMIC_SAMPLING JOIN CARDINALITY MISESTIMATE
3273885094090423666 DYNAMIC_SAMPLING JOIN CARDINALITY MISESTIMATE
17607835686132426105 DYNAMIC_SAMPLING SINGLE TABLE CARDINALITY MISESTIMATE
28719982731298412 DYNAMIC_SAMPLING_RESULT SINGLE TABLE CARDINALITY MISESTIMATE
1591495495394657516 DYNAMIC_SAMPLING JOIN CARDINALITY MISESTIMATE
162577689324691883 DYNAMIC_SAMPLING JOIN CARDINALITY MISESTIMATE
13736133022354002565 DYNAMIC_SAMPLING JOIN CARDINALITY MISESTIMATE
7592221435558555884 DYNAMIC_SAMPLING SINGLE TABLE CARDINALITY MISESTIMATE
...
...
173
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select ...
2 from order_iterms o,
3 product_info p
4 where o.sales_date > date '2017-01-01'
5 and o.product_id = p.product_id
Note:
- 3 Sql Plan Directives used for this statement
174
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
same SQL ...
175
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
... different plans
176
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
... then more different plans
177
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
... then even more different plans
178
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
179
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
A common criticism ....
180
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
upgrade to 12.1
181
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
new optimizations
182
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
new statistics
183
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
default = everything enabled
184
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
185
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
"the plans keep changing"
186
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
just one switch
187
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
188
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
options
189
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
optimizer_adaptive_features = false
190
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
optimizer_features_enable = 11.2.0.4
191
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
don't panic ... that's fine
endorsed
192
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
12.1 ... perhaps too aggressive
193
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
12.2 ... more control
194
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
12.2 ... more passive
195
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
TRUE FALSE 196
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
12.2 ... much better
197
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
12.1
patch 22652097
198
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
which brings us to ...
199
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
upgrade scenarios
200
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
there are only two
201
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
1) your system sucks :-)
202
upgrade to 12.2
explore full adaptive
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
2) your system is OK
203
how can I lower risk ?
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL Plan Baselines
204
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
apology #1
205
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
206
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
but ultimately ...
207
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
... just three things
208
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
try run stuff good
1
209
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
when it's running good …
2
210
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
… keep running it like that !
211
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
If there is something better
212
3
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
then tell me
213
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
214
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
215
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
baselines do exactly this !
216
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
rarely used
217
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
apology #2
218
evolve
accepted
repeatable
unaccepted
capture
signature
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
close to our goals
219
working good ? Keep it
found something better ? Tell me
found something worse ? Don’t use it
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
not new
220
11g
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
(quick) terminology
221
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
signature
222
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select sal
from emp
where empno = ...
SQL> select SAL
from EMP where EMPNO = ...
SQL> SELECT /* comment */ SAL FROM EMP
WHERE EMPNO = ...
etc
etc
223
signature
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
plan(s) for signature
224
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
225
SELECT A.DATA,
B.DATA
FROM TAB1 A, TAB2
WHERE B.TAB1_ID = A.ID
AND A.CODE = :1
-----------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
-----------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | |
| 1 | NESTED LOOPS | | 25 | 425 |
| 2 | NESTED LOOPS | | 25 | 425 |
|* 3 | TABLE ACCESS FULL | TAB1 | 1 | 11 |
|* 4 | INDEX RANGE SCAN | TAB2_TAB1_FKI | 25 | |
| 5 | TABLE ACCESS BY INDEX ROWID| TAB2 | 25 | 150 |
-----------------------------------------------------------------------
select a.data, b.data
from tab1 a, tab2
where b.tab1_id = a.id
and a.code = :1
"capture" a baseline
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
226
SELECT A.DATA,
B.DATA
FROM TAB1 A, TAB2
WHERE B.TAB1_ID = A.ID
AND A.CODE = :1
-----------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
-----------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | |
| 1 | NESTED LOOPS | | 25 | 425 |
| 2 | NESTED LOOPS | | 25 | 425 |
|* 3 | TABLE ACCESS FULL | TAB1 | 1 | 11 |
|* 4 | INDEX RANGE SCAN | TAB2_TAB1_FKI | 25 | |
| 5 | TABLE ACCESS BY INDEX ROWID| TAB2 | 25 | 150 |
-----------------------------------------------------------------------
------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | |
| * 1 | HASH JOIN | | 25 | 425 |
| * 5 | TABLE ACCESS FULL | TAB1 | 1 | 11 |
| 8 | TABLE ACCESS FULL | TAB2 | 25 | 150 |
------------------------------------------------------------------------
select a.data, b.data
from tab1 a, tab2
where b.tab1_id = a.id
and a.code = :1
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
when it's running good …
227
… keep running it like that !
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
228
SELECT A.DATA,
B.DATA
FROM TAB1 A, TAB2
WHERE B.TAB1_ID = A.ID
AND A.CODE = :1
-----------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
-----------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | |
| 1 | NESTED LOOPS | | 25 | 425 |
| 2 | NESTED LOOPS | | 25 | 425 |
|* 3 | TABLE ACCESS FULL | TAB1 | 1 | 11 |
|* 4 | INDEX RANGE SCAN | TAB2_TAB1_FKI | 25 | |
| 5 | TABLE ACCESS BY INDEX ROWID| TAB2 | 25 | 150 |
-----------------------------------------------------------------------
------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | |
| * 1 | HASH JOIN | | 25 | 425 |
| * 5 | TABLE ACCESS FULL | TAB1 | 1 | 11 |
| 8 | TABLE ACCESS FULL | TAB2 | 25 | 150 |
------------------------------------------------------------------------
select a.data, b.data
from tab1 a, tab2
where b.tab1_id = a.id
and a.code = :1
but we saved this !
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
maybe it is better ?
229
------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | |
| * 1 | HASH JOIN | | 25 | 425 |
| * 5 | TABLE ACCESS FULL | TAB1 | 1 | 11 |
| 8 | TABLE ACCESS FULL | TAB2 | 25 | 150 |
------------------------------------------------------------------------
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
evolve a plan
230
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
DBMS_SPM.EVOLVE_SQL_PLAN_BASELINE
231
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
232
SELECT A.DATA,
B.DATA
FROM TAB1 A, TAB2
WHERE B.TAB1_ID = A.ID
AND A.CODE = :1
-----------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
-----------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | |
| 1 | NESTED LOOPS | | 25 | 425 |
| 2 | NESTED LOOPS | | 25 | 425 |
|* 3 | TABLE ACCESS FULL | TAB1 | 1 | 11 |
|* 4 | INDEX RANGE SCAN | TAB2_TAB1_FKI | 25 | |
| 5 | TABLE ACCESS BY INDEX ROWID| TAB2 | 25 | 150 |
-----------------------------------------------------------------------
------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | |
| * 1 | HASH JOIN | | 25 | 425 |
| * 5 | TABLE ACCESS FULL | TAB1 | 1 | 11 |
| 8 | TABLE ACCESS FULL | TAB2 | 25 | 150 |
------------------------------------------------------------------------
select a.data, b.data
from tab1 a, tab2
where b.tab1_id = a.id
and a.code = :1
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
unless …
233
… that makes it bad or
there's something better
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
if only we had done ...
234
DBMS_SPM.I_LOVE_THIS_PLAN(sql_id)
DBMS_SPM. THIS_PLAN_SUCKS(sql_id)
DBMS_SPM. SWAP_THIS_PLAN_IN(sql_id)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
so back to upgrade
235
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
2) your system is OK
236
how can I lower risk ?
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> alter system set
2 optimizer_capture_sql_plan_baselines = true
237
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> exec DBMS_SPM.PACK_STGTAB_BASELINE
(datapump)
SQL> exec DBMS_SPM.UNPACK_STGTAB_BASELINE
238
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
the same performance
239
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
240
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
wrap up
241
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
12c optimizer is better
242
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
12c optimizer is different
243
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
12.2 preferred
244
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
12.1 ... backport
245
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SPM is your friend
246
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
That's a wrap!
youtube bit.ly/youtube-connor
blog bit.ly/blog-connor
twitter bit.ly/twitter-connor
400+ posts mainly on database & development
250 technical videos, new uploads every week
rants and raves on tech and the world :-)

Wellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer

  • 1.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. Taming the beast The 12c Optimizer Connor McDonald 1
  • 2.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. Connor McDonald
  • 3.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. 3
  • 4.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. 4
  • 5.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. | Stuff youtube bit.ly/youtube-connor blog bit.ly/blog-connor twitter bit.ly/twitter-connor 400+ posts mainly on database & development 250 technical videos, new uploads every week rants and raves on tech and the world :-)
  • 6.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. etc... facebook bit.ly/facebook-connor linkedin bit.ly/linkedin-connor instagram bit.ly/instagram-connor slideshare bit.ly/slideshare-connor
  • 7.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. 7https://asktom.oracle.com
  • 8.
    Copyright © 2018,Oracle and/or its affiliates. All rights reserved. https://asktom.oracle.com/officehours
  • 9.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 150 hours free access so far 9
  • 10.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. this session 10
  • 11.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 3 things 11
  • 12.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 12c optimizer … better performance 12
  • 13.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 12c optimizer … worse performance 13
  • 14.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. worse performance … 14
  • 15.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 15
  • 16.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 16
  • 17.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. goal of the optimizer 17
  • 18.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. simple 18
  • 19.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. good execution plan 19
  • 20.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. so how did we end up here ? 20
  • 21.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. Hi, I'm the optimizer. How I can help ? 21
  • 22.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. Hi, I'm the optimizer. How I can help ? What I would really like … 22
  • 23.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. Hi, I'm the optimizer. How I can help ? What I would really like … … is for you to suffer like I do 23
  • 24.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. PROBLEM #1 24
  • 25.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. missing or poor statistics 25
  • 26.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. cardinality mis-estimates 26
  • 27.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. cardinality is everything 27
  • 28.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 28
  • 29.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. better stats 29
  • 30.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. missing or poor statistics 30
  • 31.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 1) better histograms 31
  • 32.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> create table T 2 as select * from dba_objects; Table created. SQL> exec dbms_stats.gather_table_stats('','T'); PL/SQL procedure successfully completed. 32
  • 33.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select COLUMN_NAME,NUM_DISTINCT, 2 ( select count(*) 3 from all_tab_histograms 4 where owner = a.owner 5 and table_name = a.table_name 6 and column_name = a.column_name ) 7 from all_tab_cols a 8 where table_name = 'T' 9 order by column_id; COLUMN_NAME NUM_DISTINCT HIST_CNT ------------------------------ ------------ ---------- OWNER 25 2 OBJECT_NAME 53000 2 SUBOBJECT_NAME 230 2 OBJECT_ID 90808 2 33
  • 34.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 34
  • 35.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 35
  • 36.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select intcol#,equality_preds, 2 range_preds,timestamp 3 from sys.col_usage$ 4 where obj# = (select object_id 5 from obj 6 where object_name = 'T' ); INTCOL# EQUALITY_PREDS RANGE_PREDS TIMESTAMP ---------- -------------- ----------- --------- 1 1 0 24-SEP-17 36
  • 37.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> exec dbms_stats.gather_table_stats('','T'); SQL> select COLUMN_NAME,NUM_DISTINCT, 2 ( select count(*) 3 from all_tab_histograms 4 where owner = a.owner 5 and table_name = a.table_name 6 and column_name = a.column_name ) 7 from all_tab_cols a 8 where table_name = 'T' 9 order by column_id; COLUMN_NAME NUM_DISTINCT HIST_CNT ------------------------------ ------------ ---------- OWNER 25 25 OBJECT_NAME 53000 2 SUBOBJECT_NAME 230 2 OBJECT_ID 90808 2 37
  • 38.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. we don't know what your "app" is 38
  • 39.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. still requires care 39
  • 40.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 12c improvements 40
  • 41.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select status, count(*) 2 from orders 3 group by status 4 order by 1; STATUS COUNT(*) -------------------- ---------- 1-New 1000 2-Assigned 10 3-InProgress 4000 4-Processed 3 5-Shipped 800 6-Received 5000 7-Completed 15000 8-Archived 20000 41
  • 42.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. skewed ... 42
  • 43.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. ... need histogram 43
  • 44.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 11g 44
  • 45.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> begin 2 dbms_stats.gather_table_stats('','ORDERS', 3 method_opt=>'for all columns size 15'); 4 end; 5 / PL/SQL procedure successfully completed. SQL> select histogram from USER_TAB_COL_STATISTICS 2 where table_name = 'ORDERS'; HISTOGRAM --------------- FREQUENCY 45
  • 46.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select 2 endpoint_number, 3 substr( 4 utl_raw.cast_to_varchar2( 5 hextoraw(to_char(endpoint_value,rpad('FM',65,'X')))),1,5), 6 endpoint_number - 7 nvl(lag(endpoint_number) over ( order by endpoint_number),0) 8 from user_histograms 9 where table_name = 'ORDERS' 10 order by 1; ENDPOINT_NUMBER END_VAL FREQ --------------- -------------------- ---------- 1000 1-Nev 1000 1010 2-Ass 10 5010 3-InP 4000 5013 4-Pro 3 5813 5-Shi 800 10813 6-Rec 5000 25813 7-Com 15000 45813 8-Arc 20000 46
  • 47.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select 2 endpoint_number, 3 substr( 4 utl_raw.cast_to_varchar2( 5 hextoraw(to_char(endpoint_value,rpad('FM',65,'X')))),1,5), 6 endpoint_number - 7 nvl(lag(endpoint_number) over ( order by endpoint_number),0) 8 from user_histograms 9 where table_name = 'ORDERS' 10 order by 1; ENDPOINT_NUMBER END_VAL FREQ --------------- -------------------- ---------- 1000 1-Nev 1000 1010 2-Ass 10 5010 3-InP 4000 5013 4-Pro 3 5813 5-Shi 800 10813 6-Rec 5000 25813 7-Com 15000 45813 8-Arc 20000 47
  • 48.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select 2 endpoint_number, 3 substr( 4 utl_raw.cast_to_varchar2( 5 hextoraw(to_char(endpoint_value,rpad('FM',65,'X')))),1,5), 6 endpoint_number - 7 nvl(lag(endpoint_number) over ( order by endpoint_number),0) 8 from user_histograms 9 where table_name = 'ORDERS' 10 order by 1; ENDPOINT_NUMBER END_VAL FREQ --------------- -------------------- ---------- 1000 1-Nev 1000 1010 2-Ass 10 5010 3-InP 4000 5013 4-Pro 3 5813 5-Shi 800 10813 6-Rec 5000 25813 7-Com 15000 45813 8-Arc 20000 48
  • 49.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select * from orders 2 where status = '5-Shipped'; ---------------------------------------------------- | Id | Operation | Name | Rows | Bytes | ---------------------------------------------------- | 0 | SELECT STATEMENT | | 800 | 8800 | |* 1 | TABLE ACCESS FULL| ORDERS | 800 | 8800 | ---------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("STATUS"='5-Shipped') 49 true = 800
  • 50.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. so far … so good 50
  • 51.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. NDV > 254* 51
  • 52.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> begin 2 dbms_stats.gather_table_stats('','ORDERS', 3 method_opt=>'for all columns size 6'); 4 end; 5 / PL/SQL procedure successfully completed. SQL> select histogram from USER_TAB_COL_STATISTICS 2 where table_name = 'ORDERS'; HISTOGRAM --------------- HEIGHT BALANCED 52
  • 53.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select 2 endpoint_number, 3 substr( 4 utl_raw.cast_to_varchar2( 5 hextoraw(to_char(endpoint_value,rpad('FM',65,'X')))),1,5), 6 endpoint_number - 7 nvl(lag(endpoint_number) over ( order by endpoint_number),0) 8 from user_histograms 9 where table_name = 'ORDERS' 10 order by 1; ENDPOINT_NUMBER END_VAL BKTS --------------- -------------------- ---------- 0 1-Nev 0 1 6-Rec 1 3 7-Com 2 6 8-Arc 3 53
  • 54.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 1-New 6-Received 7-Complete 8-Archived 8-Archived 8-Archived 7-Complete 54
  • 55.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select * from orders 2 where status = '8-Archived'; ---------------------------------------------------- | Id | Operation | Name | Rows | Bytes | ---------------------------------------------------- | 0 | SELECT STATEMENT | | 19089 | 205K| |* 1 | TABLE ACCESS FULL| ORDERS | 19089 | 205K| ---------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("STATUS"='8-Archived') true = 20000 55
  • 56.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select * from orders 2 where status = '7-Completed'; ----------------------------------------------------- | Id | Operation | Name | Rows | Bytes | ----------------------------------------------------- | 0 | SELECT STATEMENT | | 15271 | 164K| |* 1 | TABLE ACCESS FULL| ORDERS | 15271 | 164K| ----------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("STATUS"='7-Completed') true = 10000 56
  • 57.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 57
  • 58.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 1-New 6-Received 7-Complete 8-Archived 8-Archived 8-Archived 7-Completetotal ~ 45,000 ~7000 per bucket 58
  • 59.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 1-New 6-Received 7-Complete 8-Archived 8-Archived 8-Archived 7-Completetotal = 45,000 ~7000 per bucket 59
  • 60.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select * from orders 2 where status = '2-Assigned'; ---------------------------------------------------- | Id | Operation | Name | Rows | Bytes | ---------------------------------------------------- | 0 | SELECT STATEMENT | | 1273 | 14003 | |* 1 | TABLE ACCESS FULL| ORDERS | 1273 | 14003 | ---------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("STATUS"='2-Assigned') true = 3 60
  • 61.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. height balanced means ... 61
  • 62.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. bucket spanning = dramas 62
  • 63.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. bucket swallowing = dramas 63
  • 64.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 11g HEIGHT-BALANCED FREQUENCY 64
  • 65.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. Footnote: 11g FOR ALL COLUMNS SIZE 25AUTO 65
  • 66.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 66
  • 67.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> begin 2 dbms_stats.gather_table_stats('','ORDERS', 3 method_opt=>'for all columns size 15'); 4 end; 5 / PL/SQL procedure successfully completed. SQL> select histogram from USER_TAB_COL_STATISTICS 2 where table_name = 'ORDERS'; HISTOGRAM --------------- FREQUENCY 67
  • 68.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> begin 2 dbms_stats.gather_table_stats('','ORDERS', 3 method_opt=>'for all columns size 6'); 4 end; 5 / PL/SQL procedure successfully completed. SQL> select histogram from USER_TAB_COL_STATISTICS 2 where table_name = 'ORDERS'; HISTOGRAM --------------- TOP-FREQUENCY 68
  • 69.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select 2 endpoint_number, 3 substr( 4 utl_raw.cast_to_varchar2( 5 hextoraw(to_char(endpoint_value,rpad('FM',65,'X')))),1,5) 6 endpoint_number - 7 nvl(lag(endpoint_number) over ( order by endpoint_number),0) 8 from user_histograms 9 where table_name = 'ORDERS' 10 order by 1; ENDPOINT_NUMBER END_VAL FREQ --------------- -------------------- ---------- 1000 1-Nev 1000 5000 3-InP 4000 5800 5-Shi 800 10800 6-Rec 5000 25800 7-Com 15000 45800 8-Arc 20000 69
  • 70.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 1-New 6-Received 3-InProgress 5-Shipped 8-Archived 7-Completed 70
  • 71.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. other values ? 71
  • 72.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select num_rows 2 from user_tables 3 where table_name = 'ORDERS'; NUM_ROWS ---------- 45813 SQL> select num_distinct 2 from user_tab_cols 3 where table_name = 'ORDERS'; NUM_DISTINCT ------------ 8 FREQ ---------- 800 1000 4000 5000 15000 20000 ======== 45800 ( 45813 - 45800 ) / ( 8 - 6 ) = 72
  • 73.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select * from orders 2 where status = '4-Processed'; ----------------------------------------------------- | Id | Operation | Name | Rows | Bytes | ----------------------------------------------------- | 0 | SELECT STATEMENT | | 7 | 77 | |* 1 | TABLE ACCESS FULL| ORDERS | 7 | 77 | ----------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("STATUS"='4-Processed') 73 true = 3
  • 74.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. what defines "TOP" % top values > ((bkt-1)/bkt)* num eg 1000 rows/ 12 bucket 12 most frequent > 11/12 * 1000 ~920 rows 74
  • 75.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. what if TOP FREQ not possible ? 75
  • 76.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> insert into orders select '1-New' 2 from dual connect by level <= 9000; SQL> insert into orders select '2-Assigned' 2 from dual connect by level <= 9500; SQL> insert into orders select '3-InProgress' 2 from dual connect by level <= 6000; SQL> insert into orders select '4-Processed' 2 from dual connect by level <= 9500; SQL> insert into orders select '5-Shipped' 2 from dual connect by level <= 8800; SQL> insert into orders select '6-Received' 2 from dual connect by level <= 4500; 76
  • 77.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select status, count(*) 2 from orders 3 group by status 4 order by 1; STATUS COUNT(*) -------------------- ---------- 1-New 10000 2-Assigned 9510 3-InProgress 10000 4-Processed 9503 5-Shipped 9600 6-Received 9500 7-Completed 15000 8-Archived 20000 77
  • 78.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> begin 2 dbms_stats.gather_table_stats('','ORDERS', 3 method_opt=>'for all columns size 6'); 4 end; 5 / PL/SQL procedure successfully completed. SQL> select histogram from USER_TAB_COL_STATISTICS 2 where table_name = 'ORDERS'; HISTOGRAM --------------- HYBRID 78
  • 79.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select 2 endpoint_number, 3 substr( 4 utl_raw.cast_to_varchar2( 5 hextoraw(to_char(endpoint_value,rpad('FM',65,'X')))),1,5), 6 endpoint_number - 7 nvl(lag(endpoint_number) over ( order by endpoint_number),0), 8 endpoint_repeat_count 9 from user_histograms 10 where table_name = 'ORDERS' 11 order by 1; ENDPOINT_NUMBER END_VAL FREQ ENDPOINT_REPEAT_COUNT --------------- -------------------- ---------- --------------------- 590 1-Nev 590 590 1743 3-InP 1153 626 2314 4-Pro 571 571 2895 5-Shi 581 581 3449 6-Rec 554 554 5547 8-Arc 2098 1213 79
  • 80.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 1-New 6-Received 3-InProgress 5-Shipped 8-Archived 4-Processed ENDPOINT_NUMBER END_VAL FREQ ENDPOINT_REPEAT_COUNT --------------- -------------------- ---------- --------------------- 590 1-Nev 590 590 1743 3-InP 1153 626 2314 4-Pro 571 571 2895 5-Shi 581 581 3449 6-Rec 554 554 5547 8-Arc 2098 1213 2-Assigned 590 1153 571 581 554 2098 7-Completed 80
  • 81.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 8-Archived END_VAL FREQ ENDPOINT_REPEAT_COUNT ---------------- -------- --------------------- 1-Nev 590 590 3-InP 1153 626 4-Pro 571 571 5-Shi 581 581 6-Rec 554 554 8-Arc 2098 1213 2098 7-Completed "Bucket 8-Arc has 2098 occurrences... 1213 of them are the end value 8-Arc... therefore 885 are > 6-Rec and < 8-Arc" 81 6-Received 554
  • 82.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. no bucket spanning 82
  • 83.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. key point 83
  • 84.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. must use auto sample size 84
  • 85.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. still need care 85
  • 86.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. representative values 86
  • 87.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 87
  • 88.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. "today's hot deals" 88
  • 89.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. gather statistics SQL> select count(*) 2 from items 3 where type = 'HOT_DEAL' COUNT(*) ---------- 0 89
  • 90.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. activate "deals of the day" SQL> update items 2 set type = 'HOT_DEAL' 3 where ... SQL> select count(*) 2 from items 3 where type = 'HOT_DEAL' COUNT(*) ---------- 14 90
  • 91.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. biggest day of the year ! SQL> select min(discount) 2 from items 3 where type = 'HOT_DEAL' 4 and ... where type = 'HOT_DEAL' SQL> select free_shipping 2 from items 3 where hot_deal = 'Y' 4 and ... SQL> select ... 2 from ... SQL> select ... 2 from ... SQL> select ... 2 from ... SQL> select ... 2 from ...SQL> select ... 2 from ... 91
  • 92.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 92
  • 93.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. where type = 'HOT_DEAL' 93
  • 94.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 94
  • 95.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select type, count(*) 2 from items 3 group by type; TYPE COUNT(*) ------ ---------- ORDERED 21353 ARCHIVED 4213 NORMAL 513234 SOLD 528291 HOT_DEAL 0 95
  • 96.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. normally... 96
  • 97.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. "ok... I got 1,000,000 total rows... and 7 distinct values. I got a frequency histogram... There's 4 popular values, adding up to 910,000 That's 3 values left to cover the rest 3 / ( 1,000,000 - 910,000) = density ... I'm done!" 97
  • 98.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SINGLE TABLE ACCESS PATH Single Table Cardinality Estimation for ITEMS[ITEMS] SPD: Return code in qosdDSDirSetup: NOCTX, estType = TABLE kkecdn: Single Table Predicate:"ITEMS"."TYPE"='HOT_DEAL' Column (#2): NewDensity:0.001974, OldDensity:0.000000 BktCnt:1067091.000000, PopBktCnt:1067091.000000, PopValCnt:4, NDV:4 Column (#2): TYPE(VARCHAR2) AvgLen: 7 NDV: 4 Nulls: 0 Density: 0.001974 Histogram: Freq #Bkts: 4 UncompBkts: 1067091 EndPtVals: 4 Using density: 0.001974 of col #2 as selectivity of pred having unreasonably low value NDV / (1067091 - 1067091)"Aaggghhhh!" 98
  • 99.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select * from items where type = 'HOT_DEAL'; ---------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| ---------------------------------------------------------------- | 0 | SELECT STATEMENT | | 2107 | 23177 | 672 (2)| |* 1 | TABLE ACCESS FULL| ITEMS | 2107 | 23177 | 672 (2)| ---------------------------------------------------------------- TYPE COUNT(*) ------ ---------- ORDERED 21353 ARCHIVED 4213 * 50% NORMAL 513234 SOLD 528291 99
  • 100.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. representative values ... at the right time 100
  • 101.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 2) extensions 101
  • 102.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 11g 102
  • 103.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. "extended" statistics 103
  • 104.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. aka "column groups" 104
  • 105.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. solve GIGO 105
  • 106.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select * 2 from ADDRESS 3 where CITY = 'Bangalore' 4 and COUNTRY = 'Australia'; 106
  • 107.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 107
  • 108.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. automatic column groups 108
  • 109.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 12.2 109
  • 110.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. expression tracking 110
  • 111.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select s.item_id, 2 s.category, 3 p.prod_list_price - p.prod_min_price 4 from products p, 5 sales s 6 where ....; SQL> select expression_text, evaluation_count, fixed_cost 2 from user_expression_statistics 2 where table_name = 'PRODUCTS'; EXPRESSION_TEXT EVALUATION_COUNT FIXED_COST ---------------------------------- ---------------- ---------- "PROD_LIST_PRICE"-"PROD_MIN_PRICE" 766 .000041667 111
  • 112.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. missing or poor statistics 112
  • 113.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 3) online gather 113
  • 114.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. the old problem 114
  • 115.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> insert /*+ APPEND */ into MY_TABLE 2 select * 3 from MY_WHOPPING_GREAT_FAT_TABLE;MY_WHOPPING_GREAT_FAT_TABLE; 115
  • 116.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 116
  • 117.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 117
  • 118.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 118
  • 119.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 119
  • 120.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 120
  • 121.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> insert /*+ APPEND */ into MY_TABLE 2 select * 3 from MY_WHOPPING_GREAT_FAT_TABLE 4 ... 7102984123 rows created. Elapsed: 06:12:34.00 121
  • 122.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. and then... 122
  • 123.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select num_rows from user_tables 2 where table_name = 'MY_TABLE'; NUM_ROWS ---------- 123
  • 124.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. so ... 124
  • 125.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> begin 2 dbms_stats.gather_table_stats('', 3 tname=>'MY_TABLE' 4 ... 5 ... 6 end; 7 / Elapsed: a bloody long time 125
  • 126.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 126
  • 127.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. on load 127
  • 128.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> create table T ( 2 ... 3 ... 4 ... ); Table created. SQL> select num_rows 2 from user_tables 3 where table_name = 'T'; NUM_ROWS ---------- SQL> insert /*+ APPEND */ into T 2 select * from dba_objects; 78876 rows created. SQL> commit; Commit complete. SQL> select num_rows 2 from user_tables 3 where table_name = 'T'; NUM_ROWS ---------- 78876 128
  • 129.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. things to note 129
  • 130.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. must be direct insert /*+ APPEND */ create table as select 130
  • 131.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> insert into T select * from dba_objects; 78876 rows created. SQL> commit; SQL> select num_rows from user_tables 2 where table_name = 'T'; NUM_ROWS ---------- 131
  • 132.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. must be empty 132
  • 133.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> insert into T values (....) 1 row created. SQL> insert /*+ APPEND */ into T select * from dba_objects; 78876 rows created. SQL> commit; SQL> select num_rows from user_tables 2 where table_name = 'T'; NUM_ROWS ---------- 133
  • 134.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. execution plan 134
  • 135.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> insert /*+ APPEND */ into T 2 select * from t_src; ------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| ------------------------------------------------------------------------------ | 0 | INSERT STATEMENT | | 78877 | 9M| 428 (1)| | 1 | LOAD AS SELECT | T | | | | | 2 | OPTIMIZER STATISTICS GATHERING | | 78877 | 9M| 428 (1)| | 3 | TABLE ACCESS FULL | T_SRC| 78877 | 9M| 428 (1)| ------------------------------------------------------------------------------ 135
  • 136.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select column_name, notes 2 from user_tab_col_statistics 3 where table_name = 'T'; COLUMN_NAME NOTES ------------------------------ ------------- OWNER STATS_ON_LOAD OBJECT_NAME STATS_ON_LOAD SUBOBJECT_NAME STATS_ON_LOAD OBJECT_ID STATS_ON_LOAD DATA_OBJECT_ID STATS_ON_LOAD OBJECT_TYPE STATS_ON_LOAD CREATED STATS_ON_LOAD ... ... 136
  • 137.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. note: no histograms 137
  • 138.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 3) session GTT 138
  • 139.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 11g 139
  • 140.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> create global temporary table t ( x int, y int ) 2 on commit preserve rows; Table created. SQL> insert into t 2 select rownum, rownum 3 from dual 4 connect by level <= 10000; 10000 rows created. 140
  • 141.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> exec dbms_stats.gather_table_stats('','T'); SQL> set autotrace traceonly explain SQL> select * from t; --------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| --------------------------------------------------------------- | 0 | SELECT STATEMENT | | 10000 | 80000 | 7 (0)| | 1 | TABLE ACCESS FULL| T | 10000 | 80000 | 7 (0)| --------------------------------------------------------------- 141
  • 142.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. looks great until ... 142
  • 143.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> connect scott/tiger Connected. SQL> select count(*) from t; COUNT(*) ---------- 0 SQL> set autotrace traceonly explain SQL> select * from t; --------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| --------------------------------------------------------------- | 0 | SELECT STATEMENT | | 10000 | 80000 | 7 (0)| | 1 | TABLE ACCESS FULL| T | 10000 | 80000 | 7 (0)| --------------------------------------------------------------- 143
  • 144.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 144
  • 145.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> create global temporary table t ( x int, y int ) 2 on commit preserve rows; Table created. SQL> insert into t 2 select rownum, rownum 3 from dual 4 connect by level <= 10000; 10000 rows created. 145
  • 146.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> exec dbms_stats.gather_table_stats('','T'); SQL> set autotrace traceonly explain SQL> select * from t; --------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| --------------------------------------------------------------- | 0 | SELECT STATEMENT | | 10000 | 80000 | 7 (0)| | 1 | TABLE ACCESS FULL| T | 10000 | 80000 | 7 (0)| --------------------------------------------------------------- as before 146
  • 147.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> connect scott/tiger Connected. SQL> insert into t 2 select rownum, rownum 3 from dual 4 connect by level <= 50; 50 rows created. SQL> exec dbms_stats.gather_table_stats('','T'); 147
  • 148.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> set autotrace traceonly explain SQL> select * from t; --------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| --------------------------------------------------------------- | 0 | SELECT STATEMENT | | 50 | 300 | 2 (0)| | 1 | TABLE ACCESS FULL| T | 50 | 300 | 2 (0)| --------------------------------------------------------------- Note ----- - Global temporary table session private statistics used 148
  • 149.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. back to session 1 149
  • 150.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> set autotrace traceonly explain SQL> select * from t; --------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| --------------------------------------------------------------- | 0 | SELECT STATEMENT | | 10000 | 80000 | 7 (0)| | 1 | TABLE ACCESS FULL| T | 10000 | 80000 | 7 (0)| --------------------------------------------------------------- 150
  • 151.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. note: default = private 151
  • 152.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. so far ... 152
  • 153.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. missing or poor statistics 153
  • 154.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. improved optimizer "inputs" histograms gather on load private GTT 154
  • 155.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. PROBLEM #2 155
  • 156.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. statistics needed = "∞" 156
  • 157.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. learn ... as we go 157
  • 158.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. learn ... from experiences 158
  • 159.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. Adaptive Query Optimization #1 159 learn as we go
  • 160.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. "Find all of the products with a unit price of 15 that we have sold more than 1 unit" 160
  • 161.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> set autotrace traceonly explain SQL> select ... 2 from order_iterms o, 3 product_info p 4 where o.unit_price = 15 5 and o.quantity > 1 6 and o.product_id = p.product_id ----------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | ----------------------------------------------------------------- | 0 | SELECT STATEMENT | | 12 | 200 | | 1 | NESTED LOOPS | | 12 | 200 | | 2 | NESTED LOOPS | | 12 | 200 | | 3 | TABLE ACCESS FULL | ORDER_ITEMS | 12 | 800 | | 4 | INDEX UNIQUE SCAN | PRODUCT_PK | 1 | 40 | | 5 | TABLE ACCESS BY ROWID | PRODUCT_INFO | 1 | 10 | ----------------------------------------------------------------- 161
  • 162.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 162 what if there's 5000 ? 4 where o.unit_price = 15 5 and o.quantity > 1 6 and o.product_id = p.product_id ----------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | ----------------------------------------------------------------- | 0 | SELECT STATEMENT | | 12 | 200 | | 1 | NESTED LOOPS | | 12 | 200 | | 2 | NESTED LOOPS | | 12 | 200 | | 3 | TABLE ACCESS FULL | ORDER_ITEMS | 12 | 800 | | 4 | INDEX UNIQUE SCAN | PRODUCT_PK | 1 | 40 | | 5 | TABLE ACCESS BY ROWID | PRODUCT_INFO | 1 | 10 | -----------------------------------------------------------------
  • 163.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. the runtime plan ? 163
  • 164.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select * from table( 2 dbms_xplan.display_cursor('...')); -------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| -------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 2000 | 16000 | 7 (0)| | 1 | HASH JOIN | | 2000 | 16000 | 7 (0)| | 2 | TABLE ACCESS FULL | ORDER_ITEMS | 10000 | 80000 | 7 (0)| | 3 | TABLE ACCESS FULL | PRODUCT_INFO | 10000 | 80000 | 7 (0)| -------------------------------------------------------------------------- 164
  • 165.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> desc V$SQL Name Null? Type ----------------------------------------- -------- ---------------------------- SQL_TEXT VARCHAR2(1000) SQL_FULLTEXT CLOB SQL_ID VARCHAR2(13) SHARABLE_MEM NUMBER PERSISTENT_MEM NUMBER ... IS_BIND_SENSITIVE VARCHAR2(1) IS_BIND_AWARE VARCHAR2(1) ... IS_REOPTIMIZABLE VARCHAR2(1) IS_RESOLVED_ADAPTIVE_PLAN VARCHAR2(1) ... SQL> 165
  • 166.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. cool 166 "dodged a bullet"
  • 167.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. Adaptive Query Optimization #2 167 learn from experience
  • 168.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select /*+ gather_plan_statistics */ ... 2 from order_iterms o, 3 product_info p 4 where o.sales_date > date '2017-01-01' 5 and o.amt > 50 6 and o.product_id = p.product_id ------------------------------------------------------------------------- | Id | Operation | Name | Starts | E-Rows | A-Rows | ------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 7500 | 250 | | 1 | HASH JOIN | | 1 | 7500 | 250 | | 2 | TABLE ACCESS FULL | ORDER_ITEMS | 1 | 7500 | 250 | | 3 | TABLE ACCESS FULL | PRODUCT_INFO | 1 | 200 | 212 | ------------------------------------------------------------------------- 168
  • 169.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> desc V$SQL Name Null? Type ----------------------------------------- -------- ---------------------------- SQL_TEXT VARCHAR2(1000) SQL_FULLTEXT CLOB SQL_ID VARCHAR2(13) SHARABLE_MEM NUMBER PERSISTENT_MEM NUMBER ... IS_BIND_SENSITIVE VARCHAR2(1) IS_BIND_AWARE VARCHAR2(1) ... IS_REOPTIMIZABLE VARCHAR2(1) IS_RESOLVED_ADAPTIVE_PLAN VARCHAR2(1) ... SQL> 169
  • 170.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select /*+ gather_plan_statistics */ ... 2 from order_iterms o, 3 product_info p 4 where o.sales_date > date '2017-01-01' 5 and o.amt > 50 6 and o.product_id = p.product_id ------------------------------------------------------------------------- | Id | Operation | Name | Starts | E-Rows | A-Rows | ------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 250 | 250 | | 1 | HASH JOIN | | 1 | 250 | 250 | | 2 | TABLE ACCESS FULL | ORDER_ITEMS | 1 | 250 | 250 | | 3 | TABLE ACCESS FULL | PRODUCT_INFO | 1 | 212 | 212 | ------------------------------------------------------------------------- Note: - statistics feedback used for this statement 170
  • 171.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. seems cool 171
  • 172.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. we mightta got carried away :-( 172
  • 173.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select 2 directive_id, 3 type, 4 reason 5 from DBA_SQL_PLAN_DIRECTIVES; DIRECTIVE_ID TYPE REASON ---------------------- ----------------------- ------------------------------------ 14774885086507357845 DYNAMIC_SAMPLING JOIN CARDINALITY MISESTIMATE 3814111798494124542 DYNAMIC_SAMPLING JOIN CARDINALITY MISESTIMATE 14157928931483804012 DYNAMIC_SAMPLING JOIN CARDINALITY MISESTIMATE 3273885094090423666 DYNAMIC_SAMPLING JOIN CARDINALITY MISESTIMATE 17607835686132426105 DYNAMIC_SAMPLING SINGLE TABLE CARDINALITY MISESTIMATE 28719982731298412 DYNAMIC_SAMPLING_RESULT SINGLE TABLE CARDINALITY MISESTIMATE 1591495495394657516 DYNAMIC_SAMPLING JOIN CARDINALITY MISESTIMATE 162577689324691883 DYNAMIC_SAMPLING JOIN CARDINALITY MISESTIMATE 13736133022354002565 DYNAMIC_SAMPLING JOIN CARDINALITY MISESTIMATE 7592221435558555884 DYNAMIC_SAMPLING SINGLE TABLE CARDINALITY MISESTIMATE ... ... 173
  • 174.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select ... 2 from order_iterms o, 3 product_info p 4 where o.sales_date > date '2017-01-01' 5 and o.product_id = p.product_id Note: - 3 Sql Plan Directives used for this statement 174
  • 175.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. same SQL ... 175
  • 176.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. ... different plans 176
  • 177.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. ... then more different plans 177
  • 178.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. ... then even more different plans 178
  • 179.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 179
  • 180.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. A common criticism .... 180
  • 181.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. upgrade to 12.1 181
  • 182.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. new optimizations 182
  • 183.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. new statistics 183
  • 184.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. default = everything enabled 184
  • 185.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 185
  • 186.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. "the plans keep changing" 186
  • 187.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. just one switch 187
  • 188.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 188
  • 189.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. options 189
  • 190.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. optimizer_adaptive_features = false 190
  • 191.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. optimizer_features_enable = 11.2.0.4 191
  • 192.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. don't panic ... that's fine endorsed 192
  • 193.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 12.1 ... perhaps too aggressive 193
  • 194.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 12.2 ... more control 194
  • 195.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 12.2 ... more passive 195
  • 196.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. TRUE FALSE 196
  • 197.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 12.2 ... much better 197
  • 198.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 12.1 patch 22652097 198
  • 199.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. which brings us to ... 199
  • 200.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. upgrade scenarios 200
  • 201.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. there are only two 201
  • 202.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 1) your system sucks :-) 202 upgrade to 12.2 explore full adaptive
  • 203.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 2) your system is OK 203 how can I lower risk ?
  • 204.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL Plan Baselines 204
  • 205.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. apology #1 205
  • 206.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 206
  • 207.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. but ultimately ... 207
  • 208.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. ... just three things 208
  • 209.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. try run stuff good 1 209
  • 210.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. when it's running good … 2 210
  • 211.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. … keep running it like that ! 211
  • 212.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. If there is something better 212 3
  • 213.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. then tell me 213
  • 214.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 214
  • 215.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 215
  • 216.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. baselines do exactly this ! 216
  • 217.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. rarely used 217
  • 218.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. apology #2 218 evolve accepted repeatable unaccepted capture signature
  • 219.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. close to our goals 219 working good ? Keep it found something better ? Tell me found something worse ? Don’t use it
  • 220.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. not new 220 11g
  • 221.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. (quick) terminology 221
  • 222.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. signature 222
  • 223.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> select sal from emp where empno = ... SQL> select SAL from EMP where EMPNO = ... SQL> SELECT /* comment */ SAL FROM EMP WHERE EMPNO = ... etc etc 223 signature
  • 224.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. plan(s) for signature 224
  • 225.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 225 SELECT A.DATA, B.DATA FROM TAB1 A, TAB2 WHERE B.TAB1_ID = A.ID AND A.CODE = :1 ----------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | ----------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | | 1 | NESTED LOOPS | | 25 | 425 | | 2 | NESTED LOOPS | | 25 | 425 | |* 3 | TABLE ACCESS FULL | TAB1 | 1 | 11 | |* 4 | INDEX RANGE SCAN | TAB2_TAB1_FKI | 25 | | | 5 | TABLE ACCESS BY INDEX ROWID| TAB2 | 25 | 150 | ----------------------------------------------------------------------- select a.data, b.data from tab1 a, tab2 where b.tab1_id = a.id and a.code = :1 "capture" a baseline
  • 226.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 226 SELECT A.DATA, B.DATA FROM TAB1 A, TAB2 WHERE B.TAB1_ID = A.ID AND A.CODE = :1 ----------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | ----------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | | 1 | NESTED LOOPS | | 25 | 425 | | 2 | NESTED LOOPS | | 25 | 425 | |* 3 | TABLE ACCESS FULL | TAB1 | 1 | 11 | |* 4 | INDEX RANGE SCAN | TAB2_TAB1_FKI | 25 | | | 5 | TABLE ACCESS BY INDEX ROWID| TAB2 | 25 | 150 | ----------------------------------------------------------------------- ------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | ------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | | | | * 1 | HASH JOIN | | 25 | 425 | | * 5 | TABLE ACCESS FULL | TAB1 | 1 | 11 | | 8 | TABLE ACCESS FULL | TAB2 | 25 | 150 | ------------------------------------------------------------------------ select a.data, b.data from tab1 a, tab2 where b.tab1_id = a.id and a.code = :1
  • 227.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. when it's running good … 227 … keep running it like that !
  • 228.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 228 SELECT A.DATA, B.DATA FROM TAB1 A, TAB2 WHERE B.TAB1_ID = A.ID AND A.CODE = :1 ----------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | ----------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | | 1 | NESTED LOOPS | | 25 | 425 | | 2 | NESTED LOOPS | | 25 | 425 | |* 3 | TABLE ACCESS FULL | TAB1 | 1 | 11 | |* 4 | INDEX RANGE SCAN | TAB2_TAB1_FKI | 25 | | | 5 | TABLE ACCESS BY INDEX ROWID| TAB2 | 25 | 150 | ----------------------------------------------------------------------- ------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | ------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | | | | * 1 | HASH JOIN | | 25 | 425 | | * 5 | TABLE ACCESS FULL | TAB1 | 1 | 11 | | 8 | TABLE ACCESS FULL | TAB2 | 25 | 150 | ------------------------------------------------------------------------ select a.data, b.data from tab1 a, tab2 where b.tab1_id = a.id and a.code = :1 but we saved this !
  • 229.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. maybe it is better ? 229 ------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | ------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | | | | * 1 | HASH JOIN | | 25 | 425 | | * 5 | TABLE ACCESS FULL | TAB1 | 1 | 11 | | 8 | TABLE ACCESS FULL | TAB2 | 25 | 150 | ------------------------------------------------------------------------
  • 230.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. evolve a plan 230
  • 231.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. DBMS_SPM.EVOLVE_SQL_PLAN_BASELINE 231
  • 232.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 232 SELECT A.DATA, B.DATA FROM TAB1 A, TAB2 WHERE B.TAB1_ID = A.ID AND A.CODE = :1 ----------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | ----------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | | 1 | NESTED LOOPS | | 25 | 425 | | 2 | NESTED LOOPS | | 25 | 425 | |* 3 | TABLE ACCESS FULL | TAB1 | 1 | 11 | |* 4 | INDEX RANGE SCAN | TAB2_TAB1_FKI | 25 | | | 5 | TABLE ACCESS BY INDEX ROWID| TAB2 | 25 | 150 | ----------------------------------------------------------------------- ------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | ------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | | | | * 1 | HASH JOIN | | 25 | 425 | | * 5 | TABLE ACCESS FULL | TAB1 | 1 | 11 | | 8 | TABLE ACCESS FULL | TAB2 | 25 | 150 | ------------------------------------------------------------------------ select a.data, b.data from tab1 a, tab2 where b.tab1_id = a.id and a.code = :1
  • 233.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. unless … 233 … that makes it bad or there's something better
  • 234.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. if only we had done ... 234 DBMS_SPM.I_LOVE_THIS_PLAN(sql_id) DBMS_SPM. THIS_PLAN_SUCKS(sql_id) DBMS_SPM. SWAP_THIS_PLAN_IN(sql_id)
  • 235.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. so back to upgrade 235
  • 236.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 2) your system is OK 236 how can I lower risk ?
  • 237.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> alter system set 2 optimizer_capture_sql_plan_baselines = true 237
  • 238.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SQL> exec DBMS_SPM.PACK_STGTAB_BASELINE (datapump) SQL> exec DBMS_SPM.UNPACK_STGTAB_BASELINE 238
  • 239.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. the same performance 239
  • 240.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 240
  • 241.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. wrap up 241
  • 242.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 12c optimizer is better 242
  • 243.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 12c optimizer is different 243
  • 244.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 12.2 preferred 244
  • 245.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. 12.1 ... backport 245
  • 246.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. SPM is your friend 246
  • 247.
    Copyright © 2017,Oracle and/or its affiliates. All rights reserved. That's a wrap! youtube bit.ly/youtube-connor blog bit.ly/blog-connor twitter bit.ly/twitter-connor 400+ posts mainly on database & development 250 technical videos, new uploads every week rants and raves on tech and the world :-)

Editor's Notes

  • #10 which of course means, we really should not be surprised when ask our customers about performance
  • #11 which of course means, we really should not be surprised when ask our customers about performance
  • #12 which of course means, we really should not be surprised when ask our customers about performance
  • #13 which of course means, we really should not be surprised when ask our customers about performance
  • #14 which of course means, we really should not be surprised when ask our customers about performance
  • #15 which of course means, we really should not be surprised when ask our customers about performance
  • #16 which of course means, we really should not be surprised when ask our customers about performance
  • #17 Where we all wish we were getting involved in the project … at the beginning
  • #18 which of course means, we really should not be surprised when ask our customers about performance
  • #19 which of course means, we really should not be surprised when ask our customers about performance
  • #20 which of course means, we really should not be surprised when ask our customers about performance
  • #21 which of course means, we really should not be surprised when ask our customers about performance
  • #22 that by the time we get involved, the users are already suffering.
  • #23 so when we ask them about performance
  • #24 we are not their best allies
  • #25 Which is great…but is unrealistic.
  • #26 which of course means, we really should not be surprised when ask our customers about performance
  • #27 which of course means, we really should not be surprised when ask our customers about performance
  • #28 which of course means, we really should not be surprised when ask our customers about performance
  • #29 which of course means, we really should not be surprised when ask our customers about performance
  • #30 So what I'm thinking is we would touch just very briefly on the stuff in 12c that makes hopefully for better plans straight off the bat, so things like histograms, global temporary table stats
  • #31 which of course means, we really should not be surprised when ask our customers about performance
  • #32 So what I'm thinking is we would touch just very briefly on the stuff in 12c that makes hopefully for better plans straight off the bat, so things like histograms, global temporary table stats
  • #83 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #84 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #85 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #86 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #87 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #88 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #89 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #90 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #91 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #92 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #94 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #96 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #97 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #98 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #99 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #100 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #101 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #102 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #103 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #104 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #105 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #106 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #107 Because garbage in = garbage out no matter how good your optimiser is
  • #109 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #110 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #111 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #112 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #113 which of course means, we really should not be surprised when ask our customers about performance
  • #114 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #115 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #123 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #125 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #128 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #130 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #131 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #133 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #135 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #138 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #139 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #140 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #143 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #145 which of course means, we really should not be surprised when ask our customers about performance
  • #150 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #152 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #153 And the second thing about running a statement well is that even with the best statistics we might still have to make some adjustments and it is best to make those adjustments midstream than waiting for the statement to finish and putting the customer through all of that pain and only then being able to make adjustments on subsequent executions
  • #154 And the second thing about running a statement well is that even with the best statistics we might still have to make some adjustments and it is best to make those adjustments midstream than waiting for the statement to finish and putting the customer through all of that pain and only then being able to make adjustments on subsequent executions
  • #155 And the second thing about running a statement well is that even with the best statistics we might still have to make some adjustments and it is best to make those adjustments midstream than waiting for the statement to finish and putting the customer through all of that pain and only then being able to make adjustments on subsequent executions
  • #156 Which is great…but is unrealistic.
  • #157 which of course means, we really should not be surprised when ask our customers about performance
  • #158 And the second thing about running a statement well is that even with the best statistics we might still have to make some adjustments and it is best to make those adjustments midstream than waiting for the statement to finish and putting the customer through all of that pain and only then being able to make adjustments on subsequent executions
  • #159 And the second thing about running a statement well is that even with the best statistics we might still have to make some adjustments and it is best to make those adjustments midstream than waiting for the statement to finish and putting the customer through all of that pain and only then being able to make adjustments on subsequent executions
  • #160 And the second thing about running a statement well is that even with the best statistics we might still have to make some adjustments and it is best to make those adjustments midstream than waiting for the statement to finish and putting the customer through all of that pain and only then being able to make adjustments on subsequent executions
  • #164 And the second thing about running a statement well is that even with the best statistics we might still have to make some adjustments and it is best to make those adjustments midstream than waiting for the statement to finish and putting the customer through all of that pain and only then being able to make adjustments on subsequent executions
  • #167 And the second thing about running a statement well is that even with the best statistics we might still have to make some adjustments and it is best to make those adjustments midstream than waiting for the statement to finish and putting the customer through all of that pain and only then being able to make adjustments on subsequent executions
  • #168 And the second thing about running a statement well is that even with the best statistics we might still have to make some adjustments and it is best to make those adjustments midstream than waiting for the statement to finish and putting the customer through all of that pain and only then being able to make adjustments on subsequent executions
  • #172 And the second thing about running a statement well is that even with the best statistics we might still have to make some adjustments and it is best to make those adjustments midstream than waiting for the statement to finish and putting the customer through all of that pain and only then being able to make adjustments on subsequent executions
  • #173 And the second thing about running a statement well is that even with the best statistics we might still have to make some adjustments and it is best to make those adjustments midstream than waiting for the statement to finish and putting the customer through all of that pain and only then being able to make adjustments on subsequent executions
  • #176 And the second thing about running a statement well is that even with the best statistics we might still have to make some adjustments and it is best to make those adjustments midstream than waiting for the statement to finish and putting the customer through all of that pain and only then being able to make adjustments on subsequent executions
  • #177 And the second thing about running a statement well is that even with the best statistics we might still have to make some adjustments and it is best to make those adjustments midstream than waiting for the statement to finish and putting the customer through all of that pain and only then being able to make adjustments on subsequent executions
  • #178 And the second thing about running a statement well is that even with the best statistics we might still have to make some adjustments and it is best to make those adjustments midstream than waiting for the statement to finish and putting the customer through all of that pain and only then being able to make adjustments on subsequent executions
  • #179 And the second thing about running a statement well is that even with the best statistics we might still have to make some adjustments and it is best to make those adjustments midstream than waiting for the statement to finish and putting the customer through all of that pain and only then being able to make adjustments on subsequent executions
  • #180 So what happens when either the user hates us ? or gives us unachieveable goals ?
  • #181 So what happens when either the user hates us ? or gives us unachieveable goals ?
  • #182 So what happens when either the user hates us ? or gives us unachieveable goals ?
  • #183 So what happens when either the user hates us ? or gives us unachieveable goals ?
  • #184 So what happens when either the user hates us ? or gives us unachieveable goals ?
  • #185 So what happens when either the user hates us ? or gives us unachieveable goals ?
  • #188 So what happens when either the user hates us ? or gives us unachieveable goals ?
  • #190 So what happens when either the user hates us ? or gives us unachieveable goals ?
  • #193 So what happens when either the user hates us ? or gives us unachieveable goals ?
  • #194 So what happens when either the user hates us ? or gives us unachieveable goals ?
  • #195 So what happens when either the user hates us ? or gives us unachieveable goals ?
  • #196 So what happens when either the user hates us ? or gives us unachieveable goals ?
  • #198 So what happens when either the user hates us ? or gives us unachieveable goals ?
  • #199 So what happens when either the user hates us ? or gives us unachieveable goals ?
  • #200 But ultimately….from the optimizer we really want some simple things
  • #201 But ultimately….from the optimizer we really want some simple things
  • #202 But ultimately….from the optimizer we really want some simple things
  • #203 But ultimately….from the optimizer we really want some simple things
  • #204 But ultimately….from the optimizer we really want some simple things
  • #205 But ultimately….from the optimizer we really want some simple things
  • #206 So what happens when either the user hates us ? or gives us unachieveable goals ?
  • #207 We will concede that over a number a releases, we've introduced, enhanced, re-thought a LOT of things with regard to the optimizer.. … which can make things feel a little overwhelming.
  • #208 But ultimately….from the optimizer we really want some simple things
  • #209 But ultimately….from the optimizer we really want some simple things
  • #210 1) run my SQL as good as it can be run … or at least TRY to
  • #211 2) and when you've got it running good…
  • #212 for god sakes, don't change anything. Just keep running it good… all the time, exactly like it is today….
  • #213 "….but … I don’t want to look like a fool, so if you DO find something better…."
  • #214 then please tell me…
  • #215 BUT DON"T TOUCH ANYTHIING. Let *me* decide if this is a good switch to make.
  • #216 We will concede that over a number a releases, we've introduced, enhanced, re-thought a LOT of things with regard to the optimizer.. … which can make things feel a little overwhelming.
  • #217 then please tell me…
  • #218 So when it comes to running stuff well, the two elements we would focus on are - better statistics so the chances of getting a good plan are better - and a recognition that no matter how good the statistics are there will always be challenges for the optimizer so it needs the ability to change course mid-stride
  • #219 So what happens when either the user hates us ? or gives us unachieveable goals ?
  • #220 So when it comes to running stuff well, the two elements we would focus on are - better statistics so the chances of getting a good plan are better - and a recognition that no matter how good the statistics are there will always be challenges for the optimizer so it needs the ability to change course mid-stride
  • #221 So when it comes to running stuff well, the two elements we would focus on are - better statistics so the chances of getting a good plan are better - and a recognition that no matter how good the statistics are there will always be challenges for the optimizer so it needs the ability to change course mid-stride
  • #222 So when it comes to running stuff well, the two elements we would focus on are - better statistics so the chances of getting a good plan are better - and a recognition that no matter how good the statistics are there will always be challenges for the optimizer so it needs the ability to change course mid-stride
  • #223 So when it comes to running stuff well, the two elements we would focus on are - better statistics so the chances of getting a good plan are better - and a recognition that no matter how good the statistics are there will always be challenges for the optimizer so it needs the ability to change course mid-stride
  • #225 So when it comes to running stuff well, the two elements we would focus on are - better statistics so the chances of getting a good plan are better - and a recognition that no matter how good the statistics are there will always be challenges for the optimizer so it needs the ability to change course mid-stride
  • #226 These are just some slides I ripped out of existing decks, obviously they would be cleaned up and formatted as we see fit but really just to touch on some of the things in 12c whether it be release 1 or release 2
  • #227 These are just some slides I ripped out of existing decks, obviously they would be cleaned up and formatted as we see fit but really just to touch on some of the things in 12c whether it be release 1 or release 2
  • #228 2) and when you've got it running good…
  • #229 These are just some slides I ripped out of existing decks, obviously they would be cleaned up and formatted as we see fit but really just to touch on some of the things in 12c whether it be release 1 or release 2
  • #230 for god sakes, don't change anything. Just keep running it good… all the time, exactly like it is today….
  • #231 for god sakes, don't change anything. Just keep running it good… all the time, exactly like it is today….
  • #233 These are just some slides I ripped out of existing decks, obviously they would be cleaned up and formatted as we see fit but really just to touch on some of the things in 12c whether it be release 1 or release 2
  • #234 and 3…. which is always the kicker … unless of course
  • #235 So when it comes to running stuff well, the two elements we would focus on are - better statistics so the chances of getting a good plan are better - and a recognition that no matter how good the statistics are there will always be challenges for the optimizer so it needs the ability to change course mid-stride
  • #236 And the second thing about running a statement well is that even with the best statistics we might still have to make some adjustments and it is best to make those adjustments midstream than waiting for the statement to finish and putting the customer through all of that pain and only then being able to make adjustments on subsequent executions
  • #237 But ultimately….from the optimizer we really want some simple things
  • #240 And the second thing about running a statement well is that even with the best statistics we might still have to make some adjustments and it is best to make those adjustments midstream than waiting for the statement to finish and putting the customer through all of that pain and only then being able to make adjustments on subsequent executions
  • #241 which of course means, we really should not be surprised when ask our customers about performance
  • #242 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #243 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #244 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #245 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #246 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  • #247 So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!