1.唯一索引:键值不重复
create unique index doctor_index on t_doctor(empno) drop indexdoctor_index
2.一般索引:键值可重复
create index doctor_index on t_doctor(empno) drop indexdoctor_index
3.复合索引:绑定了多个列
create index doctor_index ont_doctor(empno,job) drop indexdoctor_index
4.反向索引:为避免平衡树索引热块,如t_doctor表中empno开头都是“7”,这样构建索引树的时候,很可能会把所有数据分配到一个块里,使用反向索引,避免此类问题,使索引树分布均匀
create index doctor_index ont_doctor(empno) reverse drop indexdoctor_index
5.函数索引:查询时必须用到这个函数,才会使用到
create index func_index ont_doctor(lower(empno)) --select * from t_doctor where lower(empno) = 'lina' drop indexfunc_index
6.压缩索引:不常用
create index doctor_index ont_doctor(empno) compress drop indexdoctor_index
7.升序降序索引:
create index doctor_index ont_doctor(empno desc, job asc) drop indexdoctor_index
索引碎片问题
由于对基表做DML操作,导致索引表块的自动更改操作,尤其是基表的delete操作会引起index表的index_entries的逻辑删除,注意只有当一个索引块中的全部index_entry都被删除了,才会把这个索引块删除,索引对基表的delete、insert操作都会产生索引碎片问题。
在Oracle文档里并没有清晰的给出索引碎片的量化标准,Oracle建议通过Segment Advisor(段顾问)解决表和索引的碎片问题,如果你想自行解决,可以通过查看index_stats视图,当以下三种情形之一发生时,说明积累的碎片应该整理了(仅供参考)。
查看执行计划:set autotrace traceonly explain;
分析索引列:
analyze index ind_1 validate structure; select name,HEIGHT,PCT_USED,DEL_LF_ROWS/LF_ROWS from index_stats; HEIGHT >=4 PCT_USED< 50% DEL_LF_ROWS/LF_ROWS>0.2 alter index ind_1 rebuild [online] [tablespace name];
到此这篇关于oracle数据库关于索引建立及使用的详细介绍的文章就介绍到这了,更多相关oracle数据库索引内容请搜索