本文介紹了再Oracle中創建索引的方法及策略。Oracle索引和對應的表應該位于不同的表空間中,Oracle能夠并行讀取位于不同硬盤上的數據,可以避免產生I/O沖突B樹索引:在B樹的葉節點中存儲索引字段的值與ROWID.唯一索引和不唯一索引都只是針對B樹索引而言。
Oracle最多允許包含32個字段的復合索引。
1、Oracle索引創建策略
(1)導入數據后再創建索引
(2)不需要為很小的表創建索引
(3)對于取值范圍很小的字段(比如性別字段)應當建立位圖索引
(4)限制表中的索引的數目
(5)為索引設置合適的PCTFREE值
(6)存儲索引的表空間最好單獨設定
2、創建不唯一索引
create index emp_ename on employees(ename)
tablespace users
torage(……)
pctfree 0;
3、創建唯一索引
create unique index emp_email on employees(email)
tablespace users;
4、創建位圖索引
create bitmap index emp_sex on employees(sex)
tablespace users;
5、創建反序索引
create unique index order_reinx on orders(order_num,order_date)
tablespace users
reverse;
6、創建函數索引(函數索引即可以是普通的B樹索引,也可以是位圖索引)
create index emp_substr_empno on employees(substr(empno,1,2))
新聞熱點
疑難解答