Oracle里大量删除记录后,表和索引里占用的数据块空间并没有释放。
table move可以释放已删除记录表占用的数据块空间,整理碎片。如果将表格用move方式整理碎片后,索引将失效,这时需要将索引重建。
重建索引可以释放已删除记录索引占用的数据块空间。重建索引不仅能增加索引表空间空闲空间大小,还能够提高查询性能。
--table move
alter table tbl move;
--rebuild索引
alter index idx_tbl_col rebuild;
alter index idx_tbl_col rebuild online;
--rename
ALTER INDEX employee_idx RENAME TO employee_index_Newname;
普通情况下建立索引或者rebuild索引时,oracle会对基表加share锁,由于share锁和 row-X是不兼容的,也就是说,在建立索引期间,无法对基表进行DML操作。
是否加online,要看你的系统需求。因为不加online时rebuild会阻塞一切DML操作。
当我们对索引进行rebuild时,如果不加online选项,oracle则直接读取原索引的数据;当我们添加online选项时,oracle是直接扫描表中的数据
索引在重建时,查询仍然可以使用旧索引。实际上,oracle在rebuild时,在创建新索引过程中,并不会删除旧索引,直到新索引rebuild成功。
从这点可以知道rebuild比删除索引然后重建索引的一个好处是不会影响原有的SQL查询,但也正由于此,用rebuild方式建立索引需要相应表空间的空闲空间是删除重建方式的2倍。
可以通过如下的sql看到rebuild前后的索引空间大小
Select Segment_Name, Sum(bytes) / 1024 / 1024/1024 as Gsize
From User_Extents
Group By Segment_Name
order by Gsize desc
不能直接rebuild整个分区索引
对于非组合索引,需要rebuild每个分区(partition),不能直接rebuild整个索引
对于组合索引,需要rebuild每个子分区(subpartition),不能直接rebuild整个索引,也不能直接rebuild分区
使用下面的sql可以生成相应的rebuild语句,注意是否加上online
非组合索引:
select 'alter index ' || index_owner || '.' ||index_name ||' rebuild partition ' || PARTITION_NAME || ' nologging parallel ;'
from dba_ind_partitions
where index_owner = 'USER_NAME'
AND INDEX_NAME = 'idx_tbl_col'
组合索引:
select 'alter index ' || index_owner || '.' ||index_name ||' rebuild subpartition ' || subpartition_name || ' parallel ;'
from dba_ind_subpartitions where index_owner='&index_owner' and index_name='&index_name';
参考
rebuild 分区索引
分享到:
相关推荐
Useful SQL commands or scripts to alter Oracle table used for SAP
NULL 博文链接:https://aindf0128.iteye.com/blog/752997
index rebuild
1.1、Rebuild以index fast full scan(or table full scan) 方式读取原索引中的数据来构建一个新的索引,有排序的操作; 1.2、rebuild online 执行表扫描获取数据,有排序的操作; 说明:Rebuild 方式 (index ...
朋友有一个Rebuild Index的Job执行一般停掉了,问我是否可以查看哪些Index已经被Rebuild过了。本来以为Sys.index或者Sys.objects会存储类似的信息,结果没有找到。 从网上查了一下,SQL Server没有存储类似的信息...
Toad and Oracle Enterprise Manager 29 Quick Search Bar 30 Additional Resources 31 Working with other Quest Products 32 Knowledge Xpert 32 Using SQL Optimizer with Toad 32 Benchmark Factory 33 Quest ...
@FragmentationMedium = 'INDEX_REORGANIZE,INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE', @FragmentationHigh = 'INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE', @FragmentationLevel1 = 5, @...
alter table TABLE_NAME add constraint KEY_NAME primary key (TABLE_COLUMN) using index tablespace TABLE_SPACE_NAME; 2.增加外键 alter table TABLE_NAME add constraint FK_NAME foreign key (TABLE_COLUMN)...
where c.owner = upper('&table_owner') and c.table_name = upper('&table_name') and c.owner = cc.owner and c.constraint_name = cc.constraint_name order by cc.position; 8、存储函数和过程 查看函数...
以前都是手工右击索引重新生成,但是索引太多,操作起来费时费力,索引在网上找了个存储过程,自己整理了一下,执行的时候只需要选择相应的数据库,运行exec sp_rebuild_index即可,如下。 USE [master] GO SET ...
记住Oracle Applications会有很多索引,定期rebuild index会对性能有好处,当然做这项工作应该在系统的空闲时间。 4.不要为了提高性能而在没有询问oracle Support前试着去增加额外的indexes。如果你一定要去做,那...
nexus index索引手动更新,不需要等待nexus自动更新很慢的下载速度,节约时间
Solar Board Rebuild on TI part4
The only source of any storage location information is the sysindexes table, which keeps track of the address of the root page for every index, and the first IAM page for the index or table....
SQL置疑REPAIR_REBUILD修复
DELL_服务器硬盘掉线后的REBUILD修复操作全过程
高度可配置化的企业管理系统!可免费商用!...REBUILD 侧重于业务需求实现,而非基础技术框架或项目启动模板,通过 REBUILD 可以真正实现零代码快速搭建!无需编程、无需编译代码,甚至无需了解任何技术。
where c.owner = upper('&table_owner') and c.table_name = upper('&table_name') and c.owner = cc.owner and c.constraint_name = cc.constraint_name order by cc.position; 8、存储函数和过程 查看函数...
Android版Rebuild.fm Android的Rebuild.fm是收听Rebuild.fm的最佳播客播放器。 (非官方) 关于Rebuild.fm 的。 谈论技术,软件开发和小工具。 截屏 当前版本(0.10.0) 安装 建立在本地 $ git clone ...