ITPub博客

首页 > 数据库 > Oracle > 索引@oracle索引技术

索引@oracle索引技术

原创 Oracle 作者:lff1530983327 时间:2015-02-05 18:22:46 0 删除 编辑

索引

索引:其中记录的书rowid以及可以标示堆组织表的一行,聚簇表例外

独特值

覆盖索引

B树索引:索引组织表 organization index;

         唯一索引:unique index

         反向键索引:reverse;

         键压缩索引:compress 2;

         降序索引:

------------------------------------------------------索引健压缩是指从串联(多列)索引取出冗余

select * from user_objects where  object_type='INDEX';

create table t as select * from all_objects where rownum<=50000;

create index t_idx on t(owner,object_type,object_name);

select * from big_table;

ANALYZE INDEX t_idx VALIDATE STRUCTURE;

create table idx_stats as select 'noncompressed' what,  a.* from index_stats a;

select * from idx_stats;

drop index t_idx;

create index t_idx on t(owner,object_type,object_name) compress &1;----使用3个压缩列来创建这个索引

create index t_idx on t(owner,object_type,object_name) compress &1;----使用2个压缩列来创建这个索引

create index t_idx on t(owner,object_type,object_name) compress &1;----使用1个压缩列来创建这个索引

analyze index t_idx validate structure;

insert into idx_stats select 'compress &1',a.* from index_stats a; 

select  what,height,lf_blks 叶子节点块,br_blks ,btree_space 可以得出索引大小,opt_cmpr_count 可用的最佳压缩数,opt_cmpr_pctsave 节省空间 from idx_stats ;

----------------------------------------------------------------反向健索引是指主要用于缓解忙索引右侧的缓冲区

select 90101 ,dump(90101,16) from dual;

begin dbms_stats.gather_index_stats(user,'T',method_opt => 'for all indexed column');end;

 select * from user_objects where object_type='TABLE';

 

位图索引:相对较低的差异值 bitmap(数据仓库环境中用的较多)

位图连接索引:表的外键列和另一个表的主键列连接时适用

主键约束:在主键列值上自动创建索引

唯一键约束:

1 只读索引块

2 读索引与数据块

3 只读数据块

dbms_space.create_index_cost 估算索引大小

dbms_metadata.get_ddl 获取元数据

alter index unusable/invisible

alter index rebuild

drop  index

 不可见 需要维护用来避免锁定问题或强制执行约束

 不可用 优化器不用 维护不用

 外键索引:主要是为了减少锁定问题

 

 当select子句中的列都具有索引时 这种索引称为覆盖索引 只需读取索引块主键列

 

 index range scan

 index fast full scan ---对count()很适用

  db block gets+consistent gets=总的内存读

 buffer is pinned count 第二次读取的块数是收集在缓冲区被钉住记数统计信息里面而不被收集进入统计信息中。

 

 dbms_rowid.rowid_relative_fno(rowid)---rowid转换

 

 外联 约束声明与列定义之间 用逗号 好处是可以为主键指定多列

 constraint cust_pk primary key(cust_id);

 

 独立索引删除与禁用 主键约束 先建unique index之后 add constraint primary key 

 listagg ?

organization index:  存储在b树索引结构中 在此结构中没有为每行存储物理rowid

star_transformation 星型转换

IOT(堆组织表) 索引组织表:按主键的顺序存储的,所以必须有主键

----分区索引

索引的前导部分:在列清单中首先指定索引中的一个或多个列

on table mytable(a,b,c)

前导部分为:a b abc 而b c bc不是

前导部分只有少量的不同值而非前导部分有很多不同值,这个时候会选择索引跳跃扫描(逻辑子索引)

复合索引:确保where 子句中使用的键组成复合索引的前导部分

global 可以在分区表或则非分区表中使用

local 只可以在分区表的基础上建立

表的分区在前导列:前缀索引

全局分区索引:必须有一个maxvalue 必须是前缀分区索引

alter table employees_12 split partition manager_max at(1000) into (partition manager_max,partition manager_1000);

alter table t truncate  截断分区--全局unusable 本地的usable

alter table t move      移动分区--全局和本地都是unusable,但是本地只是在这个分区内unusable

截断分区清除表分区内的所有数据

本地分区索引:不影响底层的索引分区

非分区索引/全局index :全部变成unusable

添加虚拟分区实现分区拆分 :虚拟一个高端值 然后在高端值后面添加一个maxvalue 删除某个分区对本地索引分区没有任何影响 usable

alter table t merge partition p1995 ,pmax into partition pmax update indexs;--更新之后的status会依然是usable

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30018455/viewspace-1427788/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 索引分区
请登录后发表评论 登录
全部评论

注册时间:2014-11-12

  • 博文量
    72
  • 访问量
    49744