- 最后登录
- 2018-11-1
- 在线时间
- 377 小时
- 威望
- 29
- 金钱
- 6866
- 注册时间
- 2011-10-12
- 阅读权限
- 200
- 帖子
- 891
- 精华
- 4
- 积分
- 29
- UID
- 1
|
1#
发表于 2012-12-6 16:42:59
|
查看: 5957 |
回复: 3
RBO优化器模式下2个都可以用的索引用哪一个?
可以通过如下演示说明该问题的哦- SQL> create table testind as select 1 t1,2 t2 ,3 t3 from dual connect by level <=90000;
- Table created.
- SQL> create index ind1 on testind(t2,t1);
- Index created.
- SQL> create index ind2 on testind(t2,t3);
- Index created.
- SQL> select /*+ RULE */ * from testind where t2=10;
- no rows selected
- Execution Plan
- ----------------------------------------------------------
- Plan hash value: 272597711
- -----------------------------------------------
- | Id | Operation | Name |
- -----------------------------------------------
- | 0 | SELECT STATEMENT | |
- | 1 | TABLE ACCESS BY INDEX ROWID| TESTIND |
- |* 2 | INDEX RANGE SCAN | IND2 |
- -----------------------------------------------
- Predicate Information (identified by operation id):
- ---------------------------------------------------
- 2 - access("T2"=10)
- Note
- -----
- - rule based optimizer used (consider using cbo)
-
- alter system flush shared_pool;
- drop index ind1;
- create index ind1 on testind(t2,t1);
-
- select /*+ RULE */ * from testind where t2=10;
- SQL> select /*+ RULE */ * from testind where t2=10;
- no rows selected
- Execution Plan
- ----------------------------------------------------------
- Plan hash value: 3431448338
- -----------------------------------------------
- | Id | Operation | Name |
- -----------------------------------------------
- | 0 | SELECT STATEMENT | |
- | 1 | TABLE ACCESS BY INDEX ROWID| TESTIND |
- |* 2 | INDEX RANGE SCAN | IND1 |
- -----------------------------------------------
- Predicate Information (identified by operation id):
- ---------------------------------------------------
- 2 - access("T2"=10)
- Note
- -----
- - rule based optimizer used (consider using cbo)
复制代码 如以上测试可以说明 同时有2个可用索引时 RBO会选择 更晚 创建 或者 重建的索引, 这是RBO的一点小秘密。 |
|