|
bsp; .索引列的结合范围查找.
.索引列的非结合范围查找.
.排序合并连接.
.索引列的最大max或min
.索引列的order by.
.全表扫描.
举例来说,如果生成一个在where子句条件中精确匹配两列的表的查询,一列拥有主键(对应于使用主键的单独记录.)而别一列拥有非主键(对应于单列主键),则RBO更喜欢主键(对应于使用主键的单独记录.),而不是非主键(对应于单列主键).
当在一个查询中涉及到要访问多个表,优化器需要确定那个表是驱动表.RBO生成一组连接顺序,每一个表做为第一个表,然后优化器从执行计划的结果集中选择最理想的计划.优化器评估不同条件诸如(最少的嵌套循环,最少的排序合并连接,最佳级别的表访问路径,等等),如果仍然不能比较出结果,则优化器会选择查询的FROM子句第一个表作为驱动表.因此,常规条件下的编码实践将把驱动表放在最右边.其它的表按访问顺序跟随在FROM子句中. 也就是说,表的顺序是从右到左的访问顺序。
请注意,用以搜索列的操作符也扮演着决定级别的角色,有时甚至考虑索引的时间作为级别
例如下面的表证明了在列1和列2上的索引使用情况,如果它们两个在where子句上用”=”连接
例:
select * from am79 where col1 = 1 and col2 = 'amar'; -- here both col1 and col2 are indexed. ------------------------------------------------------------------------------------- Normal index types | Index used in RBO column1(a) column2(b) column1+column2(c) | ------------------------------------------------------------------------------------- non-unique non-unique c non-unique non-unique a + b non-unique non-unique non-unique c unique non-unique a unique non-unique a unique unique b (the most recent index created) unique unique unique c ------------------------------------------------------------------------------------- -The above is tested on Oracle 8.1.7.1. -In case of non-unique single column indexes, both indexes are used. -In case of unique indexes, they are not combined for execution plan, any one is taken. -Preference is given to the index available with the "=" operator column, than with others operators. -Don't create bitmap & function-based indexes, these will not work in RBO. -------------------------------------------------------------------------------------
RBO偏好Oracle早期版本的大多数设置作为执行计划路径,这种选择是统一的。查询总会产生同样的方法对于运行在不同数据库上相同的应用程序(待续).
上一页 [1] [2] [ORACLE]Oracle Optimizer:迁移到使用基于成本的优化器---…
|