SlideShare a Scribd company logo
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 :-)

More Related Content

What's hot

Kscope19 - Flashback: Good for Developers as well as DBAs
Kscope19 - Flashback: Good for Developers as well as DBAsKscope19 - Flashback: Good for Developers as well as DBAs
Kscope19 - Flashback: Good for Developers as well as DBAs
Connor McDonald
 
18(ish) Things You'll Love About Oracle Database 18c
18(ish) Things You'll Love About Oracle Database 18c18(ish) Things You'll Love About Oracle Database 18c
18(ish) Things You'll Love About Oracle Database 18c
Chris Saxon
 
KScope19 - SQL Features
KScope19 - SQL FeaturesKScope19 - SQL Features
KScope19 - SQL Features
Connor McDonald
 
Latin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matchingLatin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matching
Connor McDonald
 
APEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQLAPEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQL
Connor McDonald
 
Latin America Tour 2019 - slow data and sql processing
Latin America Tour 2019  - slow data and sql processingLatin America Tour 2019  - slow data and sql processing
Latin America Tour 2019 - slow data and sql processing
Connor McDonald
 
Sangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesSangam 2019 - The Latest Features
Sangam 2019 - The Latest Features
Connor McDonald
 
Agile Database Development with JSON
Agile Database Development with JSONAgile Database Development with JSON
Agile Database Development with JSON
Chris Saxon
 
Cool SQL Features
Cool SQL FeaturesCool SQL Features
Cool SQL Features
Connor McDonald
 
Using Optimizer Hints to Improve MySQL Query Performance
Using Optimizer Hints to Improve MySQL Query PerformanceUsing Optimizer Hints to Improve MySQL Query Performance
Using Optimizer Hints to Improve MySQL Query Performance
oysteing
 
Polymorphic Table Functions in SQL
Polymorphic Table Functions in SQLPolymorphic Table Functions in SQL
Polymorphic Table Functions in SQL
Chris Saxon
 
Sangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolestSangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolest
Connor McDonald
 
Wellington APAC Groundbreakers tour - SQL Pattern Matching
Wellington APAC Groundbreakers tour - SQL Pattern MatchingWellington APAC Groundbreakers tour - SQL Pattern Matching
Wellington APAC Groundbreakers tour - SQL Pattern Matching
Connor McDonald
 
Oracle b tree index internals - rebuilding the thruth
Oracle b tree index internals - rebuilding the thruthOracle b tree index internals - rebuilding the thruth
Oracle b tree index internals - rebuilding the thruthXavier Davias
 
pstack, truss etc to understand deeper issues in Oracle database
pstack, truss etc to understand deeper issues in Oracle databasepstack, truss etc to understand deeper issues in Oracle database
pstack, truss etc to understand deeper issues in Oracle database
Riyaj Shamsudeen
 
Ineffective and Effective Ways To Find Out Latency Bottlenecks With Ftrace
Ineffective and Effective Ways To Find Out Latency Bottlenecks With FtraceIneffective and Effective Ways To Find Out Latency Bottlenecks With Ftrace
Ineffective and Effective Ways To Find Out Latency Bottlenecks With Ftrace
Yoshitake Kobayashi
 
Pebank java handsout
Pebank java handsoutPebank java handsout
Pebank java handsout
PE-BANK
 
Php forum2015 tomas_final
Php forum2015 tomas_finalPhp forum2015 tomas_final
Php forum2015 tomas_final
Bertrand Matthelie
 
Who's afraid of ML -V2- Hello MLKit
Who's afraid of ML -V2- Hello MLKitWho's afraid of ML -V2- Hello MLKit
Who's afraid of ML -V2- Hello MLKit
Britt Barak (HIRING)
 

What's hot (19)

Kscope19 - Flashback: Good for Developers as well as DBAs
Kscope19 - Flashback: Good for Developers as well as DBAsKscope19 - Flashback: Good for Developers as well as DBAs
Kscope19 - Flashback: Good for Developers as well as DBAs
 
18(ish) Things You'll Love About Oracle Database 18c
18(ish) Things You'll Love About Oracle Database 18c18(ish) Things You'll Love About Oracle Database 18c
18(ish) Things You'll Love About Oracle Database 18c
 
KScope19 - SQL Features
KScope19 - SQL FeaturesKScope19 - SQL Features
KScope19 - SQL Features
 
Latin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matchingLatin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matching
 
APEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQLAPEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQL
 
Latin America Tour 2019 - slow data and sql processing
Latin America Tour 2019  - slow data and sql processingLatin America Tour 2019  - slow data and sql processing
Latin America Tour 2019 - slow data and sql processing
 
Sangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesSangam 2019 - The Latest Features
Sangam 2019 - The Latest Features
 
Agile Database Development with JSON
Agile Database Development with JSONAgile Database Development with JSON
Agile Database Development with JSON
 
Cool SQL Features
Cool SQL FeaturesCool SQL Features
Cool SQL Features
 
Using Optimizer Hints to Improve MySQL Query Performance
Using Optimizer Hints to Improve MySQL Query PerformanceUsing Optimizer Hints to Improve MySQL Query Performance
Using Optimizer Hints to Improve MySQL Query Performance
 
Polymorphic Table Functions in SQL
Polymorphic Table Functions in SQLPolymorphic Table Functions in SQL
Polymorphic Table Functions in SQL
 
Sangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolestSangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolest
 
Wellington APAC Groundbreakers tour - SQL Pattern Matching
Wellington APAC Groundbreakers tour - SQL Pattern MatchingWellington APAC Groundbreakers tour - SQL Pattern Matching
Wellington APAC Groundbreakers tour - SQL Pattern Matching
 
Oracle b tree index internals - rebuilding the thruth
Oracle b tree index internals - rebuilding the thruthOracle b tree index internals - rebuilding the thruth
Oracle b tree index internals - rebuilding the thruth
 
pstack, truss etc to understand deeper issues in Oracle database
pstack, truss etc to understand deeper issues in Oracle databasepstack, truss etc to understand deeper issues in Oracle database
pstack, truss etc to understand deeper issues in Oracle database
 
Ineffective and Effective Ways To Find Out Latency Bottlenecks With Ftrace
Ineffective and Effective Ways To Find Out Latency Bottlenecks With FtraceIneffective and Effective Ways To Find Out Latency Bottlenecks With Ftrace
Ineffective and Effective Ways To Find Out Latency Bottlenecks With Ftrace
 
Pebank java handsout
Pebank java handsoutPebank java handsout
Pebank java handsout
 
Php forum2015 tomas_final
Php forum2015 tomas_finalPhp forum2015 tomas_final
Php forum2015 tomas_final
 
Who's afraid of ML -V2- Hello MLKit
Who's afraid of ML -V2- Hello MLKitWho's afraid of ML -V2- Hello MLKit
Who's afraid of ML -V2- Hello MLKit
 

Similar to Wellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer

Melbourne Groundbreakers Tour - Upgrading without risk
Melbourne Groundbreakers Tour - Upgrading without riskMelbourne Groundbreakers Tour - Upgrading without risk
Melbourne Groundbreakers Tour - Upgrading without risk
Connor McDonald
 
Sangam 18 - The New Optimizer in Oracle 12c
Sangam 18 - The New Optimizer in Oracle 12cSangam 18 - The New Optimizer in Oracle 12c
Sangam 18 - The New Optimizer in Oracle 12c
Connor McDonald
 
OpenWorld 2018 - SQL Tuning in 20 mins
OpenWorld 2018 - SQL Tuning in 20 minsOpenWorld 2018 - SQL Tuning in 20 mins
OpenWorld 2018 - SQL Tuning in 20 mins
Connor McDonald
 
OG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizerOG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizer
Connor McDonald
 
18c and 19c features for DBAs
18c and 19c features for DBAs18c and 19c features for DBAs
18c and 19c features for DBAs
Connor McDonald
 
Melbourne Groundbreakers Tour - Hints and Tips
Melbourne Groundbreakers Tour - Hints and TipsMelbourne Groundbreakers Tour - Hints and Tips
Melbourne Groundbreakers Tour - Hints and Tips
Connor McDonald
 
Latin America Tour 2019 - 18c and 19c featues
Latin America Tour 2019   - 18c and 19c featuesLatin America Tour 2019   - 18c and 19c featues
Latin America Tour 2019 - 18c and 19c featues
Connor McDonald
 
Hyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19cHyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19c
Connor McDonald
 
APEX Connect 2019 - successful application development
APEX Connect 2019 - successful application developmentAPEX Connect 2019 - successful application development
APEX Connect 2019 - successful application development
Connor McDonald
 
Perth APAC Groundbreakers tour - 18c features
Perth APAC Groundbreakers tour - 18c featuresPerth APAC Groundbreakers tour - 18c features
Perth APAC Groundbreakers tour - 18c features
Connor McDonald
 
Pattern Matching with SQL - APEX World Rotterdam 2019
Pattern Matching with SQL - APEX World Rotterdam 2019Pattern Matching with SQL - APEX World Rotterdam 2019
Pattern Matching with SQL - APEX World Rotterdam 2019
Connor McDonald
 
Histogram Support in MySQL 8.0
Histogram Support in MySQL 8.0Histogram Support in MySQL 8.0
Histogram Support in MySQL 8.0
oysteing
 
Perth APAC Groundbreakers tour - The Autonomous Database
Perth APAC Groundbreakers tour - The Autonomous DatabasePerth APAC Groundbreakers tour - The Autonomous Database
Perth APAC Groundbreakers tour - The Autonomous Database
Connor McDonald
 
Five more things about Oracle SQL and PLSQL
Five more things about Oracle SQL and PLSQLFive more things about Oracle SQL and PLSQL
Five more things about Oracle SQL and PLSQL
Connor McDonald
 
How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0
Norvald Ryeng
 
Mysql Performance Schema - fossasia 2016
Mysql Performance Schema - fossasia 2016Mysql Performance Schema - fossasia 2016
Mysql Performance Schema - fossasia 2016
Mayank Prasad
 
5 Cool Things About SQL
5 Cool Things About SQL5 Cool Things About SQL
5 Cool Things About SQL
Connor McDonald
 
2019 indit blackhat_honeypot your database server
2019 indit blackhat_honeypot your database server2019 indit blackhat_honeypot your database server
2019 indit blackhat_honeypot your database server
Georgi Kodinov
 
MySQL innodb cluster and Group Replication in a nutshell - hands-on tutorial ...
MySQL innodb cluster and Group Replication in a nutshell - hands-on tutorial ...MySQL innodb cluster and Group Replication in a nutshell - hands-on tutorial ...
MySQL innodb cluster and Group Replication in a nutshell - hands-on tutorial ...
Frederic Descamps
 
Oracle Database features every developer should know about
Oracle Database features every developer should know aboutOracle Database features every developer should know about
Oracle Database features every developer should know about
gvenzl
 

Similar to Wellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer (20)

Melbourne Groundbreakers Tour - Upgrading without risk
Melbourne Groundbreakers Tour - Upgrading without riskMelbourne Groundbreakers Tour - Upgrading without risk
Melbourne Groundbreakers Tour - Upgrading without risk
 
Sangam 18 - The New Optimizer in Oracle 12c
Sangam 18 - The New Optimizer in Oracle 12cSangam 18 - The New Optimizer in Oracle 12c
Sangam 18 - The New Optimizer in Oracle 12c
 
OpenWorld 2018 - SQL Tuning in 20 mins
OpenWorld 2018 - SQL Tuning in 20 minsOpenWorld 2018 - SQL Tuning in 20 mins
OpenWorld 2018 - SQL Tuning in 20 mins
 
OG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizerOG Yatra - upgrading to the new 12c+ optimizer
OG Yatra - upgrading to the new 12c+ optimizer
 
18c and 19c features for DBAs
18c and 19c features for DBAs18c and 19c features for DBAs
18c and 19c features for DBAs
 
Melbourne Groundbreakers Tour - Hints and Tips
Melbourne Groundbreakers Tour - Hints and TipsMelbourne Groundbreakers Tour - Hints and Tips
Melbourne Groundbreakers Tour - Hints and Tips
 
Latin America Tour 2019 - 18c and 19c featues
Latin America Tour 2019   - 18c and 19c featuesLatin America Tour 2019   - 18c and 19c featues
Latin America Tour 2019 - 18c and 19c featues
 
Hyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19cHyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19c
 
APEX Connect 2019 - successful application development
APEX Connect 2019 - successful application developmentAPEX Connect 2019 - successful application development
APEX Connect 2019 - successful application development
 
Perth APAC Groundbreakers tour - 18c features
Perth APAC Groundbreakers tour - 18c featuresPerth APAC Groundbreakers tour - 18c features
Perth APAC Groundbreakers tour - 18c features
 
Pattern Matching with SQL - APEX World Rotterdam 2019
Pattern Matching with SQL - APEX World Rotterdam 2019Pattern Matching with SQL - APEX World Rotterdam 2019
Pattern Matching with SQL - APEX World Rotterdam 2019
 
Histogram Support in MySQL 8.0
Histogram Support in MySQL 8.0Histogram Support in MySQL 8.0
Histogram Support in MySQL 8.0
 
Perth APAC Groundbreakers tour - The Autonomous Database
Perth APAC Groundbreakers tour - The Autonomous DatabasePerth APAC Groundbreakers tour - The Autonomous Database
Perth APAC Groundbreakers tour - The Autonomous Database
 
Five more things about Oracle SQL and PLSQL
Five more things about Oracle SQL and PLSQLFive more things about Oracle SQL and PLSQL
Five more things about Oracle SQL and PLSQL
 
How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0
 
Mysql Performance Schema - fossasia 2016
Mysql Performance Schema - fossasia 2016Mysql Performance Schema - fossasia 2016
Mysql Performance Schema - fossasia 2016
 
5 Cool Things About SQL
5 Cool Things About SQL5 Cool Things About SQL
5 Cool Things About SQL
 
2019 indit blackhat_honeypot your database server
2019 indit blackhat_honeypot your database server2019 indit blackhat_honeypot your database server
2019 indit blackhat_honeypot your database server
 
MySQL innodb cluster and Group Replication in a nutshell - hands-on tutorial ...
MySQL innodb cluster and Group Replication in a nutshell - hands-on tutorial ...MySQL innodb cluster and Group Replication in a nutshell - hands-on tutorial ...
MySQL innodb cluster and Group Replication in a nutshell - hands-on tutorial ...
 
Oracle Database features every developer should know about
Oracle Database features every developer should know aboutOracle Database features every developer should know about
Oracle Database features every developer should know about
 

More from Connor McDonald

Flashback ITOUG
Flashback ITOUGFlashback ITOUG
Flashback ITOUG
Connor McDonald
 
Sangam 19 - Analytic SQL
Sangam 19 - Analytic SQLSangam 19 - Analytic SQL
Sangam 19 - Analytic SQL
Connor McDonald
 
UKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tipsUKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tips
Connor McDonald
 
Sangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on AutonomousSangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on Autonomous
Connor McDonald
 
UKOUG 2019 - SQL features
UKOUG 2019 - SQL featuresUKOUG 2019 - SQL features
UKOUG 2019 - SQL features
Connor McDonald
 
APEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomousAPEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomous
Connor McDonald
 
APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne
Connor McDonald
 
OOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAsOOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAs
Connor McDonald
 
OOW19 - Read consistency
OOW19 - Read consistencyOOW19 - Read consistency
OOW19 - Read consistency
Connor McDonald
 
OOW19 - Slower and less secure applications
OOW19 - Slower and less secure applicationsOOW19 - Slower and less secure applications
OOW19 - Slower and less secure applications
Connor McDonald
 
OOW19 - Killing database sessions
OOW19 - Killing database sessionsOOW19 - Killing database sessions
OOW19 - Killing database sessions
Connor McDonald
 
OOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL featuresOOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL features
Connor McDonald
 
Latin America tour 2019 - Flashback
Latin America tour 2019 -  FlashbackLatin America tour 2019 -  Flashback
Latin America tour 2019 - Flashback
Connor McDonald
 
Latin America Tour 2019 - 10 great sql features
Latin America Tour 2019  - 10 great sql featuresLatin America Tour 2019  - 10 great sql features
Latin America Tour 2019 - 10 great sql features
Connor McDonald
 
ANSI vs Oracle language
ANSI vs Oracle languageANSI vs Oracle language
ANSI vs Oracle language
Connor McDonald
 
OG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tipsOG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tips
Connor McDonald
 
OG Yatra - Flashback, not just for developers
OG Yatra - Flashback, not just for developersOG Yatra - Flashback, not just for developers
OG Yatra - Flashback, not just for developers
Connor McDonald
 
Kscope19 - Understanding the basics of SQL processing
Kscope19 - Understanding the basics of SQL processingKscope19 - Understanding the basics of SQL processing
Kscope19 - Understanding the basics of SQL processing
Connor McDonald
 

More from Connor McDonald (18)

Flashback ITOUG
Flashback ITOUGFlashback ITOUG
Flashback ITOUG
 
Sangam 19 - Analytic SQL
Sangam 19 - Analytic SQLSangam 19 - Analytic SQL
Sangam 19 - Analytic SQL
 
UKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tipsUKOUG - 25 years of hints and tips
UKOUG - 25 years of hints and tips
 
Sangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on AutonomousSangam 19 - Successful Applications on Autonomous
Sangam 19 - Successful Applications on Autonomous
 
UKOUG 2019 - SQL features
UKOUG 2019 - SQL featuresUKOUG 2019 - SQL features
UKOUG 2019 - SQL features
 
APEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomousAPEX tour 2019 - successful development with autonomous
APEX tour 2019 - successful development with autonomous
 
APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne APAC Groundbreakers 2019 - Perth/Melbourne
APAC Groundbreakers 2019 - Perth/Melbourne
 
OOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAsOOW19 - Flashback, not just for DBAs
OOW19 - Flashback, not just for DBAs
 
OOW19 - Read consistency
OOW19 - Read consistencyOOW19 - Read consistency
OOW19 - Read consistency
 
OOW19 - Slower and less secure applications
OOW19 - Slower and less secure applicationsOOW19 - Slower and less secure applications
OOW19 - Slower and less secure applications
 
OOW19 - Killing database sessions
OOW19 - Killing database sessionsOOW19 - Killing database sessions
OOW19 - Killing database sessions
 
OOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL featuresOOW19 - Ten Amazing SQL features
OOW19 - Ten Amazing SQL features
 
Latin America tour 2019 - Flashback
Latin America tour 2019 -  FlashbackLatin America tour 2019 -  Flashback
Latin America tour 2019 - Flashback
 
Latin America Tour 2019 - 10 great sql features
Latin America Tour 2019  - 10 great sql featuresLatin America Tour 2019  - 10 great sql features
Latin America Tour 2019 - 10 great sql features
 
ANSI vs Oracle language
ANSI vs Oracle languageANSI vs Oracle language
ANSI vs Oracle language
 
OG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tipsOG Yatra - 25 years of hints and tips
OG Yatra - 25 years of hints and tips
 
OG Yatra - Flashback, not just for developers
OG Yatra - Flashback, not just for developersOG Yatra - Flashback, not just for developers
OG Yatra - Flashback, not just for developers
 
Kscope19 - Understanding the basics of SQL processing
Kscope19 - Understanding the basics of SQL processingKscope19 - Understanding the basics of SQL processing
Kscope19 - Understanding the basics of SQL processing
 

Recently uploaded

Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 

Recently uploaded (20)

Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 

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

  1. which of course means, we really should not be surprised when ask our customers about performance
  2. which of course means, we really should not be surprised when ask our customers about performance
  3. which of course means, we really should not be surprised when ask our customers about performance
  4. which of course means, we really should not be surprised when ask our customers about performance
  5. which of course means, we really should not be surprised when ask our customers about performance
  6. which of course means, we really should not be surprised when ask our customers about performance
  7. which of course means, we really should not be surprised when ask our customers about performance
  8. Where we all wish we were getting involved in the project … at the beginning
  9. which of course means, we really should not be surprised when ask our customers about performance
  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. that by the time we get involved, the users are already suffering.
  14. so when we ask them about performance
  15. we are not their best allies
  16. Which is great…but is unrealistic.
  17. which of course means, we really should not be surprised when ask our customers about performance
  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. 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
  22. which of course means, we really should not be surprised when ask our customers about performance
  23. 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
  24. 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 !!!
  25. 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 !!!
  26. 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 !!!
  27. 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 !!!
  28. 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 !!!
  29. 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 !!!
  30. 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 !!!
  31. 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 !!!
  32. 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 !!!
  33. 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 !!!
  34. 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 !!!
  35. 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 !!!
  36. 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 !!!
  37. 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 !!!
  38. 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 !!!
  39. 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 !!!
  40. 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 !!!
  41. 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 !!!
  42. 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 !!!
  43. 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 !!!
  44. 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 !!!
  45. 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 !!!
  46. Because garbage in = garbage out no matter how good your optimiser is
  47. 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 !!!
  48. 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 !!!
  49. 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 !!!
  50. 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 !!!
  51. which of course means, we really should not be surprised when ask our customers about performance
  52. 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 !!!
  53. 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 !!!
  54. 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 !!!
  55. 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 !!!
  56. 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 !!!
  57. 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 !!!
  58. 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 !!!
  59. 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 !!!
  60. 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 !!!
  61. 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 !!!
  62. 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 !!!
  63. 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 !!!
  64. 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 !!!
  65. which of course means, we really should not be surprised when ask our customers about performance
  66. 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 !!!
  67. 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 !!!
  68. 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
  69. 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
  70. 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
  71. Which is great…but is unrealistic.
  72. which of course means, we really should not be surprised when ask our customers about performance
  73. 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
  74. 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
  75. 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
  76. 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
  77. 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
  78. 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
  79. 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
  80. 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
  81. 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
  82. 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
  83. 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
  84. 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
  85. So what happens when either the user hates us ? or gives us unachieveable goals ?
  86. So what happens when either the user hates us ? or gives us unachieveable goals ?
  87. So what happens when either the user hates us ? or gives us unachieveable goals ?
  88. So what happens when either the user hates us ? or gives us unachieveable goals ?
  89. So what happens when either the user hates us ? or gives us unachieveable goals ?
  90. So what happens when either the user hates us ? or gives us unachieveable goals ?
  91. So what happens when either the user hates us ? or gives us unachieveable goals ?
  92. So what happens when either the user hates us ? or gives us unachieveable goals ?
  93. So what happens when either the user hates us ? or gives us unachieveable goals ?
  94. So what happens when either the user hates us ? or gives us unachieveable goals ?
  95. So what happens when either the user hates us ? or gives us unachieveable goals ?
  96. So what happens when either the user hates us ? or gives us unachieveable goals ?
  97. So what happens when either the user hates us ? or gives us unachieveable goals ?
  98. So what happens when either the user hates us ? or gives us unachieveable goals ?
  99. But ultimately….from the optimizer we really want some simple things
  100. But ultimately….from the optimizer we really want some simple things
  101. But ultimately….from the optimizer we really want some simple things
  102. But ultimately….from the optimizer we really want some simple things
  103. But ultimately….from the optimizer we really want some simple things
  104. But ultimately….from the optimizer we really want some simple things
  105. So what happens when either the user hates us ? or gives us unachieveable goals ?
  106. 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.
  107. But ultimately….from the optimizer we really want some simple things
  108. But ultimately….from the optimizer we really want some simple things
  109. 1) run my SQL as good as it can be run … or at least TRY to
  110. 2) and when you've got it running good…
  111. for god sakes, don't change anything. Just keep running it good… all the time, exactly like it is today….
  112. "….but … I don’t want to look like a fool, so if you DO find something better…."
  113. then please tell me…
  114. BUT DON"T TOUCH ANYTHIING. Let *me* decide if this is a good switch to make.
  115. 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.
  116. then please tell me…
  117. 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
  118. So what happens when either the user hates us ? or gives us unachieveable goals ?
  119. 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
  120. 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
  121. 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
  122. 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
  123. 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
  124. 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
  125. 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
  126. 2) and when you've got it running good…
  127. 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
  128. for god sakes, don't change anything. Just keep running it good… all the time, exactly like it is today….
  129. for god sakes, don't change anything. Just keep running it good… all the time, exactly like it is today….
  130. 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
  131. and 3…. which is always the kicker … unless of course
  132. 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
  133. 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
  134. But ultimately….from the optimizer we really want some simple things
  135. 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
  136. which of course means, we really should not be surprised when ask our customers about performance
  137. 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 !!!
  141. 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 !!!
  142. 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 !!!