rebuild index 和 recreate index (重新建立index) 的区别

Rebuild index :

rebuild时也会使用临时表空间
ask tom上关于rebuild index 有这么一段话:
If you need to rebuild your indexes, you need 2x the space -- you'll have the old and the new index for a period of time. If you do it online, you'll need additional space to hold the changes that are made during the rebuild as well

2×的空间是当前index所在的tablespace中使用空间


以前有人问过类似的问题

rebuild index为何要排序

我们都知道索引是有序的存储
然而在block内部,实际上索引键值的存储是无序的

比如说,你先存入了1,3
即使以后增加了一个2
那么在同一个数据块内部,数据库也不会去动1,3的存储
在读取的时候,oracle可以作简单的块内排序,进行有序的读取输出

在重建索引的时候
Oracle显然不会按照1,2,3..........的索引顺序来读出索引内容
因其代价高昂

Oracle实际执行的是Fast Full Scan
按顺序读取block

这样读取出来的数据需要重新sort
排序,然后重构索引

这个重构的索引在物理存储上比原来更为有序

这个可以通过block dump观察到

建立索引实际上是排序,大型的排序(只要sort area容纳不下)就要使用临时表空间

我作了两个试验
我的index大小为7M左右。
首先,我将index所在的tablespace只开到10M,临时表空间较大,
rebuild 时报无法在index所在的tablespace上扩展temp 段。
将表空间增大,rebuild成功。(至少要开到20M)
在将临时表空间只开到5M,表空间开到20M,rebuild就报无法在temp表空间上扩展(这个是因为需要排序,而sort area容不下,所以要利用临时表空间),将临时表空间增大到10M,rebuild成功。


1.索引的存储是,块内无序,块间有序
2.rebuild index时对于索引块的读取也是Fast full scan
3.不是说读索引的代价高,是说顺序读取块内无序的索引的代价高
所以会采用Fast Full Scan方式读取

ALTER INDEX REBUILD is usually faster than dropping and re-creating an index because it uses the fast full scan feature. It thus reads all the index blocks, using multi-block I/O, then discards the branch blocks. The Oracle database allows the creation of an index or the re-creation of an existing index while allowing concurrent operations on the base table. This helps achieve demanding availability goals by allowing maintenance operations to be performed online with no down time.

索引的rebuild具有下列特征:
新索引在建立的时候使用已存的索引作为数据源。
使用已存的索引建立新索引不需要排序操作,从而提高性能。
新索引建立后就会删除旧的索引. 在索引重建期间,在两个不同的表空间上需要足够的空间来同时放置新旧两个索引,
新的索引不会包含有任何已经删除了的行的条目,从而索引空间具有更好的利用率。
在新索引建立期间,查询语句可以继续使用以前的索引 。

========================

重新建立索引是drop index ,释放空间, 然后重新create . 当然也需要排序。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/35489/viewspace-84792/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/35489/viewspace-84792/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值