gdufo

 

oracle 索引管理

第四章:索引

1.creating function-based indexes

sql> create index summit.item_quantity on summit.item(quantity-

quantity_shipped);

2.create a B-tree index  #oracle 默认是这种索引,此种索引适用于唯一性高的列

sql> create [unique] index index_name on table_name(column,.. asc/desc)

tablespace

sql> tablespace_name [pctfree integer] [initrans integer] [maxtrans integer] #不能指定pctused参数

sql> [logging | nologging] [nosort] storage(initial 200k next 200k pctincrease 0

sql> maxextents 50);

3.pctfree(index)=(maximum number of rows-initial number of rows)*100/maximum

number of rows

4.creating reverse key indexes

sql> create unique index xay_id on xay(a) reverse pctfree 30 storage(initial

200k
next 200k pctincrease 0 maxextents 50) tablespace indx;

5.create bitmap index #此种索引适用于唯一性低的列,如性别列,只有"男","女"两种

情况,也就是说,很多行会重复。

sql> create bitmap index xay_id on xay(a) pctfree 30 storage( initial 200k next

200k

sql> pctincrease 0 maxextents 50) tablespace indx;

6.change storage parameter of index

sql> alter index xay_id storage (next 400k maxextents 100);

7.allocating index space

sql> alter index xay_id allocate extent(size 200k datafile

'c:/oracle/index.dbf');

8.deallocating index space
sql> alter index xay_id deallocate unused;

9.rebuilding indexes
sql> alter index testindex3 rebuild tablespace indx;#移到指定tablespace

sql> alter index testindex3 rebuild reverse;#转换成反转索引

10.online rebuild of indexes
sql> alter index testindex3 rebuild online #不锁定表,原有索引的基础上建

11.coalescing indexes 碎片整理
sql> alter index testindex3 coalesce;

12.checking index validity  校验索引
sql> analyze index testindex validate structrue;

13.dropping indexes
sql> drop index testindex;

14.identifying unused indexes
sql> alter index testindex monitoring useage;   #开始监视
sql> alter index testindex nomonitoring useage; #取消监视

15. obtaining index information
   dba_indexes, dba_ind_columns, dba_ind_expressions,v$object_usage
16.oracle B-tree和bitmap索引区别
1、都是树型结构,叶子节点存储内容不一样。
2、列的取值范围较大(适合常规b—tree索
引),取值范围较小(适合位图索引);
3、由于bitmap索引的特点,他不是unique型的,
也不涉及unique概念。
4、bitmap通常where如果有or连接效率比较高。
5、b-tree适合
oltp,bitmap适合数据仓库。

16.索引占用空间使用情况
sql>analyze index ***.***_subscriber_groupid_indx validate structure;
Index analyzed.

column name format a15
column blocks heading "ALLOCATED|BLOCKS"
column lf_blks heading "LEAF|BLOCKS"
column br_blks heading "BRANCH|BLOCKS"
column Empty heading "UNUSED|BLOCKS"

SQL> list
1  select name,
2         blocks,
3         lf_blks,
4         br_blks,
5         blocks-(lf_blks+br_blks) empty
6* from   index_stats
SQL> /
ALLOCATED       LEAF     BRANCH     UNUSED
NAME                BLOCKS     BLOCKS     BLOCKS     BLOCKS
————— ———- ———- ———- ———-
***_SUBSCRIBER        640        577          3         60
_GROUPID_INDX

也可通过如下的查询来确定该索引在BTREE空间内使用情况

SQL> list
1  select name,
2         btree_space,
3         used_space,
4         pct_used
5* from   index_stats
SQL> /

NAME                           BTREE_SPACE USED_SPACE   PCT_USED
—————————— ———– ———- ———-
AGCF_SUBSCRIBER_GROUPID_INDX       4637776    3027283         66



 

posted on 2009-11-22 18:18 gdufo 阅读(518) 评论(0)  编辑  收藏 所属分类: Database (oracle, sqlser,MYSQL)

导航

统计

常用链接

留言簿(6)

随笔分类

随笔档案

文章分类

文章档案

收藏夹

Hibernate

友情链接

搜索

最新评论

阅读排行榜

评论排行榜