Click here to load reader

Introduction to oracle optimizer

Embed Size (px)

Citation preview

  • 1. Introduction to Oracle Optimizer Heribertus Bramundito

2. Agenda Our Environment Heap Table Histogram Oracle Optimizer Cost Selectivity & Cardinality Clustering Factor Access Method Partitioning Join Method Sub-query Hint 3. Our Environment Heap Table This is default table when we issue the CREATE TABLEstatement Data is stored in random fashion, no specific sort of order (best fit algorithm)3 4. Our Environment Heap Table (result from table access)4 5. Our Environment Heap Table (result from index access)5 6. Our Environment IOT Table (a comparison)6 7. Our Environment Histogram Collection of information about data distribution inspecific column Oracle maintains 2 types of histogram: frequency and height-balanced Oracle use histogram as additional information when deciding whether to use index scan or table scan7 8. Our Environment Histogram (column without histogram)8 9. Our Environment Histogram (create histogram)9 10. Our Environment Histogram (column with histogram)10 11. Agenda Our Environment Heap Table Histogram Oracle Optimizer Cost Selectivity & Cardinality Clustering Factor Access Method Partitioning Join Method Sub-query Hint 12. Cost Jonathan Lewis: The cost represents the optimizers best estimate of thetime it will take to execute the statement A result of the calculation performed by optimizer Few conditions that make CBO produces wrong result No statistics on the underlying objects or statistics are obsolete Performance characteristics of hardware or current workloads are not known Bug From Oracle Performance Tuning Guide and ReferenceCost = (#SRds * sreadtim + #MRds * mreadtim + #CPUCycles / cpuspeed) / sreadtim #SRds: number of single data block reads #MRds: number of multi data block reads #CPUCycle: number of CPU cycles sreadtim: single block read time mreadtim: multi block read time cpuspeed: CPU cycles per second 12 13. Cost (the calculation) #SRds = blevel + #leaf_block * idx_sel + clustering_factor * tbl_sel (index scan) #MRds = #tbl_blocks under HWM / mbrc (full table/ index scan) sreadtim = ioseektim + block_size * iotfrspeed (SREADTIM) mreadtim = ioseektim + mbrc * block_size * iotfrspeed (MREADTIM) mbrc = db_file_multiblock_read_count (MBRC) Going back to slide #4 (lets try to calculate cost of tablescan) Cost = (24 / 16) * (10 + 16 * 8192 / 4092) / (10 + 8192 / 4092) = 1.5 * 42 /12 = 5.25 Slide #5 (index scan only) Cost = 0 + ceil(1 * 0.0588) = ceil(0.0588) = 1 Slide #10 (index scan with access to the table) Cost = 0 + 1 + ceil((4 / 17) * 20) = 1 + ceil(4.705) = 1 + 5 = 6 13 14. Selectivity & Cardinality Selectivity is what fraction of row the predicate is supposed to fetch/ returnSelectivity = 1 / num_distinct (no histogram)Selectivity = density (histogram) Cardinality is total number of row the predicate is supposed to returnCardinality = num_rows * density Going back to slide #4 Cardinality = num_rows = 20 Slide #5 Selectivity = (number of bucket with data / number of total bucket) = 17 / 17 = 1Cardinality = selectivity * num_rows = 1 * 20 = 20 Slide #10 14Selectivity = 4 / 17 = 0.235Cardinality = 0.235 * 20 = 4.7 15. Clustering Factor Represents the degree to which data is randomlydistributed through a table Number of blocks