日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

oracle索引建立

發(fā)布時間:2023/12/10 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 oracle索引建立 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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)建與約束相關的索引

可以用using index字句,為與unique和primary key約束相關的索引,例:

alter table table_name

add constraint PK_primary_keyname primary key(field_name)

using index tablespace tablespace_name;

?

如何創(chuàng)建局部區(qū)索引?

1)基礎表必須是分區(qū)表

2)分區(qū)數(shù)量與基礎表相同

3)每個索引分區(qū)的子分區(qū)數(shù)量與相應的基礎表分區(qū)相同

4)基礎表的自分區(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ū)的全局索引?

基礎表可以是全局表和分區(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)索引沒有針對其相關的表所發(fā)布的查詢提供所期望的性能改善

3)應用沒有用該索引來查詢數(shù)據(jù)

4)該索引無效,必須在重建之前刪除該索引

5)該索引已經(jīng)變的太碎了,必須在重建之前刪除該索引

語句:

drop index idx_name;

drop index idx_name partition partition_name;

?

建立索引的代價?

基礎表維護時,系統(tǒng)要同時維護索引,不合理的索引將嚴重影響系統(tǒng)資源,

主要表現(xiàn)在CPU和I/O上。

插入、更新、刪除數(shù)據(jù)產(chǎn)生大量db file sequential read鎖等待。


轉(zhuǎn)載于:https://blog.51cto.com/jialong/1658443

總結(jié)

以上是生活随笔為你收集整理的oracle索引建立的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。