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 閱讀(529) 評論(0) 編輯 收藏 所屬分類: Database (oracle, sqlser,MYSQL)