下面具体详细介绍Oracle数数据库的三大索引种类,仅作参考。

一、B-Tree索引
三大特性:相对高度比较低、储存列值、构造井然有序
1.1运用索引特点进行调整
外键约束上创建索引:不仅能够提升查询高效率,并且能有效防止锁之间的竞争(外键约束所属表delete纪录未提交,外键约束所属表能被锁定)。
统计类查询SQL:count(), avg(), sum(), max(), min()
排序实际操作:order by字段创建索引
去重实际操作:distinct
UNION/UNION ALL:union all不必须去重,不用排序
1.2协同索引
应用领域一:SQL查询列非常少,创建查询列的协同索引能有效清除回表,但一般超出3个字段的协同索引都是不合适的.
应用领域二:在字段A回到纪录多,在字段B回到纪录多,在字段A,B与此同时查询回到纪录少,例如实行下边的查询,结论c1,c2都有很多,c3其实很少。
select count(1) c1 from t where A = 1;
select count(1) c2 from t where B = 2;
select count(1) c3 from t where A = 1 and B = 2;
广泛时兴的立场:重复记录少字段放到前边,重复记录多的是放到后边,其实这种结果并不准确。
drop table t purge;
create table t as select * from dba_objects;
create index idx1_object_id on t(object_id,object_type);
create index idx2_object_id on t(object_type,object_id);
–等价查询:
select * from t where object_id = 20 and object_type = 'TABLE';
select /* index(t,idx1_object_id) */ * from t where object_id = 20 and object_type = 'TABLE';
select /* index(t,idx2_object_id) */ * from t where object_id = 20 and object_type = 'TABLE';
结果:等价查询前提下,组成索引的列不管哪一列放前,特性都一样。
–范畴查询:
select * from t where object_id >=20 and object_id < 2000 and object_type = 'TABLE';
select /* index(t,idx1_object_id) */ * from t where object_id >=20 and object_id < 2000 and object_type = 'TABLE';
select /* index(t,idx2_object_id) */ * from t where object_id >=20 and object_id < 2000 and object_type = 'TABLE';
结果:组成索引的列,等价查询列放前,范畴查询列在后。 那如果在具体工作环境要明确组成索引列谁放前,要充分考虑全部常见SQL应用索引状况,由于索引过多危害进库特性。
1.3索引的危害性
表里有过多索引关键会影响到插进特性;
对delete实际操作,删掉少许数据信息索引能有效快速查找,提高删掉高效率,但如果删掉海量数据便会有不良影响;
对update实际操作类似delete,不过如果升级的对错索引列则无危害。
1.4索引的监管
–监管
alter index[index_name]monitoring usage;
select * from v$object_usage;
–撤销监管:
alter index[index_name]nomonitoring usage;
通过对索引监管得到的结果,对长期未使用的索引可以选择把它删掉。
1.5索引最常见的执行计划
INDEX FULL SCAN:索引的全扫描仪,每块读,井然有序
INDEX RANGE SCAN:索引的范畴扫描仪
INDEX FAST FULL SCAN:索引的高效全扫描仪,几块读,混乱
INDEX FULL SCAN(MIN/MAX):对于MAX(),MIN()函数的查询
INDEX SKIP SCAN:查询标准并没有使用组成索引的第一列,而组成索引的第一列反复度较大时,很有可能使用
应用领域:表中升级实际操作非常少,反复也比较的列。
优点:count(*) 高效率
create table t(
name_id,
gender not null,
location not null,
age_range not null,
data
)as select
rownum,
decode(floor(dbms_random.value(0,2)),0,'M',1,'F') gender,
ceil(dbms_random.value(0,50)) location,
decode(floor(dbms_random.value(0,4)),0,'child',1,'young',2,'middle',3,'old') age_range,
rpad('*',20,'*') data
from dual connect by rownum <= 100000;
create index idx_t on t(gender,location,age_range);
create bitmap index gender_idx on t(gender);
create bitmap index location_idx on t(location);
create bitmap index age_range_idx on t(age_range);
select * from t where gender = 'M' and location in (1,10,30) and age_range = 'child';
select /* index(t,idx_t) */* from t where gender = 'M' and location in (1,10,30) and age_range = 'child';
应用领域:迫不得已对某一列开展函数公式计算的画面。
运用函数公式索引效率要小于运用一般索引的。
oracle中创建函数索引就是 你运用了什么函数就建什么函数索引,例如substr
select * from table where 1=1 and substr(field,0,2) in (’01’)
create index indexname on table(substr(fileld,0,2)) online nologging ;
感觉有益的身边的朋友帮忙转发哦!后面会共享更多devops和DBA方面的知识,感兴趣的小伙伴可关注下~
原创文章,作者:leping,如若转载,请注明出处:https://www.changtianfy.com/wbbs-1543.html