Oracle索引技術(shù)之如何建立最佳索引
本文關(guān)鍵詞:Oracle索引技術(shù),由筆耕文化傳播整理發(fā)布。
> Oracle > 正文 Oracle索引技術(shù)之如何建立最佳索引 2011-08-02 我要投稿
怎樣建立最佳索引?
1、明確地創(chuàng)建索引
create index index_name on table_name(field_name)
tablespace tablespace_name
pctfree 5
initrans 2
maxtrans 255
storage
(
minextents 1
maxextents 16382
pctincrease 0
);
2、創(chuàng)建基于函數(shù)的索引
常用與UPPER、LOWER、TO_CHAR(date)等函數(shù)分類上,例:
create index idx_func on emp(UPPER(ename)) tablespace tablespace_name;
3、創(chuàng)建位圖索引
對基數(shù)較小,且基數(shù)相對穩(wěn)定的列建立索引時,首先應該考慮位圖索引,例:
create bitmap index idx_bitm on class (classno) tablespace tablespace_name;
4、明確地創(chuàng)建唯一索引
可以用create unique index語句來創(chuàng)建唯一索引,例:
create unique index dept_unique_idx on dept(dept_no) tablespace idx_1;
5、創(chuàng)建與約束相關(guān)的索引
可以用using index字句,為與unique和primary key約束相關(guān)的索引,例:
alter table table_name
add constraint PK_primary_keyname primary key(field_name)
using index tablespace tablespace_name;
如何創(chuàng)建局部區(qū)索引?
1)基礎(chǔ)表必須是分區(qū)表
2)分區(qū)數(shù)量與基礎(chǔ)表相同
3)每個索引分區(qū)的子分區(qū)數(shù)量與相應的基礎(chǔ)表分區(qū)相同
4)基礎(chǔ)表的自分區(qū)中的行的索引項,被存儲在該索引的相應的自分區(qū)中,例如
create index TG_CDR04_SERV_ID_IDX on TG_CDR04(SERV_ID)
Pctfree 5
Tablespace TBS_AK01_IDX
Storage(
MaxExtents 32768
PctIncrease 0
FreeLists 1
FreeList Groups 1
)
local
/
如何創(chuàng)建范圍分區(qū)的全局索引?
基礎(chǔ)表可以是全局表和分區(qū)表
create index idx_start_date on tg_cdr01(start_date)
global partition by range(start_date)
(partition p01_idx vlaues less than ('0106')
partition p01_idx vlaues less than ('0111')
...
partition p01_idx vlaues less than ('0401'))
/
如何重建現(xiàn)存的索引?
重建現(xiàn)存的索引的當前時刻不會影響查詢
重建索引可以刪除額外的數(shù)據(jù)塊
提高索引查詢效率
alter index idx_name rebuild nologging;
對于分區(qū)索引
alter index idx_name rebuild partition partition_name nologging;
刪除索引的原因?
1)不再需要的索引
2)索引沒有針對其相關(guān)的表所發(fā)布的查詢提供所期望的性能改善
3)應用沒有用該索引來查詢數(shù)據(jù)
4)該索引無效,必須在重建之前刪除該索引
5)該索引已經(jīng)變的太碎了,必須在重建之前刪除該索引
語句:
drop index idx_name;
drop index idx_name partition partition_name;
建立索引的代價?
基礎(chǔ)表維護時,系統(tǒng)要同時維護索引,不合理的索引將嚴重影響系統(tǒng)資源,,
主要表現(xiàn)在CPU和I/O上。
插入、更新、刪除數(shù)據(jù)產(chǎn)生大量db file sequential read鎖等待。
點擊復制鏈接 與好友分享!回本站首頁 上一篇:OCP043第八講Monitoring and Managing Memory 下一篇: Oracle MapViewer11g安裝與部署 相關(guān)文章 圖文推薦本文關(guān)鍵詞:Oracle索引技術(shù),由筆耕文化傳播整理發(fā)布。
本文編號:46829
本文鏈接:http://sikaile.net/wenshubaike/mishujinen/46829.html