SlideShare uma empresa Scribd logo
1 de 255
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.
21
You will upgrade us to 12c
with its new optimizer
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
LOL !LOL !
22
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
LMAOLMAO!
23
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
That dude
is toast!
That dude
is toast!
24
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Is this why I don't
have a desk ?
25
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
lots of fear
26
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
lots of mis-information
27
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
only 2 issues
28
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
ISSUE #1
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.
cardinality mis-estimates
31
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
cardinality is everything
32
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
33
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
better stats
34
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
missing or poor statistics
35
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
1) better histograms
36
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
2015
37
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
38
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
39
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Histograms are so
awesome. See
how much they
make me smile !
40
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
41
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
No …
… honest :-)
42
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
the sucky part
43
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.
44
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 45
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
46
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
47
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
48
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
49
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
we don't know what your "app" is
50
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
still requires care
51
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
12c improvements
52
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
53
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
skewed ...
54
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
... need histogram
55
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
11g
56
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
57
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
58
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
59
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
60
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')
61
true = 800
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
so far … so good
62
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
NDV > 254*
63
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
64
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
65
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
1-New
6-Received
7-Complete
8-Archived
8-Archived
8-Archived
7-Complete
66
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
67
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
68
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
69
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 70
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 71
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
72
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
height balanced means ...
73
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
bucket spanning = dramas
74
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
bucket swallowing = dramas
75
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
11g
HEIGHT-BALANCED
FREQUENCY
76
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Footnote: 11g
FOR ALL COLUMNS SIZE 25AUTO
77
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
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 15');
4 end;
5 /
PL/SQL procedure successfully completed.
SQL> select histogram from USER_TAB_COL_STATISTICS
2 where table_name = 'ORDERS';
HISTOGRAM
---------------
FREQUENCY
79
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
80
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 81
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
1-New
6-Received
3-InProgress
5-Shipped
8-Archived
7-Completed
82
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
other values ?
83
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 ) =
84
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')
85
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
86
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
what if TOP FREQ not possible ?
87
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;
88
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
89
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
90
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 91
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
92
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"
93
6-Received
554
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
no bucket spanning
94
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
key point
95
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
must use auto sample size
96
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
still need care
97
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
representative values
98
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
"today's hot deals"
99
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
100
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
101
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 ...
102
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
where type = 'HOT_DEAL'
103
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
104
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
105
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
normally...
106
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!"
107
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!"
108
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
109
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
representative values
... at the right time
110
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
2) extensions
111
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
11g
112
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
"extended" statistics
113
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
aka "column groups"
114
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
solve GIGO
115
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL> select *
2 from ADDRESS
3 where CITY = 'Bangalore'
4 and COUNTRY = 'Australia';
116
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
117
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
automatic column groups
118
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
12.2
119
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
expression tracking
120
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
121
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
missing or poor statistics
122
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
3) online gather
123
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
the old problem
124
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;
125
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
126
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
127
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
128
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
129
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
130
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
131
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
and then...
132
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
----------
133
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
so ...
134
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
135
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
136
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
on load
137
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 138
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
things to note
139
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
must be direct
insert /*+ APPEND */
create table as select
140
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
----------
141
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
must be empty
142
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
----------
143
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
execution plan
144
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)|
------------------------------------------------------------------------------
145
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
...
...
146
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
note: no histograms
147
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
3) session GTT
148
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
11g
149
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.
150
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)|
---------------------------------------------------------------
151
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
looks great until ...
152
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)|
---------------------------------------------------------------
153
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
154
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.
155
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
156
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');
157
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
158
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
back to session 1
159
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)|
---------------------------------------------------------------
160
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
note: default = private
161
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
so far ...
162
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
missing or poor statistics
163
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
improved optimizer "inputs"
histograms
gather on load
private GTT
164
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
ISSUE #2
165
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
statistics needed = "∞"
166
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
learn ... as we go
167
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
learn ... from experiences
168
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Adaptive Query Optimization #1
169
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"
170
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 |
-----------------------------------------------------------------
171
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
172
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 ?
173
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)|
--------------------------------------------------------------------------
174
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>
175
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
cool
176
"dodged a bullet"
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Adaptive Query Optimization #2
177
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 |
-------------------------------------------------------------------------
178
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>
179
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
180
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
seems cool
181
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
we mightta got carried away :-(
182
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
...
...
183
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
184
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
same SQL ...
185
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
... different plans
186
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
... then more different plans
187
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
... then even more different plans
188
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
So ... this happens
189
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
upgrade to 12.1
190
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
new optimizations
191
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
new statistics
192
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
default = everything enabled
193
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
"the plans keep changing"
194
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
just one switch
195
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
196
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
options
197
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
optimizer_adaptive_features = false
198
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
optimizer_features_enable = 11.2.0.4
199
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
don't panic ... that's fine
endorsed
200
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
12.1 ... perhaps too aggressive
201
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
12.2 ... more control
202
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
12.2 ... more passive
203
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
TRUE FALSE 204
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
12.2 ... much better
205
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
12.1
patch 22652097
206
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
which brings us to ...
207
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
upgrade scenarios
208
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
there are only two
209
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
1) your system sucks :-)
210
upgrade to 12.2
explore full adaptive
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
2) your system is OK
211
how can I lower risk ?
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SQL Plan Baselines
212
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
apology #1
213
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
214
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
but ultimately ...
215
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
... just three things
216
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
try run stuff good
1
217
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
when it's running good …
2
218
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
… keep running it like that !
219
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
If there is something better
220
3
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
then tell me
221
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
222
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
223
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
baselines do exactly this !
224
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
rarely used
225
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
apology #2
226
evolve
accepted
repeatable
unaccepted
capture
signature
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
close to our goals
227
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
228
11g
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
(quick) terminology
229
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
signature
230
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
231
signature
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
plan(s) for signature
232
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
233
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.
234
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 …
235
… keep running it like that !
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
236
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 ?
237
------------------------------------------------------------------------
| 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
238
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
DBMS_SPM.EVOLVE_SQL_PLAN_BASELINE
239
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
240
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 …
241
… that makes it bad or
there's something better
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
if only we had done ...
242
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
243
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
2) your system is OK
244
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
245
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
246
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
the same performance
247
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
248
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
wrap up
249
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
12c optimizer is better
250
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
12c optimizer is different
251
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
12.2+ preferred
252
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
12.1 ... backport
253
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
SPM is your friend
254
Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
Thank you!
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 :-)

Mais conteúdo relacionado

Mais procurados

EXAchk for Exadata Presentation
EXAchk for Exadata PresentationEXAchk for Exadata Presentation
EXAchk for Exadata Presentation
Sandesh Rao
 

Mais procurados (19)

Oracle Autonomous Health Service- For Protecting Your On-Premise Databases- F...
Oracle Autonomous Health Service- For Protecting Your On-Premise Databases- F...Oracle Autonomous Health Service- For Protecting Your On-Premise Databases- F...
Oracle Autonomous Health Service- For Protecting Your On-Premise Databases- F...
 
15 Troubleshooting Tips and Tricks for database 21c - OGBEMEA KSAOUG
15 Troubleshooting Tips and Tricks for database 21c - OGBEMEA KSAOUG15 Troubleshooting Tips and Tricks for database 21c - OGBEMEA KSAOUG
15 Troubleshooting Tips and Tricks for database 21c - OGBEMEA KSAOUG
 
Oracle Real Application Clusters 19c- Best Practices and Internals- EMEA Tour...
Oracle Real Application Clusters 19c- Best Practices and Internals- EMEA Tour...Oracle Real Application Clusters 19c- Best Practices and Internals- EMEA Tour...
Oracle Real Application Clusters 19c- Best Practices and Internals- EMEA Tour...
 
TFA, ORAchk and EXAchk 20.2 - What's new
TFA, ORAchk and EXAchk 20.2 - What's new TFA, ORAchk and EXAchk 20.2 - What's new
TFA, ORAchk and EXAchk 20.2 - What's new
 
LAD - GroundBreakers - Jul 2019 - Using Oracle Autonomous Health Framework to...
LAD - GroundBreakers - Jul 2019 - Using Oracle Autonomous Health Framework to...LAD - GroundBreakers - Jul 2019 - Using Oracle Autonomous Health Framework to...
LAD - GroundBreakers - Jul 2019 - Using Oracle Autonomous Health Framework to...
 
The Oracle Autonomous Database
The Oracle Autonomous DatabaseThe Oracle Autonomous Database
The Oracle Autonomous Database
 
AIOUG-GroundBreakers-Jul 2019 - 19c RAC
AIOUG-GroundBreakers-Jul 2019 - 19c RACAIOUG-GroundBreakers-Jul 2019 - 19c RAC
AIOUG-GroundBreakers-Jul 2019 - 19c RAC
 
Hyderabad Mar 2019 - Autonomous Database
Hyderabad Mar 2019 - Autonomous DatabaseHyderabad Mar 2019 - Autonomous Database
Hyderabad Mar 2019 - Autonomous Database
 
EXAchk for Exadata Presentation
EXAchk for Exadata PresentationEXAchk for Exadata Presentation
EXAchk for Exadata Presentation
 
Whats new in oracle trace file analyzer 19.2
Whats new in oracle trace file analyzer 19.2Whats new in oracle trace file analyzer 19.2
Whats new in oracle trace file analyzer 19.2
 
What's new in Oracle and Exachk version 18.4.0
What's new in Oracle and Exachk version 18.4.0What's new in Oracle and Exachk version 18.4.0
What's new in Oracle and Exachk version 18.4.0
 
Oracle Trace File Analyzer Overview
Oracle Trace File Analyzer OverviewOracle Trace File Analyzer Overview
Oracle Trace File Analyzer Overview
 
Examining Oracle GoldenGate Trail Files
Examining Oracle GoldenGate Trail FilesExamining Oracle GoldenGate Trail Files
Examining Oracle GoldenGate Trail Files
 
Exachk Customer Presentation
Exachk Customer PresentationExachk Customer Presentation
Exachk Customer Presentation
 
Using Machine Learning to Debug complex Oracle RAC Issues
Using Machine Learning  to Debug complex Oracle RAC IssuesUsing Machine Learning  to Debug complex Oracle RAC Issues
Using Machine Learning to Debug complex Oracle RAC Issues
 
Cluster Health Advisor (CHA) Deep Dive by Mark Scardina
Cluster Health Advisor (CHA)  Deep Dive by Mark ScardinaCluster Health Advisor (CHA)  Deep Dive by Mark Scardina
Cluster Health Advisor (CHA) Deep Dive by Mark Scardina
 
New availability features in oracle rac 12c release 2 anair ss
New availability features in oracle rac 12c release 2 anair   ssNew availability features in oracle rac 12c release 2 anair   ss
New availability features in oracle rac 12c release 2 anair ss
 
Oracle RAC features on Exadata
Oracle RAC features on ExadataOracle RAC features on Exadata
Oracle RAC features on Exadata
 
Oracle RAC 12c Rel. 2 Under the Hood and Best Practices
Oracle RAC 12c Rel. 2 Under the Hood and Best PracticesOracle RAC 12c Rel. 2 Under the Hood and Best Practices
Oracle RAC 12c Rel. 2 Under the Hood and Best Practices
 

Semelhante a Sangam 18 - The New Optimizer in Oracle 12c

Semelhante a Sangam 18 - The New Optimizer in Oracle 12c (20)

Wellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
Wellington APAC Groundbreakers tour - Upgrading to the 12c OptimizerWellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
Wellington APAC Groundbreakers tour - Upgrading to the 12c Optimizer
 
OpenWorld 2018 - 20 years of hints and tips
OpenWorld 2018 - 20 years of hints and tipsOpenWorld 2018 - 20 years of hints and tips
OpenWorld 2018 - 20 years of hints and tips
 
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
 
APEX Connect 2019 - SQL Tuning 101
APEX Connect 2019 - SQL Tuning 101APEX Connect 2019 - SQL Tuning 101
APEX Connect 2019 - SQL Tuning 101
 
APEX Connect 2019 - successful application development
APEX Connect 2019 - successful application developmentAPEX Connect 2019 - successful application development
APEX Connect 2019 - successful application development
 
Melbourne Groundbreakers Tour - Hints and Tips
Melbourne Groundbreakers Tour - Hints and TipsMelbourne Groundbreakers Tour - Hints and Tips
Melbourne Groundbreakers Tour - Hints and Tips
 
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
 
Hyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19cHyderabad Mar 2019 - Database 18c / 19c
Hyderabad Mar 2019 - Database 18c / 19c
 
Latin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matchingLatin America Tour 2019 - pattern matching
Latin America Tour 2019 - pattern matching
 
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
 
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
 
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 ...
 
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
 
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
 
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
 
OpenWorld 2018 - Pagination
OpenWorld 2018 - PaginationOpenWorld 2018 - Pagination
OpenWorld 2018 - Pagination
 
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
 
SkiPHP -- Database Basics for PHP
SkiPHP -- Database Basics for PHP SkiPHP -- Database Basics for PHP
SkiPHP -- Database Basics for PHP
 
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
 

Mais de Connor McDonald

Mais de Connor McDonald (20)

Flashback ITOUG
Flashback ITOUGFlashback ITOUG
Flashback ITOUG
 
Sangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolestSangam 19 - PLSQL still the coolest
Sangam 19 - PLSQL still the coolest
 
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
 
Sangam 2019 - The Latest Features
Sangam 2019 - The Latest FeaturesSangam 2019 - The Latest Features
Sangam 2019 - The Latest Features
 
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
 

Último

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Último (20)

Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

Sangam 18 - The New Optimizer in Oracle 12c

  • 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. 21 You will upgrade us to 12c with its new optimizer
  • 22. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. LOL !LOL ! 22
  • 23. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. LMAOLMAO! 23
  • 24. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. That dude is toast! That dude is toast! 24
  • 25. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. Is this why I don't have a desk ? 25
  • 26. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. lots of fear 26
  • 27. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. lots of mis-information 27
  • 28. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. only 2 issues 28
  • 29. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. ISSUE #1 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. cardinality mis-estimates 31
  • 32. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. cardinality is everything 32
  • 33. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 33
  • 34. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. better stats 34
  • 35. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. missing or poor statistics 35
  • 36. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 1) better histograms 36
  • 37. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 2015 37
  • 38. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 38
  • 39. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 39
  • 40. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. Histograms are so awesome. See how much they make me smile ! 40
  • 41. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 41
  • 42. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. No … … honest :-) 42
  • 43. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. the sucky part 43
  • 44. 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. 44
  • 45. 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 45
  • 46. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 46
  • 47. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 47
  • 48. 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 48
  • 49. 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 49
  • 50. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. we don't know what your "app" is 50
  • 51. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. still requires care 51
  • 52. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 12c improvements 52
  • 53. 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 53
  • 54. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. skewed ... 54
  • 55. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. ... need histogram 55
  • 56. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 11g 56
  • 57. 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 57
  • 58. 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 58
  • 59. 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 59
  • 60. 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 60
  • 61. 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') 61 true = 800
  • 62. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. so far … so good 62
  • 63. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. NDV > 254* 63
  • 64. 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 64
  • 65. 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 65
  • 66. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 1-New 6-Received 7-Complete 8-Archived 8-Archived 8-Archived 7-Complete 66
  • 67. 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 67
  • 68. 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 68
  • 69. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 69
  • 70. 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 70
  • 71. 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 71
  • 72. 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 72
  • 73. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. height balanced means ... 73
  • 74. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. bucket spanning = dramas 74
  • 75. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. bucket swallowing = dramas 75
  • 76. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 11g HEIGHT-BALANCED FREQUENCY 76
  • 77. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. Footnote: 11g FOR ALL COLUMNS SIZE 25AUTO 77
  • 78. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 78
  • 79. 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 79
  • 80. 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 80
  • 81. 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 81
  • 82. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 1-New 6-Received 3-InProgress 5-Shipped 8-Archived 7-Completed 82
  • 83. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. other values ? 83
  • 84. 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 ) = 84
  • 85. 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') 85 true = 3
  • 86. 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 86
  • 87. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. what if TOP FREQ not possible ? 87
  • 88. 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; 88
  • 89. 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 89
  • 90. 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 90
  • 91. 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 91
  • 92. 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 92
  • 93. 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" 93 6-Received 554
  • 94. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. no bucket spanning 94
  • 95. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. key point 95
  • 96. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. must use auto sample size 96
  • 97. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. still need care 97
  • 98. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. representative values 98
  • 99. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. "today's hot deals" 99
  • 100. 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 100
  • 101. 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 101
  • 102. 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 ... 102
  • 103. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. where type = 'HOT_DEAL' 103
  • 104. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 104
  • 105. 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 105
  • 106. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. normally... 106
  • 107. 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!" 107
  • 108. 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!" 108
  • 109. 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 109
  • 110. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. representative values ... at the right time 110
  • 111. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 2) extensions 111
  • 112. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 11g 112
  • 113. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. "extended" statistics 113
  • 114. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. aka "column groups" 114
  • 115. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. solve GIGO 115
  • 116. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. SQL> select * 2 from ADDRESS 3 where CITY = 'Bangalore' 4 and COUNTRY = 'Australia'; 116
  • 117. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 117
  • 118. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. automatic column groups 118
  • 119. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 12.2 119
  • 120. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. expression tracking 120
  • 121. 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 121
  • 122. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. missing or poor statistics 122
  • 123. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 3) online gather 123
  • 124. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. the old problem 124
  • 125. 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; 125
  • 126. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 126
  • 127. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 127
  • 128. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 128
  • 129. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 129
  • 130. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 130
  • 131. 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 131
  • 132. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. and then... 132
  • 133. 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 ---------- 133
  • 134. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. so ... 134
  • 135. 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 135
  • 136. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 136
  • 137. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. on load 137
  • 138. 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 138
  • 139. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. things to note 139
  • 140. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. must be direct insert /*+ APPEND */ create table as select 140
  • 141. 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 ---------- 141
  • 142. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. must be empty 142
  • 143. 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 ---------- 143
  • 144. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. execution plan 144
  • 145. 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)| ------------------------------------------------------------------------------ 145
  • 146. 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 ... ... 146
  • 147. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. note: no histograms 147
  • 148. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 3) session GTT 148
  • 149. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 11g 149
  • 150. 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. 150
  • 151. 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)| --------------------------------------------------------------- 151
  • 152. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. looks great until ... 152
  • 153. 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)| --------------------------------------------------------------- 153
  • 154. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 154
  • 155. 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. 155
  • 156. 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 156
  • 157. 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'); 157
  • 158. 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 158
  • 159. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. back to session 1 159
  • 160. 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)| --------------------------------------------------------------- 160
  • 161. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. note: default = private 161
  • 162. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. so far ... 162
  • 163. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. missing or poor statistics 163
  • 164. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. improved optimizer "inputs" histograms gather on load private GTT 164
  • 165. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. ISSUE #2 165
  • 166. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. statistics needed = "∞" 166
  • 167. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. learn ... as we go 167
  • 168. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. learn ... from experiences 168
  • 169. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. Adaptive Query Optimization #1 169 learn as we go
  • 170. 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" 170
  • 171. 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 | ----------------------------------------------------------------- 171
  • 172. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 172 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 | -----------------------------------------------------------------
  • 173. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. the runtime plan ? 173
  • 174. 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)| -------------------------------------------------------------------------- 174
  • 175. 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> 175
  • 176. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. cool 176 "dodged a bullet"
  • 177. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. Adaptive Query Optimization #2 177 learn from experience
  • 178. 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 | ------------------------------------------------------------------------- 178
  • 179. 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> 179
  • 180. 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 180
  • 181. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. seems cool 181
  • 182. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. we mightta got carried away :-( 182
  • 183. 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 ... ... 183
  • 184. 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 184
  • 185. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. same SQL ... 185
  • 186. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. ... different plans 186
  • 187. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. ... then more different plans 187
  • 188. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. ... then even more different plans 188
  • 189. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. So ... this happens 189
  • 190. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. upgrade to 12.1 190
  • 191. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. new optimizations 191
  • 192. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. new statistics 192
  • 193. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. default = everything enabled 193
  • 194. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. "the plans keep changing" 194
  • 195. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. just one switch 195
  • 196. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 196
  • 197. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. options 197
  • 198. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. optimizer_adaptive_features = false 198
  • 199. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. optimizer_features_enable = 11.2.0.4 199
  • 200. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. don't panic ... that's fine endorsed 200
  • 201. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 12.1 ... perhaps too aggressive 201
  • 202. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 12.2 ... more control 202
  • 203. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 12.2 ... more passive 203
  • 204. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. TRUE FALSE 204
  • 205. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 12.2 ... much better 205
  • 206. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 12.1 patch 22652097 206
  • 207. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. which brings us to ... 207
  • 208. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. upgrade scenarios 208
  • 209. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. there are only two 209
  • 210. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 1) your system sucks :-) 210 upgrade to 12.2 explore full adaptive
  • 211. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 2) your system is OK 211 how can I lower risk ?
  • 212. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. SQL Plan Baselines 212
  • 213. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. apology #1 213
  • 214. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 214
  • 215. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. but ultimately ... 215
  • 216. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. ... just three things 216
  • 217. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. try run stuff good 1 217
  • 218. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. when it's running good … 2 218
  • 219. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. … keep running it like that ! 219
  • 220. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. If there is something better 220 3
  • 221. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. then tell me 221
  • 222. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 222
  • 223. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 223
  • 224. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. baselines do exactly this ! 224
  • 225. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. rarely used 225
  • 226. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. apology #2 226 evolve accepted repeatable unaccepted capture signature
  • 227. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. close to our goals 227 working good ? Keep it found something better ? Tell me found something worse ? Don’t use it
  • 228. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. not new 228 11g
  • 229. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. (quick) terminology 229
  • 230. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. signature 230
  • 231. 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 231 signature
  • 232. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. plan(s) for signature 232
  • 233. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 233 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
  • 234. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 234 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
  • 235. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. when it's running good … 235 … keep running it like that !
  • 236. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 236 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 !
  • 237. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. maybe it is better ? 237 ------------------------------------------------------------------------ | 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 | ------------------------------------------------------------------------
  • 238. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. evolve a plan 238
  • 239. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. DBMS_SPM.EVOLVE_SQL_PLAN_BASELINE 239
  • 240. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 240 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
  • 241. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. unless … 241 … that makes it bad or there's something better
  • 242. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. if only we had done ... 242 DBMS_SPM.I_LOVE_THIS_PLAN(sql_id) DBMS_SPM. THIS_PLAN_SUCKS(sql_id) DBMS_SPM. SWAP_THIS_PLAN_IN(sql_id)
  • 243. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. so back to upgrade 243
  • 244. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 2) your system is OK 244 how can I lower risk ?
  • 245. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. SQL> alter system set 2 optimizer_capture_sql_plan_baselines = true 245
  • 246. 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 246
  • 247. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. the same performance 247
  • 248. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 248
  • 249. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. wrap up 249
  • 250. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 12c optimizer is better 250
  • 251. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 12c optimizer is different 251
  • 252. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 12.2+ preferred 252
  • 253. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 12.1 ... backport 253
  • 254. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. SPM is your friend 254
  • 255. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. Thank you! 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 :-)

Notas do Editor

  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. So what happens when either the user hates us ? or gives us unachieveable goals ?
  14. So what happens when either the user hates us ? or gives us unachieveable goals ?
  15. So what happens when either the user hates us ? or gives us unachieveable goals ?
  16. So what happens when either the user hates us ? or gives us unachieveable goals ?
  17. So what happens when either the user hates us ? or gives us unachieveable goals ?
  18. which of course means, we really should not be surprised when ask our customers about performance
  19. which of course means, we really should not be surprised when ask our customers about performance
  20. which of course means, we really should not be surprised when ask our customers about performance
  21. Which is great…but is unrealistic.
  22. which of course means, we really should not be surprised when ask our customers about performance
  23. which of course means, we really should not be surprised when ask our customers about performance
  24. which of course means, we really should not be surprised when ask our customers about performance
  25. which of course means, we really should not be surprised when ask our customers about performance
  26. 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
  27. which of course means, we really should not be surprised when ask our customers about performance
  28. 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
  29. 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
  30. 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
  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. 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 !!!
  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. 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 !!!
  52. Because garbage in = garbage out no matter how good your optimiser is
  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. which of course means, we really should not be surprised when ask our customers about performance
  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. 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 !!!
  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. 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 !!!
  69. 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 !!!
  70. 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 !!!
  71. which of course means, we really should not be surprised when ask our customers about performance
  72. 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 !!!
  73. 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 !!!
  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. Which is great…but is unrealistic.
  78. which of course means, we really should not be surprised when ask our customers about performance
  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. 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
  86. 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
  87. 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
  88. 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
  89. 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
  90. 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
  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. So what happens when either the user hates us ? or gives us unachieveable goals ?
  100. So what happens when either the user hates us ? or gives us unachieveable goals ?
  101. So what happens when either the user hates us ? or gives us unachieveable goals ?
  102. So what happens when either the user hates us ? or gives us unachieveable goals ?
  103. So what happens when either the user hates us ? or gives us unachieveable goals ?
  104. But ultimately….from the optimizer we really want some simple things
  105. But ultimately….from the optimizer we really want some simple things
  106. But ultimately….from the optimizer we really want some simple things
  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. But ultimately….from the optimizer we really want some simple things
  110. So what happens when either the user hates us ? or gives us unachieveable goals ?
  111. 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.
  112. But ultimately….from the optimizer we really want some simple things
  113. But ultimately….from the optimizer we really want some simple things
  114. 1) run my SQL as good as it can be run … or at least TRY to
  115. 2) and when you've got it running good…
  116. for god sakes, don't change anything. Just keep running it good… all the time, exactly like it is today….
  117. "….but … I don’t want to look like a fool, so if you DO find something better…."
  118. then please tell me…
  119. BUT DON"T TOUCH ANYTHIING. Let *me* decide if this is a good switch to make.
  120. 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.
  121. then please tell me…
  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 what happens when either the user hates us ? or gives us unachieveable goals ?
  124. 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
  125. 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
  126. 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
  127. 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
  128. 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
  129. 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
  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. 2) and when you've got it running good…
  132. 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
  133. for god sakes, don't change anything. Just keep running it good… all the time, exactly like it is today….
  134. for god sakes, don't change anything. Just keep running it good… all the time, exactly like it is today….
  135. 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
  136. and 3…. which is always the kicker … unless of course
  137. 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
  138. 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
  139. But ultimately….from the optimizer we really want some simple things
  140. 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
  141. which of course means, we really should not be surprised when ask our customers about performance
  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 !!!
  143. So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  144. So to achieve our of goals - run fast - but keep an eye on how to run things faster - then either tell me or do it for me when needed we need something better… And its not something "NEW" in 18c, or 12c, …. Its something you already have !!!
  145. 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 !!!
  146. 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 !!!
  147. 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 !!!