索引create|rebuild|rebulid online

来源:互联网 发布:java书号书名 编辑:程序博客网 时间:2024/05/17 09:22

对于使用rebuild online 来说, 最大的好处即在于online. 也就是最小化对当前业务的影响..
创建时的开销应该会大一点, 毕竟一般情况下表会比索引大, 需要排序的内存/硬盘空间自然也会多点..创建完成后, 两种结果应该差别非常小, 通过log记录的这部分索引的更新应该类似与普通的dml操作处理..

最后一个问题,  除非用户很少使用这个索引, 否则drop index/create index肯定是一个不可取的操作..只要系统在用这个索引, 最好使用online rebuild, 是在不济, 也要考虑在系统较闲的使用rebuild index..

还想搞清楚的是:  rebuild index online ( 或者没online ) 时候Oracle会将B-Tree 的叶子节点或树的某些分支进行重新排列组合,这和drop index 之后然后重新create index 在结果上是否有大的区别 ?
rebuild online 应该与create index的机制是差不多的,只是在创建完之后需要将这段时间产生的变更的数据通过普通的dml操作的方式去更新..
这两种方法创建的索引,最终使用效果应该一样的。
区别就在于创建时online不会影响现有index的使用,建立的快一些(因在现有的索引基础之上)

我们在线系统都是用REBUILD ONLINE方式很少用DROP +CREATE 方式

REBUILD不能等同于create index.仅仅是对OLD INDEX作部分的range scan

craete index ...  Oracle will scan the whole table for the data to build the index.
alter index ... rebuild oracle takes the data already in the index and just reorganizes it.
The orginal table is not scanned again for data guring this rebuild process.

When creating a new index that is a subset of an existing index or when rebuilding an existing index with new storage characteristics, Oracle might use the existing index instead of the base table to improve the performance of the index build.
from Oracle9i Database Performance Tuning Guide and Reference

alter index  rebuid online  与alter index ....rebuild 是不同的!
至少有几个不同
1.drop & create 的话,当前Table 无法使用该index ,可能会严重影响应用,只能在应用不需用到该 Index时使用 , 而 alter index .. rebuild online 则没有这个限制,只是会消耗DB资源,不至于严重影响应用
2.Drop & create 只需占用一份index的space , 不像alter index .. rebuild online ,会在创建过程中需要占用新老两个index的space, 在free space不足的环境中,也许只能选用Drop & create
3. 至于 alter index .. rebuild ,或者alter index .. rebuild online 是否会使用 INDEX SCAN 代替 TABLE SCAN ,似乎不同环境有不同的结果。(RBO状态下)
我的一套环境中,alter index .. rebuild  ==> INDEX FAST FULL SCAN
 alter index .. rebuild  online==> TABLE FULL SCAN
而另一套,则是alter index .. rebuild  /alter index .. rebuild  online 都采用了TABLE FULL SCAN