Oracle-建立索引分割區

來源:互聯網
上載者:User

標籤:

對大資料量索引進行分區同樣能夠最佳化應用系統的效能。一般來說,如果索引所對應的表的資料量非常大,比如幾百萬甚至上千萬條資料,則索引也會佔用很大的空間,這時,建議對索引進行分區。

  Oracle索引分割區分為本地索引分割區和全域索引分割區兩種:全域索引不反映基礎資料表的結構,因此,若要分區就只能進行定界分割;而局部索引反映基礎資料表的結構。

 

本地索引分割區

  本地索引分割區就是使用和分區表同樣的分區鍵進行分區的索引,也就是說,索引分割區所採用的列與該表的分區所採用的列是相同的,本地索引有以下優點:

如果只有一個分區需要維護,則只有一個本地索引受影響

支援分區獨立性

只有本地索引能夠支援單一分區的裝入和卸載
表分區和各自的本地索引可以同時恢複
本地索引可以單獨重複
位元影像索引僅由本地索引支援

如:建立一個表分區,然後根據這個表分區建立本地索引區
1.首先建立3個資料表空間,分別存放到3不同磁碟分割中,分別為ts_1,ts_2,ts_3

2.建立一個儲存學產生績的分區表studentgrade,該表共有3個分區,分別位於資料表空間 ts_1,ts_2,ts_3

create table studentgrade
(
id number primary key,
name varchar2(10),
subject varchar2(10),
grade number
)
partition by range(grade)
(
partition par_nopass values less than(60) tablespace ts_1,
partition par_pass values less than(70) tablespace ts_2,
partition par_good values less than(maxvalue) tablespace ts_3
)
/

3.根據表分區建立本地索引分割區,與表分區一樣,索引分割區也是3個分區(p1,p2,p3)

create index grade_index on studentgrade(grade)
local
(
partition p1 tablespace ts_1,
partition p2 tablespace ts_2,
partition p3 tablespace ts_3
)
/

4.最後,使用者可以通過查詢dba_ind_partitions視圖來查看索引分割區資訊

select partition_name,tablespace_name from dba_ind_partitions where index_name=‘GRADE_INDEX‘;

 

全域索引區

  全域索引就是沒有與分區表相同分區鍵的分區索引。當分區中出現許多事物並且要保證所有分區中的資料記錄唯一時,採用全域索引分割區

無論表是否採用分區,都可以對錶採用全域索引分割區,此外,不能對Cluster表、位元影像索引採用全域索引分割區


如:以books表的saleprice列為索引列和分區鍵,建立一個定界分割的全域索引

create index index_saleprcie on books(saleprice)

global  partition by range(saleprice)

(

partition p1 values less than(30),

partition p2 values less than(50),

partition p3 values less than(maxvalue)

);

 

如:以books表的ISBN列為索引列和分區鍵,建立一個HASH分區的全域索引

create index index_ISBN on books(ISBN)

global partition by hash(ISBN);

 

 

管理索引分割區

  在管理索引分割區中的各種操作中,常用的操作主要包括刪除索引分割區和重新命名索引分割區

1.刪除索引分割區

在books表的index_saleprice索引中,使用alter index... drop partition語句刪除其中的索引分割區p2

alter index index_saleprice drop partition p2;

對於全域索引分割區,不能刪除索引的最高分區,否則系統會提示錯誤

 

  在刪除若干索引分割區之後,如果只剩餘一個索引分割區,則需要對這個分區進行重建,重建分區可以使用alter index..rebuild partition

如:在books表的index_saleprice索引中,刪除其中p2和p1索引分割區,然後使用alter index... rebuild partition語句重建索引分割區p3

alter index index_saleprice drop  partition p2;

alter index index_saleprice drop  partition p1;

alter index index_saleprice rebuild partition p3;

 

  重新命名索引分割區

如:在index_saleprice索引中,使用alter  index... rename partition 重新命名索引分割區p3

alter index index_saleprice rename partition p3 to p_new;

 

Oracle-建立索引分割區

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.