The Effects of
optimizer_index_cost_adj and
optimizer_index_caching on Access Plans Wolfgang Breitling breitliw@centrexcc.com
Who am I Independent consultant since 1996 specializing in Oracle and Peoplesoft setup, administration, and performance tuning Member of the Oaktable Network 25+ years in database management DL/1, IMS, ADABAS, SQL/DS, DB2, Oracle
OCP certified DBA - 7, 8, 8i, 9i Oracle since 1993 (7.0.12) Mathematics major at University of Stuttgart 2
Š Wolfgang Breitling, Centrex Consulting Corporation
Hotsos Symposium, March 6-9, 2005
Agenda Show how different setting of o_i_c_a and o_i_c change the CBO’s cost calculation Show one case where the CBO refuses to be lied to Show how the changed costs translate into access path transformations Contrast the o_i_c_a parameters to the effect of system statistics 3
© Wolfgang Breitling, Centrex Consulting Corporation
Hotsos Symposium, March 6-9, 2005
Index Access Costs
4
Unique scan
blevel + 1
Fast full scan
leaf_blocks / k
Index-only
blevel + FFi * leaf_blocks
Range scan
blevel + FFi * leaf_blocks + FFt * clustering_factor
Š Wolfgang Breitling, Centrex Consulting Corporation
Hotsos Symposium, March 6-9, 2005
Single Table Access Path and o_i_c_a OPTIMIZER_INDEX_COST_ADJ = 100 Access path: tsc Access path: index (no sta/stp keys) RSC_CPU: 0 Access path: index (equal) RSC_CPU: 0 BEST_CST:
Resc: 4698 RSC_IO: 27954 RSC_IO: 6891 4698.00
PATH: 2
Setting event 10183 prevents rounding OPTIMIZER_INDEX_COST_ADJ = 10 Access path: tsc Resc: 4698 Access path: index (no sta/stp keys) RSC_CPU: 0 RSC_IO: 27954 Access path: index (equal) RSC_CPU: 0 RSC_IO: 6891 BEST_CST: 689.10 PATH: 4
5
OPTIMIZER_INDEX_COST_ADJ = 1 Access path: tsc Access path: index (no sta/stp keys) RSC_CPU: 0 Access path: index (equal) RSC_CPU: 0 BEST_CST:
Resc: 4698 RSC_IO: 27954 RSC_IO: 6891 68.91
PATH: 4
OPTIMIZER_INDEX_COST_ADJ = 1000 Access path: tsc Access path: index (no sta/stp keys) RSC_CPU: 0 Access path: index (equal) RSC_CPU: 0 BEST_CST:
Resc: 4698 RSC_IO: 27954 RSC_IO: 6891 4698.00
PATH: 2
© Wolfgang Breitling, Centrex Consulting Corporation
Hotsos Symposium, March 6-9, 2005
Single Table Access Path and o_i_c_a Index access costs get “discounted” by applying a factor of optimizer_index_cost_adj/100 to the calculated index costs before deciding the lowest-cost single table access path.
6
© Wolfgang Breitling, Centrex Consulting Corporation
Hotsos Symposium, March 6-9, 2005
Single Table Access Path and o_i_c_a Since 4698/6891 = 0.681759, it is to be expected that the adjusted “index (equal)” access cost, and with it the single table access path to fall below the tsc access cost – which remains unadjusted – between o_i_c_a = 69 and o_i_c_a = 68:
7
OPTIMIZER_INDEX_COST_ADJ = 100 Access path: tsc Access path: index (no sta/stp keys) RSC_CPU: 0 Access path: index (equal) RSC_CPU: 0 BEST_CST:
Resc: 4698 RSC_IO: 27954 RSC_IO: 6891 4698.00
OPTIMIZER_INDEX_COST_ADJ = 69 Access path: tsc Access path: index (no sta/stp keys) RSC_CPU: 0 Access path: index (equal) RSC_CPU: 0 BEST_CST:
Resc: 4698 RSC_IO: 27954 RSC_IO: 6891 [4754.79] 4698.00 PATH: 2
OPTIMIZER_INDEX_COST_ADJ = 68 Access path: tsc Access path: index (no sta/stp keys) RSC_CPU: 0 Access path: index (equal) RSC_CPU: 0 BEST_CST:
Resc: 4698 RSC_IO: 27954 RSC_IO: 6891 4685.88
© Wolfgang Breitling, Centrex Consulting Corporation
PATH: 2
PATH: 4
Hotsos Symposium, March 6-9, 2005
Joins and o_i_c_a o_i_c_a affects joins in 2, perhaps 3 ways adjusted cost of the outer table from carried single table access best_cst adjusted NL index access costs adjusted index access cost instead of a sort in SM join
8
© Wolfgang Breitling, Centrex Consulting Corporation
Hotsos Symposium, March 6-9, 2005
o_i_c_a and NL Joins OPTIMIZER_INDEX_COST_ADJ = 100 Outer table: cost: 4698 cdn: 144 rcz: 43 Inner table: Access path: tsc Resc: 2541 Access path: index (unique) RSC_IO: 2 Access path: index (scan) RSC_IO: 3 Access path: index (no sta/stp keys) RSC_IO: 3153 Access path: index (scan) RSC_IO: 271 Access path: index (eq-unique) RSC_IO: 2 Best NL cost: 4986
Join: 370602 Join: 4986 Join: 5130 Join: 458730 Join: 43722 Join: 4986
No fractional costs shown despite event 10183 OPTIMIZER_INDEX_COST_ADJ = 10 689 + 144*2 * 10/100 Outer table: cost: 689 cdn: 144 rcz: 43 Inner table: Access path: tsc Access path: index Access path: index Access path: index Access path: index Access path: index Best NL cost: 718
9
Resc: 2541 Join: 366593 (unique) RSC_IO: 2 Join: 718 (scan) RSC_IO: 3 Join: 732 (no sta/stp keys) RSC_IO: 3153 Join: 46092 (scan) RSC_IO: 271 Join: 4592 (eq-unique) RSC_IO: 2 Join: 718
Š Wolfgang Breitling, Centrex Consulting Corporation
14.4% 14.3% 10.0% 10.5% 14.4%
Hotsos Symposium, March 6-9, 2005
o_i_c_a and HA and SM Joins Beyond possibly reduced access costs of outer and inner tables, there is no further affect of optimizer_index_cost_adj on HA joins I have not observed any cases where an index on the inner table in an SM join was used to avoid the sort and was discounted, but it is certainly possible.
10
Š Wolfgang Breitling, Centrex Consulting Corporation
Hotsos Symposium, March 6-9, 2005
Optimizer_Index_Caching LVLS: 2
#LB: 3178
CLUF: 21958
Outer table: cost: 7387
cdn: 429
rcz: 23
0 Access path: index (no sta/stp keys) RSC_IO: 4226 Join: 1820341 10 Access path: index (no sta/stp keys) RSC_IO: 3959 Join: 1705798 20 Access path: index (no sta/stp keys) RSC_IO: 3635 Join: 1566802 30 Access path: index (no sta/stp keys) RSC_IO: 3312 Join: 1428235 40 Access path: index (no sta/stp keys) RSC_IO: 2988 Join: 1289239 50 Access path: index (no sta/stp keys) RSC_IO: 2664 Join: 1150243 60 Access path: index (no sta/stp keys) RSC_IO: 2341 Join: 1011676 70 Access path: index (no sta/stp keys) RSC_IO: 2017 Join: 872680 80 Access path: index (no sta/stp keys) RSC_IO: 1694 Join: 734113 90 Access path: index (no sta/stp keys) RSC_IO: 1370 Join: 595117 100 Access path: index (no sta/stp keys) RSC_IO: 1046 Join: 456121
11
Š Wolfgang Breitling, Centrex Consulting Corporation
Hotsos Symposium, March 6-9, 2005
Optimizer_Index_Caching rsc_io
4,500 4,000 3,500 3,000 2,500 2,000 1,500 1,000 500 0 0
12
10
20
30
40
50
Š Wolfgang Breitling, Centrex Consulting Corporation
60
70
80
90
100 o_i_c
Hotsos Symposium, March 6-9, 2005
Optimizer_Index_Caching
rsc_io ≈ lvls + (100 – oic)/100 * ix_sel*#lb + tb_sel*cluf join = $outer + cdnouter * rsc_ioinner
13
© Wolfgang Breitling, Centrex Consulting Corporation
Hotsos Symposium, March 6-9, 2005
Optimizer_Index_Caching lvls 2
#lb 3,178
cluf 21,958
4250 4226
4225
4218
4200
33 4185
32 4153
4150
32 4121
33
4100
4088
32 4056
4050
32 4024 4000
3991 3959
3950 0
14
1
2
3
4
Š Wolfgang Breitling, Centrex Consulting Corporation
5
6
7
8
9
10
Hotsos Symposium, March 6-9, 2005
Index Access Costs
15
Unique scan
blevel + 1 1 or even 0
Fast full scan
leaf_blocks / k leaf_blocks / k
Index-only
blevel + FFi * leaf_blocks (100-oic)/100 * FFi * leaf_blocks
Range scan
blevel + FFi * leaf_blocks + FFt * clustering_factor (100-oic)/100 * FFi * leaf_blocks + FFt * clustering_factor
Š Wolfgang Breitling, Centrex Consulting Corporation
Hotsos Symposium, March 6-9, 2005
Optimizer_Index_Caching
Unlike optimizer_index_cost_adj, optimizer_index_caching affects only the cost of NL joins
16
Š Wolfgang Breitling, Centrex Consulting Corporation
Hotsos Symposium, March 6-9, 2005
o_i_c_a and o_i_c together Outer table: cost: 7387 cdn: 429 rcz: 23 Inner table index: LVLS: 2 #LB: 3178 CLUF: 21958 IX_SEL: 1.0000e+00 TB_SEL: 4.7619e-02 oic 0 10 20 30 40 50 60 70 80 90 100
17
o_i_c_a: rsc_io 4,226 3,959 3,635 3,312 2,988 2,664 2,341 2,017 1,694 1,370 1,046
100 join 1,820,341 1,705,798 1,566,802 1,428,235 1,289,239 1,150,243 1,011,676 872,680 734,113 595,117 456,121
Š Wolfgang Breitling, Centrex Consulting Corporation
10 join 188,682 177,228 163,328 149,472 135,572 121,673 107,816 93,916 80,060 66,160 52,260
1 join 25,517 24,371 22,981 21,595 20,206 18,816 17,430 16,040 14,654 13,264 11,874
Hotsos Symposium, March 6-9, 2005
o_i_c_a and o_i_c together 2,000,000
o_i_c_a = 100
o_i_c_a = 10
o_i_c_a = 1
1,820,341 = 7387 + 1,812,954
1,800,000
1,600,000
1,400,000
1,200,000
1,000,000
800,000
600,000
400,000 188,682 = 7387 + 181,295
200,000
25,517 = 7387 + 18,130 0 0
10
20
30
40
50
60
70
80
90
100 o_i_c
18
Š Wolfgang Breitling, Centrex Consulting Corporation
Hotsos Symposium, March 6-9, 2005
o_i_c_a and o_i_c together
$join = $outer + oica/100 * cdn * rsc_io rsc_io ≈ lvls + (100 – oic)/100 * ix_sel*#lb + tb_sel*cluf
19
© Wolfgang Breitling, Centrex Consulting Corporation
Hotsos Symposium, March 6-9, 2005
Optimizer_Index_Caching db_cache_size=64M ( 8192 8K blocks ) 30,000.0 3,508
#LB
7,015
14,029
28,057
25,000.0
20,000.0
15,000.0
10,000.0
5,000.0
0.0 0
20
10
20
30
40
50
Š Wolfgang Breitling, Centrex Consulting Corporation
60
70
80
90
o_i _c 100
Hotsos Symposium, March 6-9, 2005
Source: http://www.tpc.org/information/sessions/sigmod/sld029.htm 21
Š Wolfgang Breitling, Centrex Consulting Corporation
Hotsos Symposium, March 6-9, 2005
select sum(o.totalprice) from order_1 o , customer_1 c , lineitem_1 l , part_1 p where o.cust_id = c.cust_id and l.order_id = o.order_id and l.part_id = p.part_id and o.orderpriority = '2-HIGH' and c.mktsegment = 'HOUSEHOLD' and p.mfgr = 'Manufacturer#2' and p.brand = 'Brand#33' and l.shipdate > to_date('2005-01-22','yyyy-mm-dd') 22
Š Wolfgang Breitling, Centrex Consulting Corporation
Hotsos Symposium, March 6-9, 2005
Access Path Evolution optimizer_index_cost_adj = 100 optimizer_index_caching = 0
cardinality
row source
1
sort1640
cost (access path)
HA
50
160
160
160
23
P
37 (iff)
HA
NL
1640
C 3000
1586
O 1426
238
1
L
1 (unique)
NL = SM = HA =
1586 + 160*1 = 1586 + 53 + 2 + 11 = 1586 + 53 + 1 =
1746 1652 1640
NL = SM = HA =
1426 + 160*1 = 1426 + 340 + 2 + 174 = 1426 + 340 + 2 =
1586 1942 1768
53 (tsc)
NL = SM = HA =
37 + 160*1388 = 222117 37 + 1388 + 2 + 2 = 1428 37 + 1388 + 2 = 1426
1388 (tsc)
Š Wolfgang Breitling, Centrex Consulting Corporation
Hotsos Symposium, March 6-9, 2005
Access Path Evolution optimizer_index_cost_adj = 25 optimizer_index_caching = 90
cardinality
row source
1
sort NL
50
160
160
160
24
P
37 (iff)
1506
cost (access path)
HA
NL
1506
C
1
1466
O 1426
238
1
L
0 (unique)
NL = SM = HA =
1466 + 0.25* 160*1 = 1466 + 53 + 2 + 11 = 1466 + 53 + 1 =
1506 1652 1640
NL = SM = HA =
1426 + 0.25* 160*1 = 1426 + 340 + 2 + 174 = 1426 + 340 + 2 =
1466 1942 1768
0 (unique)
NL = SM = HA =
37 + 0.25*160*368 = 0.25* 37 + 1388 + 2 + 2 = 37 + 1388 + 2 =
14757 1428 1426
1388 (tsc)
Š Wolfgang Breitling, Centrex Consulting Corporation
Hotsos Symposium, March 6-9, 2005
Access Path Evolution optimizer_index_cost_adj = 10 optimizer_index_caching = 90
cardinality
row source
1
sort NL
50
74
238
238
25
L
1443
cost (access path)
NL
1388 (tsc)
NL
1443
1
1436
P
1
1
1436 + 0.1* 74*1 = 1436 + 24 + 2 + 2 = 1436 + 24 + 2 =
1443 1462 1460
NL = SM = HA =
1412 + 0.1* 238*1 = 1412 + 53 + 2 + 11 = 1412 + 53 + 1 =
1436 1478 1466
0 (unique)
C 1412
NL = SM = HA =
0 (unique)
NL = SM = HA =
1388 + 0.1*238*1 = 0.1* 1388 + 340 + 2 + 174 = 1388 + 340 + 1 =
1411.8 1904 1729
O
0 (unique)
Š Wolfgang Breitling, Centrex Consulting Corporation
Hotsos Symposium, March 6-9, 2005
Access Path Evolution mbrc=8, mreadtim=1.21 * sreadtim
cardinality
row source
1
160
160
26
P
37 (iff)
sort 1634
cost (access path)
50
160
optimizer_index_caching = 0
HA
NL
HA
1634
C 3000
1580
O 1420
238
1
L
1 (unique)
NL = SM = HA =
1580 + 160*1 = 1579 + 53 + 2 = 1579 + 53 + 1 =
1740 1634 1633
NL = SM = HA =
1420 + 160*1 = 1419 + 339 + 2 + 188 = 1419 + 339 + 1 =
1580 1948 1759
53 (tsc)
NL = SM* = HA =
37 + 160*1382 = 221157 369 + 1382 + 1 = 1752 37 + 1382 + 1 = 1420
1382 (tsc)
Š Wolfgang Breitling, Centrex Consulting Corporation
Hotsos Symposium, March 6-9, 2005
Access Path Evolution mbrc=8, mreadtim=4.84 * sreadtim
cardinality
row source
1
sort NL
160
160
5986
cost (access path)
50
HA
NL
NL = SM = HA =
5986
C
1
5826
O 5666
1
optimizer_index_caching = 0
1 (unique)
5825 + 160*1 = 5825 + 207 + 2 = 5825 + 207 + 1 =
5985 6034 6033
NL = 5665 + 160*1 = SM = 5665 + 1351 + 320 [+2] = HA = 5665 + 1351 [+1] =
5825 7338 7017
1 (unique)
NL = SM = HA =
♣
140 + 160*4230 = 676939 139 + 5525 + 1 = 5666 139 + 5525 = 5665
♣ but best NL cost reported as 884140 = 140 + 160*5525
160
27
P
140 (iff)
238
L
5525 (tsc)
© Wolfgang Breitling, Centrex Consulting Corporation
Hotsos Symposium, March 6-9, 2005
Access Path Evolution mbrc=8, mreadtim=4.84 * sreadtim 1
sort NL
50
160
160
HA
NL
5986 NL = SM = HA =
5986
C
1
5826
O 5666
1
optimizer_index_caching = 90
1 (unique)
5825 + 160*1 = 5825 + 207 + 2 = 5825 + 207 + 1 =
5985 6034 6033
NL = 5665 + 160*1 = SM = 5665 + 1351 + 320 [+2] = HA = 5665 + 1351 [+1] =
5825 7338 7017
1 (unique)
NL = SM = HA =
♣
140 + 160*439 = 70379 139 + 5525 + 1 = 5666 139 + 5525 = 5665
♣ but best NL cost reported as 884140 = 140 + 160*5525
160
28
P
140 (iff)
238
L
5525 (tsc)
© Wolfgang Breitling, Centrex Consulting Corporation
Hotsos Symposium, March 6-9, 2005
Access Path Evolution mbrc=8, mreadtim=12.1 * sreadtim optimizer_index_caching = 90 1
sort NL
50
160
160
HA
NL
14361 NL = SM = HA =
14361
C
1
14201
O 14041
1
1 (unique)
14201 + 160*1 = 14200 + 516 [+2] = 14200 + 516 [+1] =
14361 14718 14717
NL = 14041 + 160*1 = SM = 14040 + 3376 + 580 [+2] = HA = 14040 + 3376 [+1] =
14201 17998 17417
1 (unique)
NL = SM = HA =
♣
229 + 160*439 = 70468 228 + 1388 + 2 + 2 = 1428 228 + 1388 + 2 = 1426
♣ but best NL cost reported as 2209989 = 229 + 160*13811
160
29
P
229 (iff)
238
L
13811 (tsc)
© Wolfgang Breitling, Centrex Consulting Corporation
Hotsos Symposium, March 6-9, 2005
My favorite websites asktom.oracle.com www.evdbt.com www.ixora.com.au www.jlcomp.demon.co.uk www.hotsos.com www.miracleas.dk www.oracledba.co.uk www.oraperf.com www.orapub.com
30
Š Wolfgang Breitling, Centrex Consulting Corporation
(Thomas Kyte) (Tim Gorman) (Steve Adams) (Jonathan Lewis) (Cary Millsap) (Mogens Nørgaard) (Connor McDonald) (Anjo Kolk) (Craig Shallahamer)
Hotsos Symposium, March 6-9, 2005
Wolfgang Breitling breitliw@centrexcc.com
Centrex Consulting Corp. www.centrexcc.com