SlideShare a Scribd company logo
1 of 74
How to estimate oracle cost

Philip Zhong
Sina WeiBo:@离叔-菲利普
Blog: Philipzhong.blogspot.com
2013-2-18

© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   1
• Important Statistics Values and Parameters
• Cardinality and Selectivity
• IO Cost model
• New Cost model




© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   2
Table Statistics:
         Number of table blocks(BLOCKS)
         Number of table rows(NUM_ROWS)
Index Statistics:
         Levels of the index(BLEVEL)
         Number of leaf blocks (LEAF_BLOCKS)
         Clustering factor(CLUSTERING_FACTOR)
         Number of distinct keys(DISTINCT_KEYS)
Column Statistics:
           Number of distinct values(NUM_DISTINCT)
           Number of NULL values(NUM_NULLS)
           Density

© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   3
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   4
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   5
• NUM_DISTINCT=number of distinct value
• Base Cardinality = number of rows of the table
• FF=filter factor of the condition=1 / NUM_DISTINCT(column)
• Selectivity = FF= Estimated cardinality /Base Cardinality
• Estimated Cardinality = Selectivity * Base Cardinality




© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   6
• C1=value  1/NUM_DISTINCT
• C1 like value  1/NUM_DISTINCT
• C1>value  ((Hi-Value)/(Hi-Lo))
• C1<value  ((Value-Lo)/(Hi-Lo))
• C1>=value  ((Hi-Value)/(Hi-Lo))+1/NUM_DISTINCT
• C1<=value  ((Value-Lo)/(Hi-Lo))+1/NUM_DISTINCT
• C1 between value1 and value2  ((value2 – value1)/(Hi-
  Lo))+2/NUM_DISTINCT
• Notice: if column is NULL

           Adjusted selectivity =
            Base selectivity * (1 - num_nulls/num_rows)
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   7
• C1=:B1  C1.Density

• C1 like :B1  { 0.05 | C1.Density }
• C1 { < | <= | > | >= } :B1 C1.Density

• C1 between :B1 and :B2  C1.Density*C2. Density

• Notice: if column is NULL

          Adjusted selectivity =
          C1.Density * ( 1 - num_nulls/ num_rows )




© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   8
• C1 and C2  FF1 * FF2

• C1 or C2  FF1 + FF2 - FF1 * FF2

• Not C1                                            1-FF1




© 2011 Cisco and/or its affiliates. All rights reserved.     Cisco Confidential   9
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   10
• Full Table Scan:
       Cost=( NBLKS/ k )+1 (if _table_scan_cost_plus_one = true)
• Non-Index costing:
         Cost = blevel + (leaf_blocks * effective index selectivity)
                                  +(clustering_factor * effective table selectivity)
•        Unique-Index costing:
         Cost=blevel + min cost of index +(clustering_factor * effective table selectivity)
• Join cost:
       NESTED LOOP JOIN cost = cost of accessing outer table + (cardinality of outer table
       * cost of accessing inner table )
       SORT MERGE JOIN cost = (cost of accessing outer table + outer sort cost) + (cost
       of accessing inner table + inner sort cost)
       HASH JOIN cost = (cost of accessing outer table) + (cost of building hash table) +
       (cost of accessing inner table )


© 2011 Cisco and/or its affiliates. All rights reserved.                                Cisco Confidential   11
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   12
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   13
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   14
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   15
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   16
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   17
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   18
• Cost Calculation formula:

         Cost= (NBLKS/ k)+1 (if _table_scan_cost_plus_one = true)


             Case Name                                     Estimate Cost           Original Cost

             Case 1                                        171/10.40+1=17.44       18

             Case 2                                        1495/10.40+1=144.75     145

             Case 3                                        12151/10.40+1=1169.37   1170

             Case 4                                        12151/6.59+1=1844.85    1846



© 2011 Cisco and/or its affiliates. All rights reserved.                                           Cisco Confidential   19
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   20
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   21
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   22
Cost = blevel +( leaf_blocks * effective index selectivity +
 clustering_factor * effective table selectivity)


             Case Name                                     Estimate Cost                    Original Cost

             Case 1                                        1+(190*1)=191                   191

             Case 2                                        1+1=2                           2

             Case 3                                        1+(264*1+91723* 0.000027)=267.48 268




© 2011 Cisco and/or its affiliates. All rights reserved.                                                    Cisco Confidential   23
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   24
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   25
Cost = blevel + ( leaf_blocks * effective index selectivity/k)



             Case Name                                     Estimate Cost           Original Cost

             Case 1                                        1+(190*1/10.40)=19.27   20

             Case 2                                        1+(190*1/6.59)=29.83    30




© 2011 Cisco and/or its affiliates. All rights reserved.                                           Cisco Confidential   26
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   27
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   28
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   29
• NewDensity = [ (BktCnt - PopBktCnt) / BktCnt ] /
       (NDV - PopValCnt)
• NewDensity=((254-12)/254)/(717-6)=0.001340022




© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   30
Cost = blevel + (leaf_blocks * effective index selectivity
                                            + clustering_factor * effective table selectivity)


             Case Name                                     Estimate Cost                     Original Cost

             Case 1                                        1+(190*0.000285+84136*0.000285)   26
                                                           =25.03
             Case 2                                        1+190*0.000285=1.05               2

             Case 3                                        1+190*0.480315=92.25              93




© 2011 Cisco and/or its affiliates. All rights reserved.                                                     Cisco Confidential   31
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   32
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   33
Cost= blevel + min cost of index +(clustering_factor * effective table
 selectivity)



            Case Name                                      Estimate Cost             Original Cost

            Case 1                                         0+1=1                     1

            Case 2                                         0+5*1+12000*0.000417=10   10




© 2011 Cisco and/or its affiliates. All rights reserved.                                             Cisco Confidential   34
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   35
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   36
Cost = blevel + ( leaf_blocks * effective index selectivity *
    max(NUM_DISTINCT(skipped columns)))+ clustering_factor *
    effective table selectivity
Notice: need set _optimizer_skip_scan_enabled                                                      = true


             Case Name                                     Estimate Cost                     Original Cost


             Case 1                                        1+(264*0.000027*36572+91723*0.0   268
                                                           00027)=264.16

             Case 2                                        1+(110*0.000040*24724+39949*0.0   113
                                                           00040)=111.38




© 2011 Cisco and/or its affiliates. All rights reserved.                                                     Cisco Confidential   37
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   38
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   39
Cost=cost of accessing outer table + (cardinality of outer table *
 cost of accessing inner table )
Nest Loop Join :
       Cost(T1)= 1+(21* 0.001721+9153*0.001721)=16.78
         Cost(T2)=1+1
       Cost(case1)=17+17*2=51 not equal 34 why?
      Adjusted Cost(case1)=17+17*1=34
       Cost(case2)=1+(21*0.00142+9153*0.00142)+14.02*1=28.04




© 2011 Cisco and/or its affiliates. All rights reserved.       Cisco Confidential   40
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   41
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   42
Cost = (cost of accessing outer table) + (cost of building hash table) + (cost of
  accessing inner table )
Cost=( NBLKS/ k )+1 (if _table_scan_cost_plus_one = true)
Cost =blevel +( leaf_blocks * effective index selectivity +     clustering_factor *
  effective table selectivity)
Cost(hash build)=(Probe passes+1)*(large table block/k)+(small table/k)
Hash Join :
             Cost(T1)=1+ 171/10.40=17.44
             Cost(T2)=1+ 1495/10.40=144.75
             Cost(hash build)=2*(1495/16.06)+171/16.06= 196.8
             Cost(case1)=18+145+ 197= 360 != 391 (k=13.8)
             Cost(T1)=1+ 171/10.40=17.44
             Cost (T2)=1+ 191+ 1463=1655
             Cost(case 2)=1655+18= 1673

© 2011 Cisco and/or its affiliates. All rights reserved.                            Cisco Confidential   43
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   44
cost = (cost of accessing outer table + outer sort cost) + (cost of accessing
  inner table + inner sort cost)
Cost =blevel +( leaf_blocks * effective index selectivity +
 clustering_factor * effective table selectivity)
Sort Merge Join :
        Cost(T1)= 1+(21* 0.001721+9153*0.001721)=16.78
        Cost(T2)=1+(191*1)+1*1463 =192+1463=1655
        Cost(sort outer)=120
        Cost(sort inner)=0 (unique index)
        Cost(case1)=1655+120+0+17=1792




© 2011 Cisco and/or its affiliates. All rights reserved.             Cisco Confidential   45
• What’s effect from “OPTIMIZER_INDEX_COST_ADJ”?

• What’s effect from parallelism degree?

• What’s effect from “Optimizer_Index_Caching”?




© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   46
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   47
• Cost = IO Cost+ (#CPUCost/cpuspeed)/sreadtim/1000) OR
       (BLOCKS/MRBC)*(mreadtim/sreadtim)+((#CPUCost/cpuspeed)/s
       readtim/1000)
• MRBC- number of multi block reads

• sreadtim is set to ioseektim + db_block_size/iotrfrspeed

• mreadtim is set to ioseektim + db_file_multiblock_read_count *
       db_block_size/iotftspeed
• Notice: you can get these data from aux_stats$ table




© 2011 Cisco and/or its affiliates. All rights reserved.     Cisco Confidential   48
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   49
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   50
Cost=(BLOCKS/MRBC)*(mreadtim/sreadtim)+((#CPUCost/cpuspee
 d)/sreadtim/1000) sreadtim is set to ioseektim +
 db_block_size/iotrfrspeed
Sreadtim=18+8192/21110=18.39
Mreadtim=18+16*8192/21110=24.21

          Case Name CPU Cost                                                    Estimate Cost           Original Cost


          Case 1                                           round(3117766/(1414 0+ceil(ceil(171/16)*24. 16
                                                           *1000*18.38)=0      21/18.39)+1+0=16

          Case 2                                           round(28085703/(141 0+ceil(ceil(1495/16)*2   126
                                                           4*1000*18.38)=1     4.21/18.39)+1+1=126



© 2011 Cisco and/or its affiliates. All rights reserved.                                                       Cisco Confidential   51
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   52
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   53
Cost = IO Cost+ (#CPUCost/cpuspeed)/sreadtim/1000)
Sreadtim=18+8192/21110=18.39
Mreadtim=18+16*8192/21110=24.21


          Case Name CPU Cost                                                    Estimate Cost   Original Cost


          Case 1                                           round(19717195/141   191*1+1=192     192
                                                           4/18.39/1000)=1

          Case 2                                           round(14443/1414/18 1+1+0=2          2
                                                           .39/1000) =0




© 2011 Cisco and/or its affiliates. All rights reserved.                                               Cisco Confidential   54
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   55
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   56
Cost=blevel+(BLOCKS/MRBC)*(mreadtim/sreadtim)+((#CPUCost/c
 puspeed)/sreadtim/1000)
Sreadtim=18+8192/21110=18.39
Mreadtim(1)=18+16*8192/21110=24.21
Mreadtim(2)=18+8*8192/21110=21.1

          Case Name CPU Cost                                                   Estimate Cost          Original Cost


          Case 1                                           round(19278250/(141 1+12*(24.21/18.39)+1   18
                                                           4*18.39*1000))=1    =18

          Case 2                                           round(19278250/(141 1+24*(21.1/18.39)+1=   30
                                                           4*18.39*1000))=1    30


© 2011 Cisco and/or its affiliates. All rights reserved.                                                     Cisco Confidential   57
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   58
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   59
Cost= IO Cost+ (#CPUCost/cpuspeed)/sreadtim/1000)
Sreadtim=18+8192/21110=18.39
Mreadtim=18+16*8192/21110=24.21

          Case Name CPU Cost                                                   Estimate Cost         Original Cost


          Case 1                                           round(202809         1+ceil((190*0.000288+ 27
                                                           /(1414*18.39*1000))= 84136*0.000288))+0=
                                                           0                    26
          Case 2                                           round(9169130        1+ceil(190*0.464567)+ 90
                                                           /(1414*18.39*1000))= 0=90
                                                           0



© 2011 Cisco and/or its affiliates. All rights reserved.                                                    Cisco Confidential   60
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   61
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   62
Cost = IO Cost+ (#CPUCost/cpuspeed)/sreadtim/1000)


          Case Name CPU Cost                                                     Estimate Cost   Original Cost


          Case 1                                           round(8171/1414/18.   0+1             1
                                                           39/1000) =0

          Case 2                                           round(108772          0+5+5=10        9
                                                           /1414/18.39/1000)=0




© 2011 Cisco and/or its affiliates. All rights reserved.                                                Cisco Confidential   63
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   64
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   65
Cost= IO Cost+ (#CPUCost/cpuspeed)/sreadtim/1000)
Sreadtim=18+8192/21110=18.39
Mreadtim=18+16*8192/21110=24.21

        Case Name CPU Cost                                               Estimate Cost          Original Cost


        Case 1                                       round(1909776        1+(264*0.000027*365   268
                                                     /(1414*18.39*1000))= 72+91723*0.000027)+
                                                     0                    0=264
        Case 2                                       round(805543         1+((110*0.000040*247 113
                                                     /(1414*18.39*1000))= 24)+39949*0.000040)
                                                     0                    +0=112



© 2011 Cisco and/or its affiliates. All rights reserved.                                                Cisco Confidential   66
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   67
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   68
Cost=cost of accessing outer table + (cardinality of outer table * cost of
 accessing inner table )
Nest Loop Join :
      Cost(CPU) =round(3418106/1414/18.39/1000)=0
      Cost(T1)= ((171/16)*24.21/18.39)+1 = 15.07
        Cost(T2)=1+0
      Cost(case1)= 15.07 + 15.07 *1= 30.14
      Cost(T1-CPU) =round(106010/1414/18.39/1000)=0
      Cost(T2-CPU) =round(234970/1414/18.39/1000)=0
        Cost(T1) =1+21*0.00142+9153*0.00142=14.02
      Cost(case2)=14.02+14.02*1=28.04




© 2011 Cisco and/or its affiliates. All rights reserved.                 Cisco Confidential   69
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   70
© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   71
Cost = (cost of accessing outer table) + (cost of building hash table) + (cost of accessing inner table )
Cost=(BLOCKS/MRBC)*(mreadtim/sreadtim)+((#CPUCost/cpuspeed)/sreadtim/1000)+1
 Cost(hash build)=(Probe passes+1)*(large table block/MRBC)+(small table/MRBC)
Hash Join :
          Cost(T1-CPU)=round(3117766/(1414*18.39*1000))=0
          Cost(T2-CPU)=round((28085703/(1414*18.39*1000)))=1
          Cost(T1)=1+ (171/16)*24.21/18.39+0= 15.07,       Cost(T2)=1+ (1495/16)*24.21/18.39+1=125
          Cost(build Hash CPU)= 178640101/(1414*18.39*1000)= 6.87
          Cost(case1)=15.07+125+ 6.87 = 146.94
          Cost(T4-CPU)=round((30493428/(1414*18.39*1000)))=1
          Cost(T2)=1+ (1495/16)*24.21/18.39+1=125 , Cost(T4)=1+ (1575/16)*24.21/18.39+1=131.59
          Cost(build Hash CPU)= 128949682/(1414*18.39*1000)= 4.96
            Cost(hash build)=2*(1575/16)+ (1495/16)=290
            Cost(case2)=125+132+5+290= 552


© 2011 Cisco and/or its affiliates. All rights reserved.                                             Cisco Confidential   72
• Wolfgang Breitling, A LOOK UNDER THE HOOD OF CBO: THE
       10053 EVENT
• Wolfgang Breitling, The Effects of optimizer_index_cost_adj and
       optimizer_index_caching on Access Plans
• Jonathan Lewis , Cost-Based Oracle Fundamentals
• Alberto Dell'Era, New Density calculation in 11g
• Chris Antognini ,CBO – A Configuration Roadmap
• Juliandyke,http://www.juliandyke.com/Diagnostics/Events/EventR
       eference.html
• http://mikixiyou.iteye.com/blog/1709321
• http://www.oaktable.net/category/tags/system-statistics
© 2011 Cisco and/or its affiliates. All rights reserved.    Cisco Confidential   73
Thank you.




© 2011 Cisco and/or its affiliates. All rights reserved.   Cisco Confidential   74

More Related Content

Viewers also liked

Project m
Project mProject m
Project m
Alex Wu
 
Ch mid year review slideshare_v2.1
Ch mid year review slideshare_v2.1Ch mid year review slideshare_v2.1
Ch mid year review slideshare_v2.1
LiLing See
 
Post new korean cinema
Post new korean cinemaPost new korean cinema
Post new korean cinema
문정 최
 
834 d4c61 5562-4adc-958a9b7e7ad30c57
834 d4c61 5562-4adc-958a9b7e7ad30c57834 d4c61 5562-4adc-958a9b7e7ad30c57
834 d4c61 5562-4adc-958a9b7e7ad30c57
Carlos Carvalho
 
Middle Ages/Canterbury Tales
Middle Ages/Canterbury TalesMiddle Ages/Canterbury Tales
Middle Ages/Canterbury Tales
ms_faris
 
Τα δημογραφικά δεδομένα του μεταεπαναστατικού Ελληνικού Πολεμικού Ναυτικού πα...
Τα δημογραφικά δεδομένα του μεταεπαναστατικού Ελληνικού Πολεμικού Ναυτικού πα...Τα δημογραφικά δεδομένα του μεταεπαναστατικού Ελληνικού Πολεμικού Ναυτικού πα...
Τα δημογραφικά δεδομένα του μεταεπαναστατικού Ελληνικού Πολεμικού Ναυτικού πα...
leonvit2005
 

Viewers also liked (20)

C 3
C 3C 3
C 3
 
Getting into things
Getting into thingsGetting into things
Getting into things
 
Project m
Project mProject m
Project m
 
Tek13 - Creating Mobile Apps with PHP and Symfony
Tek13 - Creating Mobile Apps with PHP and SymfonyTek13 - Creating Mobile Apps with PHP and Symfony
Tek13 - Creating Mobile Apps with PHP and Symfony
 
Ch mid year review slideshare_v2.1
Ch mid year review slideshare_v2.1Ch mid year review slideshare_v2.1
Ch mid year review slideshare_v2.1
 
Finitio - Data deserves a language too
Finitio - Data deserves a language tooFinitio - Data deserves a language too
Finitio - Data deserves a language too
 
Imperia esfera gurgaon 37 c Imperia 7428424386
Imperia esfera  gurgaon 37 c Imperia 7428424386Imperia esfera  gurgaon 37 c Imperia 7428424386
Imperia esfera gurgaon 37 c Imperia 7428424386
 
Post new korean cinema
Post new korean cinemaPost new korean cinema
Post new korean cinema
 
Guión ingles
Guión inglesGuión ingles
Guión ingles
 
Data Collection
Data CollectionData Collection
Data Collection
 
834 d4c61 5562-4adc-958a9b7e7ad30c57
834 d4c61 5562-4adc-958a9b7e7ad30c57834 d4c61 5562-4adc-958a9b7e7ad30c57
834 d4c61 5562-4adc-958a9b7e7ad30c57
 
Bab 2 cookbook reload fahrudin
Bab 2 cookbook reload fahrudinBab 2 cookbook reload fahrudin
Bab 2 cookbook reload fahrudin
 
Comicus2012
Comicus2012Comicus2012
Comicus2012
 
Job's portflio
Job's portflioJob's portflio
Job's portflio
 
Nltrv55
Nltrv55Nltrv55
Nltrv55
 
The Implementation of CSR in European Football by Geoff Walters
The Implementation of CSR in European Football by Geoff WaltersThe Implementation of CSR in European Football by Geoff Walters
The Implementation of CSR in European Football by Geoff Walters
 
All in one
All in oneAll in one
All in one
 
Middle Ages/Canterbury Tales
Middle Ages/Canterbury TalesMiddle Ages/Canterbury Tales
Middle Ages/Canterbury Tales
 
affTA03 - BAB III
affTA03 - BAB IIIaffTA03 - BAB III
affTA03 - BAB III
 
Τα δημογραφικά δεδομένα του μεταεπαναστατικού Ελληνικού Πολεμικού Ναυτικού πα...
Τα δημογραφικά δεδομένα του μεταεπαναστατικού Ελληνικού Πολεμικού Ναυτικού πα...Τα δημογραφικά δεδομένα του μεταεπαναστατικού Ελληνικού Πολεμικού Ναυτικού πα...
Τα δημογραφικά δεδομένα του μεταεπαναστατικού Ελληνικού Πολεμικού Ναυτικού πα...
 

Similar to How to estimate_oracle_cost

Similar to How to estimate_oracle_cost (7)

CCNA Icnd110 s04l02
CCNA Icnd110 s04l02CCNA Icnd110 s04l02
CCNA Icnd110 s04l02
 
Let’s talk about microbenchmarking
Let’s talk about microbenchmarkingLet’s talk about microbenchmarking
Let’s talk about microbenchmarking
 
Presentation cisco prime for ip ngn technical education series introduction...
Presentation   cisco prime for ip ngn technical education series introduction...Presentation   cisco prime for ip ngn technical education series introduction...
Presentation cisco prime for ip ngn technical education series introduction...
 
ADE UNIT-III (Digital Fundamentals).pptx
ADE UNIT-III (Digital Fundamentals).pptxADE UNIT-III (Digital Fundamentals).pptx
ADE UNIT-III (Digital Fundamentals).pptx
 
Deep Dive on ClickHouse Sharding and Replication-2202-09-22.pdf
Deep Dive on ClickHouse Sharding and Replication-2202-09-22.pdfDeep Dive on ClickHouse Sharding and Replication-2202-09-22.pdf
Deep Dive on ClickHouse Sharding and Replication-2202-09-22.pdf
 
A Layered Architecture for the Model-driven Development of Distributed Simula...
A Layered Architecture for the Model-driven Development of Distributed Simula...A Layered Architecture for the Model-driven Development of Distributed Simula...
A Layered Architecture for the Model-driven Development of Distributed Simula...
 
PROACT SYNC 2013 - Breakout - End to End uitleg over Cisco UCS
PROACT SYNC 2013 - Breakout - End to End uitleg over Cisco UCSPROACT SYNC 2013 - Breakout - End to End uitleg over Cisco UCS
PROACT SYNC 2013 - Breakout - End to End uitleg over Cisco UCS
 

More from Philip Zhong (13)

How to Implement Distributed Data Store
How to Implement Distributed Data Store How to Implement Distributed Data Store
How to Implement Distributed Data Store
 
MongoDB Knowledge Shareing
MongoDB Knowledge ShareingMongoDB Knowledge Shareing
MongoDB Knowledge Shareing
 
Adapter Poxy Pattern
Adapter Poxy PatternAdapter Poxy Pattern
Adapter Poxy Pattern
 
Mongo db program_installation_guide
Mongo db program_installation_guideMongo db program_installation_guide
Mongo db program_installation_guide
 
Mongo db sharding_cluster_installation_guide
Mongo db sharding_cluster_installation_guideMongo db sharding_cluster_installation_guide
Mongo db sharding_cluster_installation_guide
 
Vitess percona 2012
Vitess percona 2012Vitess percona 2012
Vitess percona 2012
 
Distributed_Database_System
Distributed_Database_SystemDistributed_Database_System
Distributed_Database_System
 
Mysql performance tuning
Mysql performance tuningMysql performance tuning
Mysql performance tuning
 
Mysql5.1 character set testing
Mysql5.1 character set testingMysql5.1 character set testing
Mysql5.1 character set testing
 
How to write_language_compiler
How to write_language_compilerHow to write_language_compiler
How to write_language_compiler
 
Compare mysql5.1.50 mysql5.5.8
Compare mysql5.1.50 mysql5.5.8Compare mysql5.1.50 mysql5.5.8
Compare mysql5.1.50 mysql5.5.8
 
Mysql handle socket
Mysql handle socketMysql handle socket
Mysql handle socket
 
Mysql architecture&parameters
Mysql architecture&parametersMysql architecture&parameters
Mysql architecture&parameters
 

How to estimate_oracle_cost

  • 1. How to estimate oracle cost Philip Zhong Sina WeiBo:@离叔-菲利普 Blog: Philipzhong.blogspot.com 2013-2-18 © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 1
  • 2. • Important Statistics Values and Parameters • Cardinality and Selectivity • IO Cost model • New Cost model © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 2
  • 3. Table Statistics: Number of table blocks(BLOCKS) Number of table rows(NUM_ROWS) Index Statistics: Levels of the index(BLEVEL) Number of leaf blocks (LEAF_BLOCKS) Clustering factor(CLUSTERING_FACTOR) Number of distinct keys(DISTINCT_KEYS) Column Statistics: Number of distinct values(NUM_DISTINCT) Number of NULL values(NUM_NULLS) Density © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 3
  • 4. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 4
  • 5. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 5
  • 6. • NUM_DISTINCT=number of distinct value • Base Cardinality = number of rows of the table • FF=filter factor of the condition=1 / NUM_DISTINCT(column) • Selectivity = FF= Estimated cardinality /Base Cardinality • Estimated Cardinality = Selectivity * Base Cardinality © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 6
  • 7. • C1=value  1/NUM_DISTINCT • C1 like value  1/NUM_DISTINCT • C1>value  ((Hi-Value)/(Hi-Lo)) • C1<value  ((Value-Lo)/(Hi-Lo)) • C1>=value  ((Hi-Value)/(Hi-Lo))+1/NUM_DISTINCT • C1<=value  ((Value-Lo)/(Hi-Lo))+1/NUM_DISTINCT • C1 between value1 and value2  ((value2 – value1)/(Hi- Lo))+2/NUM_DISTINCT • Notice: if column is NULL Adjusted selectivity = Base selectivity * (1 - num_nulls/num_rows) © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 7
  • 8. • C1=:B1  C1.Density • C1 like :B1  { 0.05 | C1.Density } • C1 { < | <= | > | >= } :B1 C1.Density • C1 between :B1 and :B2  C1.Density*C2. Density • Notice: if column is NULL Adjusted selectivity = C1.Density * ( 1 - num_nulls/ num_rows ) © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 8
  • 9. • C1 and C2  FF1 * FF2 • C1 or C2  FF1 + FF2 - FF1 * FF2 • Not C1  1-FF1 © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 9
  • 10. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 10
  • 11. • Full Table Scan: Cost=( NBLKS/ k )+1 (if _table_scan_cost_plus_one = true) • Non-Index costing: Cost = blevel + (leaf_blocks * effective index selectivity) +(clustering_factor * effective table selectivity) • Unique-Index costing: Cost=blevel + min cost of index +(clustering_factor * effective table selectivity) • Join cost: NESTED LOOP JOIN cost = cost of accessing outer table + (cardinality of outer table * cost of accessing inner table ) SORT MERGE JOIN cost = (cost of accessing outer table + outer sort cost) + (cost of accessing inner table + inner sort cost) HASH JOIN cost = (cost of accessing outer table) + (cost of building hash table) + (cost of accessing inner table ) © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 11
  • 12. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 12
  • 13. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 13
  • 14. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 14
  • 15. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 15
  • 16. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 16
  • 17. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 17
  • 18. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 18
  • 19. • Cost Calculation formula: Cost= (NBLKS/ k)+1 (if _table_scan_cost_plus_one = true) Case Name Estimate Cost Original Cost Case 1 171/10.40+1=17.44 18 Case 2 1495/10.40+1=144.75 145 Case 3 12151/10.40+1=1169.37 1170 Case 4 12151/6.59+1=1844.85 1846 © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 19
  • 20. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 20
  • 21. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 21
  • 22. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 22
  • 23. Cost = blevel +( leaf_blocks * effective index selectivity + clustering_factor * effective table selectivity) Case Name Estimate Cost Original Cost Case 1 1+(190*1)=191 191 Case 2 1+1=2 2 Case 3 1+(264*1+91723* 0.000027)=267.48 268 © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 23
  • 24. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 24
  • 25. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 25
  • 26. Cost = blevel + ( leaf_blocks * effective index selectivity/k) Case Name Estimate Cost Original Cost Case 1 1+(190*1/10.40)=19.27 20 Case 2 1+(190*1/6.59)=29.83 30 © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 26
  • 27. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 27
  • 28. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 28
  • 29. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 29
  • 30. • NewDensity = [ (BktCnt - PopBktCnt) / BktCnt ] / (NDV - PopValCnt) • NewDensity=((254-12)/254)/(717-6)=0.001340022 © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 30
  • 31. Cost = blevel + (leaf_blocks * effective index selectivity + clustering_factor * effective table selectivity) Case Name Estimate Cost Original Cost Case 1 1+(190*0.000285+84136*0.000285) 26 =25.03 Case 2 1+190*0.000285=1.05 2 Case 3 1+190*0.480315=92.25 93 © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 31
  • 32. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 32
  • 33. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 33
  • 34. Cost= blevel + min cost of index +(clustering_factor * effective table selectivity) Case Name Estimate Cost Original Cost Case 1 0+1=1 1 Case 2 0+5*1+12000*0.000417=10 10 © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 34
  • 35. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 35
  • 36. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 36
  • 37. Cost = blevel + ( leaf_blocks * effective index selectivity * max(NUM_DISTINCT(skipped columns)))+ clustering_factor * effective table selectivity Notice: need set _optimizer_skip_scan_enabled = true Case Name Estimate Cost Original Cost Case 1 1+(264*0.000027*36572+91723*0.0 268 00027)=264.16 Case 2 1+(110*0.000040*24724+39949*0.0 113 00040)=111.38 © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 37
  • 38. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 38
  • 39. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 39
  • 40. Cost=cost of accessing outer table + (cardinality of outer table * cost of accessing inner table ) Nest Loop Join : Cost(T1)= 1+(21* 0.001721+9153*0.001721)=16.78 Cost(T2)=1+1 Cost(case1)=17+17*2=51 not equal 34 why? Adjusted Cost(case1)=17+17*1=34 Cost(case2)=1+(21*0.00142+9153*0.00142)+14.02*1=28.04 © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 40
  • 41. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 41
  • 42. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 42
  • 43. Cost = (cost of accessing outer table) + (cost of building hash table) + (cost of accessing inner table ) Cost=( NBLKS/ k )+1 (if _table_scan_cost_plus_one = true) Cost =blevel +( leaf_blocks * effective index selectivity + clustering_factor * effective table selectivity) Cost(hash build)=(Probe passes+1)*(large table block/k)+(small table/k) Hash Join : Cost(T1)=1+ 171/10.40=17.44 Cost(T2)=1+ 1495/10.40=144.75 Cost(hash build)=2*(1495/16.06)+171/16.06= 196.8 Cost(case1)=18+145+ 197= 360 != 391 (k=13.8) Cost(T1)=1+ 171/10.40=17.44 Cost (T2)=1+ 191+ 1463=1655 Cost(case 2)=1655+18= 1673 © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 43
  • 44. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 44
  • 45. cost = (cost of accessing outer table + outer sort cost) + (cost of accessing inner table + inner sort cost) Cost =blevel +( leaf_blocks * effective index selectivity + clustering_factor * effective table selectivity) Sort Merge Join : Cost(T1)= 1+(21* 0.001721+9153*0.001721)=16.78 Cost(T2)=1+(191*1)+1*1463 =192+1463=1655 Cost(sort outer)=120 Cost(sort inner)=0 (unique index) Cost(case1)=1655+120+0+17=1792 © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 45
  • 46. • What’s effect from “OPTIMIZER_INDEX_COST_ADJ”? • What’s effect from parallelism degree? • What’s effect from “Optimizer_Index_Caching”? © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 46
  • 47. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 47
  • 48. • Cost = IO Cost+ (#CPUCost/cpuspeed)/sreadtim/1000) OR (BLOCKS/MRBC)*(mreadtim/sreadtim)+((#CPUCost/cpuspeed)/s readtim/1000) • MRBC- number of multi block reads • sreadtim is set to ioseektim + db_block_size/iotrfrspeed • mreadtim is set to ioseektim + db_file_multiblock_read_count * db_block_size/iotftspeed • Notice: you can get these data from aux_stats$ table © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 48
  • 49. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 49
  • 50. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 50
  • 51. Cost=(BLOCKS/MRBC)*(mreadtim/sreadtim)+((#CPUCost/cpuspee d)/sreadtim/1000) sreadtim is set to ioseektim + db_block_size/iotrfrspeed Sreadtim=18+8192/21110=18.39 Mreadtim=18+16*8192/21110=24.21 Case Name CPU Cost Estimate Cost Original Cost Case 1 round(3117766/(1414 0+ceil(ceil(171/16)*24. 16 *1000*18.38)=0 21/18.39)+1+0=16 Case 2 round(28085703/(141 0+ceil(ceil(1495/16)*2 126 4*1000*18.38)=1 4.21/18.39)+1+1=126 © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 51
  • 52. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 52
  • 53. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 53
  • 54. Cost = IO Cost+ (#CPUCost/cpuspeed)/sreadtim/1000) Sreadtim=18+8192/21110=18.39 Mreadtim=18+16*8192/21110=24.21 Case Name CPU Cost Estimate Cost Original Cost Case 1 round(19717195/141 191*1+1=192 192 4/18.39/1000)=1 Case 2 round(14443/1414/18 1+1+0=2 2 .39/1000) =0 © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 54
  • 55. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 55
  • 56. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 56
  • 57. Cost=blevel+(BLOCKS/MRBC)*(mreadtim/sreadtim)+((#CPUCost/c puspeed)/sreadtim/1000) Sreadtim=18+8192/21110=18.39 Mreadtim(1)=18+16*8192/21110=24.21 Mreadtim(2)=18+8*8192/21110=21.1 Case Name CPU Cost Estimate Cost Original Cost Case 1 round(19278250/(141 1+12*(24.21/18.39)+1 18 4*18.39*1000))=1 =18 Case 2 round(19278250/(141 1+24*(21.1/18.39)+1= 30 4*18.39*1000))=1 30 © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 57
  • 58. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 58
  • 59. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 59
  • 60. Cost= IO Cost+ (#CPUCost/cpuspeed)/sreadtim/1000) Sreadtim=18+8192/21110=18.39 Mreadtim=18+16*8192/21110=24.21 Case Name CPU Cost Estimate Cost Original Cost Case 1 round(202809 1+ceil((190*0.000288+ 27 /(1414*18.39*1000))= 84136*0.000288))+0= 0 26 Case 2 round(9169130 1+ceil(190*0.464567)+ 90 /(1414*18.39*1000))= 0=90 0 © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 60
  • 61. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 61
  • 62. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 62
  • 63. Cost = IO Cost+ (#CPUCost/cpuspeed)/sreadtim/1000) Case Name CPU Cost Estimate Cost Original Cost Case 1 round(8171/1414/18. 0+1 1 39/1000) =0 Case 2 round(108772 0+5+5=10 9 /1414/18.39/1000)=0 © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 63
  • 64. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 64
  • 65. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 65
  • 66. Cost= IO Cost+ (#CPUCost/cpuspeed)/sreadtim/1000) Sreadtim=18+8192/21110=18.39 Mreadtim=18+16*8192/21110=24.21 Case Name CPU Cost Estimate Cost Original Cost Case 1 round(1909776 1+(264*0.000027*365 268 /(1414*18.39*1000))= 72+91723*0.000027)+ 0 0=264 Case 2 round(805543 1+((110*0.000040*247 113 /(1414*18.39*1000))= 24)+39949*0.000040) 0 +0=112 © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 66
  • 67. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 67
  • 68. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 68
  • 69. Cost=cost of accessing outer table + (cardinality of outer table * cost of accessing inner table ) Nest Loop Join : Cost(CPU) =round(3418106/1414/18.39/1000)=0 Cost(T1)= ((171/16)*24.21/18.39)+1 = 15.07 Cost(T2)=1+0 Cost(case1)= 15.07 + 15.07 *1= 30.14 Cost(T1-CPU) =round(106010/1414/18.39/1000)=0 Cost(T2-CPU) =round(234970/1414/18.39/1000)=0 Cost(T1) =1+21*0.00142+9153*0.00142=14.02 Cost(case2)=14.02+14.02*1=28.04 © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 69
  • 70. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 70
  • 71. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 71
  • 72. Cost = (cost of accessing outer table) + (cost of building hash table) + (cost of accessing inner table ) Cost=(BLOCKS/MRBC)*(mreadtim/sreadtim)+((#CPUCost/cpuspeed)/sreadtim/1000)+1 Cost(hash build)=(Probe passes+1)*(large table block/MRBC)+(small table/MRBC) Hash Join : Cost(T1-CPU)=round(3117766/(1414*18.39*1000))=0 Cost(T2-CPU)=round((28085703/(1414*18.39*1000)))=1 Cost(T1)=1+ (171/16)*24.21/18.39+0= 15.07, Cost(T2)=1+ (1495/16)*24.21/18.39+1=125 Cost(build Hash CPU)= 178640101/(1414*18.39*1000)= 6.87 Cost(case1)=15.07+125+ 6.87 = 146.94 Cost(T4-CPU)=round((30493428/(1414*18.39*1000)))=1 Cost(T2)=1+ (1495/16)*24.21/18.39+1=125 , Cost(T4)=1+ (1575/16)*24.21/18.39+1=131.59 Cost(build Hash CPU)= 128949682/(1414*18.39*1000)= 4.96 Cost(hash build)=2*(1575/16)+ (1495/16)=290 Cost(case2)=125+132+5+290= 552 © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 72
  • 73. • Wolfgang Breitling, A LOOK UNDER THE HOOD OF CBO: THE 10053 EVENT • Wolfgang Breitling, The Effects of optimizer_index_cost_adj and optimizer_index_caching on Access Plans • Jonathan Lewis , Cost-Based Oracle Fundamentals • Alberto Dell'Era, New Density calculation in 11g • Chris Antognini ,CBO – A Configuration Roadmap • Juliandyke,http://www.juliandyke.com/Diagnostics/Events/EventR eference.html • http://mikixiyou.iteye.com/blog/1709321 • http://www.oaktable.net/category/tags/system-statistics © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 73
  • 74. Thank you. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 74

Editor's Notes

  1. Bitmap index cost
  2. Join Selectivity = 1/max( ndvA, ndvB)* cardA * cardB
  3. C1 like :B1  { 0.05 | C1.Density }:Depending on whether the undocumented init.ora parameter _LIKE_WITH_BIND_AS_EQUALITY is false (the default) or true.
  4. LVLS BLEVEL The height of the index b-tree #LB LEAF_BLOCKS The number of leaf blocks #DK DISTINCT_KEYS The number of distinct keys of the index LB/K AVG_LEAF_BLOCKS_PER_KEY The average number of leaf blocks per key DB/K AVG_DATA_BLOCKS_PER_KEY The average number of data blocks per key CLUF CLUSTERING_FACTOR The clustering factor of the index
  5. http://blog.csdn.net/tianlesoftware/article/details/4668723Height-Balanced Histograms:
  6. We have a range of 11—running from 1 to 12. The right-hand edge hits zero at month_no = 23(high value + 11); the left-hand edge hits zero at month_no = -10 (low value – 11).This will be bad news to some people. If you have sequence, or time-based, values in acommonly queried column and haven’t been keeping the statistics up to date, then queriesthat use an equality on that column will have been using a flat line to give you the right answeras time passes. Now, those same queries are going to give you cardinalities that keep droppingas time passes—until suddenly, the cardinality gets so low that plans may change dramatically.Cases 19 and 20 (ranges outside the recorded low/high range): The optimizer detectsthat the query falls outside the known range, and seems to return a selectivity, hencecardinality that would be correct for column = constant. (There is a nasty boundary case,though, that appears from 9i onwards when every row holds the same value.)
  7. Using prorated density: 0.001420 of col #2 as selectvity of out-of-range/non-existent value pred
  8. Don’t get overly exited over the 0 cost of a unique index lookup in an NL join. It would appear to make NL joins with this kind of index access, e.g. a fully qualified primary key join predicate, cost free.
  9. (Prob+1)*round(1495/10.40)+round(171/10.40)=2*144
  10. We Can open another topic for hash/SM/NL
  11. Don’t get overly exited over the 0 cost of a unique index lookup in an NL join. It would appear to make NL joins with this kind of index access, e.g. a fully qualified primary key join predicate, cost free.
  12. Full Table Scan: BLOCKS(table) / MBRC / parallelismdegree+ 1Index UniqueScan: (BLEVEL(index) + 1) * OPTIMIZER_INDEX_COST_ADJ / 100Index Unique Scan + Table Access by Index ROWID: (BLEVEL(index) + 2) * OPTIMIZER_INDEX_COST_ADJ / 100Index Full Scan: (BLEVEL(index) + LEAF_BLOCKS(index)) * OPTIMIZER_INDEX_COST_ADJ / 100Index Fast Full Scan: BLEVEL(index) + LEAF_BLOCKS(index) / MBRC / parallelismdegree+ 1Index Range Scan: (BLEVEL(index) + LEAF_BLOCKS(index) * FF1) / OPTIMIZER_INDEX_COST_ADJ * 100Index Range Scan+ Table Access by Index ROWID: (BLEVEL(index) + LEAF_BLOCKS(index) * FF1 + CLUSTERING_FACTOR(index) * FF2) * OPTIMIZER_INDEX_COST_ADJ / 100Index SkipScan: max(NUM_DISTINCT(skipped_columns)) * (BLEVEL(index) + LEAF_BLOCKS(index) * FF1) * OPTIMIZER_INDEX_COST_ADJ / 100Index SkipScan+ Table Access byIndex ROWID: max(NUM_DISTINCT(skipped_columns)) * (BLEVEL(index) + LEAF_BLOCKS(index) * FF1 + CLUSTERING_FACTOR(index) * FF2) * OPTIMIZER_INDEX_COST_ADJ / 100
  13. exec DBMS_STATS.GATHER_SYSTEM_STATS(&apos;NOWORKLOAD&apos;);execute dbms_stats.gather_system_stats(&apos;start&apos;);execute dbms_stats.gather_system_stats(&apos;stop&apos;);
  14. http://www.oaktable.net/category/tags/system-statistics
  15. If _table_scan_cost_plus_one=true, need +1
  16. We Can open another topic for hash/SM/NL
  17. We Can open another topic for hash/SM/NL
  18. We Can open another topic for hash/SM/NL
  19. We Can open another topic for hash/SM/NL
  20. We Can open another topic for hash/SM/NL
  21. Using prorated density: 0.001420 of col #2 as selectvity of out-of-range/non-existent value pred
  22. Don’t get overly exited over the 0 cost of a unique index lookup in an NL join. It would appear to make NL joins with this kind of index access, e.g. a fully qualified primary key join predicate, cost free.
  23. (Prob+1)*round(1495/10.40)+round(171/10.40)=2*144+
  24. (if _table_scan_cost_plus_one = true)