oracle 怎么使用索引

来源:互联网 发布:软件开发 外包 杭州 编辑:程序博客网 时间:2024/04/30 23:52


上面这张图,我画得比较粗糙,但是基本原理已经展现了!


下面再写几种常见索引的创建吧:

(1) create index 索引名 on 表(字段名);     //创建B树索引,一般用的OLTP中

(2) create bitmap index 索引名 on 表(字段名);   //创建位图索引,一般用的OLAP中

(3) create index 索引名 on 表名 (substr(字段,1,10))  

//创建函数索引,有些时候呢,咱们的搜索条件要加上函数,这种情况呢,普通索引就不能解发了,就要创建函数索引

(4) create index 索引名 on 表名 (字段1,字段2......字段n);

//复合索引,当条件中,经常去查询多个条件时,可以把多个条件放在一个索引中

(5)  create index 索引名 on 表(字段 desc);   //排序后创建索引

(6) create index 索引名 on 表名 (字段) reverse; //反转索引,消除热点块

(7) create index 索引名 on 表名(字段) local;   //创建分区本地索引

(8) create index 索引名 on 表名 (字段) global;   //创建分区全局索引




附加维护索引基本操作手段:


查看指定表上现有索引详情


select t.INDEX_NAME,t.COLUMN_NAME,i.index_type 

 from user_ind_columns t,user_indexes i where t.index_name = i.index_name and  t.table_name='表名';


查看索引及列

select t.index_name,t.status from user_indexes t where t.INDEX_NAME in ();



查看指定分区表的所有索引


select t.INDEX_NAME,t.COLUMN_NAME,i.index_type from 

user_ind_columns t,user_indexes i where t.index_name = i.index_name and  

t.table_name='表名';


查询分区索引状态

 

select PARTITION_NAME,STATUS from DBA_IND_PARTITIONS where INDEX_NAME='';



valid:当前索引有效

N/A :分区索引 有效

unusable:索引失效



重新建立索引

ALTER INDEX 用户.索引 REBUILD;


原创粉丝点击