设为首页 加入收藏

TOP

【oracle11g,19】索引管理(一)
2015-07-24 11:26:04 来源: 作者: 【 】 浏览:3
Tags:oracle11g 索引 管理
一.索引的分类:
1.逻辑上分为: 单列索引和复合索引 唯一索引和非唯一索引 函数索引 domain索引 2.物理上分: 分区索引和非分区索引 b-tree bitmap
注意:表和索引最好不放在同一表空间。
二.domain索引:(了解)

一般的索引 %MI%'是不走的索引的,但有可能走域索引。 域索引用于文本的检索,适合数据仓库。 SQL> select * from scott.emp where ename like '%MI%';
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- 7369 SMITH CLERK 7902 17-DEC-80 800 20 7934 MILLER CLERK 7782 23-JAN-82 1300 10
SQL> select * from scott.emp where ename like 'MI%';
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- 7934 MILLER CLERK 7782 23-JAN-82 1300 10

三.b-tree和bitmap 索引:
1.b-tree索引是默认的索引。 \ #创建索引表空间 (unifZ??http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcm0gc2l6ZTq/ydLUvPXJ2cvpxqwpCgoKU1FMJmd0OyBjcmVhdGUgdGFibGVzcGFjZSBpbmR4IGRhdGFmaWxlIA=="/u01/app/oracle/oradata/PROD/disk4/indx01.dbf' size 50m autoextend on next 10m maxsize 500m uniform size 1m;
Tablespace created.
详解:http://www.tuicool.com/articles/q6vqEf
2.位图索引 \
\
四.b-tree 和 bitmap的区别:
1.b-tree索引使用场景: 基数比较大(在一个大表上) 建立在重复值比较少的列上 ,在做select查询时,返回记录的行数小于全部记录的4%, 因为索引是有序的,所以可以在排序字段上建立索引。 update 较多。 oltp使用
2.bitmap 索引使用场景: (在生产环境中不使用) 基数比较小 建立在重复值非常高的列上 在做DML时代价高,所以在update较少的列上建立bitmap索引。 一般使用在altp。
bitmap缺点:当对一个有位图索引的数据表进行dml(包括insert)操作的时候,oracle会由于bitmap index 锁定过多的数据行。

3.案例: 性别列上建立索引 SQL> create table lxtb(id number(8),gender varchar2(2),name varchar2(30));
SQL> declare 2 v_num number(2); 3 begin 4 for i in 1..20000 loop 5 v_num:=round(dbms_random.value(0,1),0); 6 if v_num>0 then 7 insert into lxtb values(i,"M','male'||i); 8 else 9 insert into lxtb values(i,'F','female'||i); 10 end if; 11 if mod(i,1000)=0 then 12 commit; 13 end if; 14 end loop; 15 commit; 16 end; 17 /

PL/SQL procedure successfully completed.
SQL> select count(*) from lxtb;
COUNT(*) ---------- 20000
SQL> select * from lxtb where rownum<=10;
ID GE NAME ---------- -- -------------------------------------------------- 1 M male1 2 M male2 3 M male3 4 M male4 5 M male5 6 F female6 7 M male7 8 M male8 9 F female9 10 M male10
10 rows selected.
SQL> col index_name for a20 SQL> col index_type for a10 SQL> select index_name,index_type,table_name,tablespace_name 2 from dba_indexes where table_name='LXTB';
no rows selected
SQL> col column_name for a10 SQL> select index_name,table_name,column_name from dba_ind_columns where table_name='LXTB';
no rows selected #创建b-tree索引 (默认索引) SQL> create index i_gender on lxtb(gender) tablespace indx;
Index created. #BLEVEL=1 表示b-tree为两层,LEAF_BLOCKS 表示页块数。 SQL> select index_name,index_type,table_name,tablespace_name,blevel,leaf_blocks 2 from dba_indexes where table_name='LXTB';
INDEX_NAME INDEX_TYPE TABLE_NAME TABLESPACE BLEVEL LEAF_BLOCKS -------------------- ---------- ---------- ---------- ---------- ----------- I_GENDER NORMAL LXTB INDX 1 37
SQL> drop index i_gender;
Index dropped. #创建位图索引: SQL> create bitmap index i_gender on lxtb(gender) tablespace indx;
Index created.
SQL> col index_name for a20 SQL> col index_type for a10
SQL> select index_name,index_type,table_name,tablespace_name,blevel,leaf_blocks 2 from dba_indexes where table_name='LXTB';
INDEX_NAME INDEX_TYPE TABLE_NAME TABLESPACE BLEVEL LEAF_BLOCKS -------------------- ---------- ---------- ---------- ---------- ----------- I_GENDER BITMAP LXTB INDX 0 1
五.索引的管理操作
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇ORACLE,SQLSERVER等数据库如何获.. 下一篇oraclesplit

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·常用meta整理 | 菜鸟 (2025-12-25 01:21:52)
·SQL HAVING 子句:深 (2025-12-25 01:21:47)
·SQL CREATE INDEX 语 (2025-12-25 01:21:45)
·Shell 传递参数 (2025-12-25 00:50:45)
·Linux echo 命令 - (2025-12-25 00:50:43)