Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Overview
Query
OPTIMIZER Query Optimazation RBO / CBO
Parse
Query rewrite
Result
Query Execution
QEP Generation
Understanding RBO
Released with Oracle 6. Using an ordered list of access methods and join methods on relative cost or each operation. Has a very limited input in determining access paths. Will be removed from the Oracle database Server Normally, it chooses the path from right to left in the from clause. If hint (except RULE hint) is supplied, then it will run under CBO. On some complex queries, it outperforms CBO
RBO ranking
1. Single row by ROWID 2. Single row by cluster join. 3. Single row by hash cluster key with unique key. 4. Single row by unique index. 5. Cluster join. 6. Hash Cluster key. 7. Indexed cluster key. 8. Composite key. 9. Single-column non-unique index. 10. Bounded range search on indexed columns 11. Unbounded range search on indexed columns 12. Sort-merge join 13. Max or Min of indexed columns 14. Order by on indexed columns 15. Full table-scan. (cluster)
(cluster)
(cluster) (cluster) (cluster)
Not so good things about RBO... RBO has a small number of possible access method. (it
does not recognize IOT, bitmap index, hash join, ) It will process the tables based on how they are ordered on the query. (can be good and most of the time is not so good) Always ranks execution plan based on relative cost in the list, regardless of the data stored in the table. Index scan will always better than table scan, which is not true. Coding for the RBO is halted. All new features require implementation of CBO. RBO uses poor information to break frequently occurring ties.
Understanding CBO
It uses all available information. Dictionary , statistics, histogram, supplied parameter setting. CBO uses Oracle intelligent formula to calculate the COST of a SQL statement. Constantly improving from version to version. It examines all possible access methods (defaulted to 80,000 permutations) Evaluate the costs for each access plan, then simple choose the lowest one
selectivity for relations on indexed columns .009 selectivity for = on indexed columns .004 multiblock read factor 8 remote table average row length 100 # of blocks 100 Scan cost 13 Index levels 1 number leaf blocks/key 1
First_row applies a heuristic bias to the cost model to promote the use of indexes and nested loop)
Example
Index access
number or levels in the B*-tree number of leaf blocks to examine
Cost of Sorting
Data may need to be sorted for:
Sorts are typically CPU intensive, and can be I/O bound if the sort can not fit in memory. Cost depends on sort_area_size and # rows.
MERGE
Sort
Sort
Row source 1
Row source 2
Nested Loop
Access A (Full)
Output rows
DISK
Using HINT
21
The optimization approach (RULE, ALL_ROWS, FIRST_ROWS) The access path for a table accessed (FULL , INDEX,HASH, ...) The join order and method (ordered, leading, star, use_nl, use_merge, use_hash ...)