首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

Oracle目录管理

2013-03-01 
Oracle索引管理基础知识:create table test01(enno number(3),enname varchar(20),sexvarchar(2),agenumbe

Oracle索引管理
基础知识:create table test01(   enno number(3),   enname varchar(20),   sex  varchar(2),   age  number(3))

1、创建索引     语法:create index 索引名称 on 表名称(列名称1,列名称2,.......) tablespace 表空间名称;    例子:create index  ind_enno on test01(enno) tablespace system;    创建唯一索引:create unique index 索引名称 on 表名称(列名称1,列名称2,......) tablespace 表空间名称   例子:create unique index ind_age  on test01(age) tablespace system   创建函数索引:create index 索引名称 on 表名称(函数)   例子:create index ind_sex on test01 (upper(sex))2、查询索引     select  index_name,table_name     from dba_indexes     where table_name='TEST01';
3、删除索引      语法:drop index 索引名称       例子:drop index ind_enno;
 4、重命名索引      语法:alter index 旧索引名称 rename to 新索引名称       例子:alter  index ind_enno rename to ind_enno1
 5、监控索引的使用  开启监控:   alter index  索引名称  monitoring usage  查询使用情况:select * from v$object_usage;  关闭监控:alter index 索引名 nomonitoring usage例子:    alter index ind_enno monitoring usage;    对test01表进行查询:select * from  test01 where enno='1';   alter index ind_enno nomonitoring usage;   select * from v$object_usage;
INDEX_NAME        TABLE_NAME      MON USE    START_MONITORING  END_MONITORING------------------------------ ---------------------------  ---    --- --- ------------------- -------------------IND_ENNO        TEST01      YES     YES   02/27/2013 05:42:41
备注:use代表使用情况,yes表示使用,no表示未使用
6、重建索引   语法:alter index 索引名称 rebuild    例子:alter index ind_enno rebuild;   语法:alter index 索引名称 rebuild  online    例子:alter index  ind_enno rebuild online;

===================以下内容是引用他人文章===============================

出处:http://blog.csdn.net/hailang99/article/details/1827129

目的:为了读者更好理解作者写的内容

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

热点排行