什么时候需要重建索引1、 删除的空间没有重用,导致 索引出现碎片
2、 删除大量的表数据后,空间没有重用,导致 索引"虚高"
3、索引的 clustering_facto 和表不一致
也有人认为当索引树高度超过4的时候需要进行重建,但是如果表数量级较大,自然就不会有较高的树,而且重建不会改变索引树高度,除非是由于大量引起的索引树“虚高”,重建才会改善性能,当然这又回到了索引碎片的问题上了。关于索引是否需要重建,Oracle有这么一句话:
Generally speaking, the need to rebuild b-tree indexes is very rare, basically because a b-tree index is largely self-managed or self-balanced. 另外找到了一篇《When should one perform a rebuild?》分析的比较好的文章Firstly, if the index value were to have monotonically increasing values
then any deleted space could be a problem as this space may not be reused
(making feature 3 above redundant). However, if sufficient entries are
deleted resulting in index nodes being fully emptied (say via a bulk delete)
then feature 4 would kick in and the deleted space could be reused. The
question now becomes one of *when* would the equivalent amount of index
entries be reinserted from the time of the deletions, as index scans (in all
it's manifestations) would be impacted during this interim period. So
monotonically increasing values *and* sparse deletions would present one
case for an index rebuild. These types of indexes can be identified as
having predominately 90-10 splits rather than the usual 50-50 split.Another case would be an index that has deletions without subsequent inserts
or inserts within an acceptable period of time. Such a case would result in
wasted space that can't be effectively reused as there's not the sufficient
insert activity to reclaim the space. However, in this scenario, it's really
the *table* itself rather than the indexes directly that should be rebuilt.
Because such "shrinkage" results in both the table and associated indexes
being fragmented with HWMs that need resetting (to prevent performance
issues with Full Table Scans and all types of Index Scans). Yes the index
needs rebuilding but only as a result of the dependent table being rebuilt
as well. ALTER INDEX..REBUILD ONLINE vs ALTER INDEX..REBUILDalter index rebuild online实质上是扫描表而不是扫描现有的索引块来实现索引的重建.alter index rebuild 只扫描现有的索引块来实现索引的重建。rebuild index online在执行期间不会阻塞DML操作,但在开始和结束阶段,需要请求模式为4的TM锁。因此,如果在rebuild index online开始前或结束时,有其它长时间的事物在运行,很有可能就造成大量的锁等待。也就是说在执行前仍会产生阻塞, 应该避免排他锁.
而rebuild index在执行期间会阻塞DML操作, 但速度较快.Online Index Rebuild Features:
+ ALTER INDEX REBUILD ONLINE;
+ DMLs are allowed on the base table
+ It is comparatively Slow
+ Base table is referred for the new index
+ Base table is locked in shared mode and DDLs are not possible
+ Intermediate table stores the data changes in the base table, during the index rebuild to update the new index laterOffline Index Rebuild Features:
+ ALTER INDEX REBUILD; (Default)
+ Does not refer the base table and the base table is exclusively locked
+ New index is created from the old index
+ No DML and DDL possible on the base table
+ Comparatively faster两者重建索引时的扫描方式不同,rebuild用的是“INDEX FAST FULL SCAN”,rebuild online用的是“TABLE ACCESS FULL”; 即rebuild index是扫描索引块,而rebuild index online是扫描全表的数据块.测试过程SQL> create table t1 as select * From emp;
Table createdSQL> CREATE INDEX i_empno on T1 (empno);
Index createdSQL> CREATE INDEX i_deptno on T1 (deptno);
Index createdSQL> explain plan for alter index i_empno rebuild;
Explainedalter index xxx rebuild使用的是INDEX FAST FULL SCAN
SQL> select * from table (dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 1909342220
--------------------------------------------------------------------------------
| Id  | Operation              | Name    | Rows  | Bytes | Cost (%CPU)| Time
--------------------------------------------------------------------------------
|   0 | ALTER INDEX STATEMENT  |         |   327 |  4251 |     3   (0)| 00:00:01
|   1 |  INDEX BUILD NON UNIQUE| I_EMPNO |       |       |            |
|   2 |   SORT CREATE INDEX    |         |   327 |  4251 |            |
|   3 |    INDEX FAST FULL SCAN| I_EMPNO |       |       |            |
--------------------------------------------------------------------------------
10 rows selectedalter index xxx rebuild online使用的是TABLE ACCESS FULL
SQL> explain plan for alter index i_empno rebuild online;
ExplainedSQL> select * from table (dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 1499455000
--------------------------------------------------------------------------------
| Id  | Operation              | Name    | Rows  | Bytes | Cost (%CPU)| Time
--------------------------------------------------------------------------------
|   0 | ALTER INDEX STATEMENT  |         |   327 |  4251 |     3   (0)| 00:00:01
|   1 |  INDEX BUILD NON UNIQUE| I_EMPNO |       |       |            |
|   2 |   SORT CREATE INDEX    |         |   327 |  4251 |            |
|   3 |    TABLE ACCESS FULL   | T1      |   327 |  4251 |     3   (0)| 00:00:01
--------------------------------------------------------------------------------
10 rows selectedSQL> 

转自<http://blog.csdn.net/pan_tian/article/details/46563897>

重建索引:ALTER INDEX..REBUILD ONLINE vs ALTER INDEX..REBUILD相关推荐

  1. oracle中alter index,oracle alter index rebuild online和alter index rebuild的區別

    本文用10046事件來解析alter index rebuild與alter index rebuild online的區別 alter index rebuild online實質上是掃描表而不是掃 ...

  2. oracle rebuild online,ORACLE alter index rebuild online 操作产生的锁

    ORACLE通过锁和闩的方式实现了并发控制,v$lock 视图列出了数据库中当前拥有的锁以及未完成的锁请求.当发觉有session处于等待事件时 ,可以通过v$lock查询信息. v$lock中的常用 ...

  3. 为何要重建索引 index

    如果索引因为某些原因无效或者因为很长时间没有维护而产生过多的索引碎片(Index Fragment),需要通过重建索引来消除索引碎片.何时需 要重建索引,可以利用下面的过程进行判断. 查询数据库中有哪 ...

  4. oracle建索引默认并发,ORACLE重建索引需要考虑问题

    一:考虑重建索引的场合 1:表上频繁发生update,delete操作 2:表上发生了alter table ..move操作(move操作导致了rowid变化) 二:判断重建索引的标准 索引重建是否 ...

  5. 重建索引能释放掉字段因更改而产生额外列偏移量

    1建表和索引 create table index_test (id int identity(1,1),name sysname); create  clustered index nonidex_ ...

  6. oracle如何并发重建索引,oracle数据库如何重建索引?

    [问题描述] oracle数据库表如何重建索引? [概述] 请在Oracle数据库里面执行如下语句: declare v_table_name  varchar(255):=''; v_index_n ...

  7. oracle表重命名 索引,CSS_在Oracle数据库中按用户名重建索引的方法,如果你管理的Oracle数据库下某 - phpStudy...

    在Oracle数据库中按用户名重建索引的方法 如果你管理的Oracle数据库下某些应用项目有大量的修改删除操作, 数据索引是需要周期性的重建的. 它不仅可以提高查询性能, 还能增加索引表空间空闲空间大 ...

  8. oracle 批量 重建索引,Oracle重建索引Shell脚本、SQL脚本分享

    索引是提高数据库查询性能的有力武器.没有索引,就好比图书馆没有图书标签一样,找一本书自己想要的书比登天还难.然而索引在使用的过程中,尤其是在批量的DML的情形下会产生相应的碎片,以及B树高度会发生相应 ...

  9. Oracle11g新特性:在线操作功能增强-Oracle11g在线重建索引功能增强 (转载)

    Oracle 11g加强了ONLINE REBUILD索引功能,减少了ONLINE REBUILD索引过程中对DML操作的阻塞.下面看看10g中和11g在线重建索引的差别,首先登陆10g: SQL&g ...

最新文章

  1. 用Visual Studio .Net 2003开发PHP程序
  2. zookeeper单机单独实例安装-windows
  3. 【学习笔记】22、读写文件(I/O操作)— 读文件
  4. Lumen开发:如何向 IoC 容器中添加自己定义的类
  5. from import 导入时找不到module的解决办法(Python模块包中_init_.py文件的作用)
  6. 锋利的jQuery--编写jQuery插件(读书笔记五)[完结篇]
  7. 搭建 ELK 问题排查
  8. Visual Studio Code 1.41 发布
  9. c语言是否继续运行,C语言是否有运行时?
  10. BitMEX联合创始人:以比特币为首的加密货币综合体是防范恶性通货膨胀的最佳对冲
  11. bzoj4008: [HNOI2015]亚瑟王
  12. JavaSpring菜鸟教程,附Java面经
  13. java中怎么读取txt文件_Java读取TXT文件
  14. 虚拟机vmware的完全卸载
  15. 下载谷歌浏览器官方正式(稳定)版以及历史各种版本
  16. 2021-08-07:与数组中元素的最大异或值。给你一个由非负整数组成的数组 nums 。另有一个查询数组 queries ,其中 queries[i] = [xi, mi] 。第 i 个查询的答案是
  17. 三行代码做一辆Q弹物理自行车,骑上它去海边兜风吧!
  18. 关于wireshark包体的中文解码
  19. 山重水复疑无路,柳暗花明又一村 。
  20. Pr零基础入门指南笔记一——项目、序列、预设

热门文章

  1. wampserver3.1.7_x64启动后橙色不变绿解决办法
  2. sftp通信攻关——qt环境下使用c++实现
  3. 结对团队之1715|K班取经
  4. 百度推广资质收取要求
  5. Java实现配置文件恢复 匹配
  6. C#关于日期 月 天数 和一年有多少周及根据某年某周获取时间段的计算(转)
  7. 台湾连锁快餐业接连涨价 台“公平会”启动调查
  8. 2020 ICPC上海 题解
  9. 我用python爬取了整个斗图网站
  10. 一半以上的年轻人存款不足10万元,能带给我们什么思考?