rebuild index 的机制

来源:互联网 发布:探索者软件模块 编辑:程序博客网 时间:2024/04/29 08:04

alter index ... rebuild online的机制

当我们对索引进行rebuild时,如果不加online选项,oracle则直接读取原索引的数据;当我们添加online选项时,oracle是直接扫描表中的数据,那如何维护索引段数据的一致性呢?就是从引开始创建到索引创建完成这段时间的数据改变...

从索引开始rebuild online开始的那一刻起,oracle会先创建一个SYS_JOURNAL_xxx的系统临时日志表,结构类似于mlog$_表,通过内部触发器,记录了开始rebuild索引时表上所发生的改变的记录,当索引已经创建好之后,新数据将直接写入索引,只需要把SYS_JOURNAL_xxx日志表中的改变维护到索引中即可.

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