本篇內(nèi)容主要講解“Oracle Partition怎么使用”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“Oracle Partition怎么使用”吧!
臨沭網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),臨沭網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為臨沭上千余家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站建設(shè)要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的臨沭做網(wǎng)站的公司定做!
Oracle分區(qū)索引類型
Local Index
A.Local Prefixed Index
可以理解為分區(qū)索引的第一個(gè)索引字段是分區(qū)表的Partition key
B.Local Non-Prefixed Index
可以理解為分區(qū)索引的第一個(gè)索引字段不是分區(qū)表的Partition key
Global Prefixed Index
A.range類型分區(qū)
B.hash類型分區(qū)
注意:這兩種Global索引分區(qū)類型與基表的分區(qū)類型沒有關(guān)系。我們可以在非分區(qū)表上創(chuàng)建該索引
Global Non-Prefixed Index(目前Oracle還不支持)
創(chuàng)建該索引時(shí)會(huì)提示ORA-14038: GLOBAL partitioned index must be prefixed
注意:Local Index索引分區(qū)和基表分區(qū)是一一對(duì)應(yīng)的
Global Index索引分區(qū)和基表分區(qū)是相互獨(dú)立,不存在索引分區(qū)和表分區(qū)之間的一一對(duì)應(yīng)關(guān)系
比如基表有5個(gè)分區(qū),索引有2個(gè)分區(qū)
如何確定分區(qū)索引是Global/Local,PREFIXED/NON-PREFIXED
SQL> select index_name,table_name,locality,alignment from dba_part_indexes where owner='OHSDBA'; INDEX_NAME TABLE_NAME LOCALITY ALIGNMENT ------------------------ ------------ ---------- -------------- IDX_GLOBAL_PREFIXED OHS_PART GLOBAL PREFIXED IDX_LOCAL_NON_PREFIXED OHS_PART LOCAL NON_PREFIXED
如何選取分區(qū)索引類型
When deciding what kind of partitioned index to use, you should consider the following guidelines in this order:
If the table partitioning column is a subset of the index keys, then use a local index. If this is the case, then you are finished. If this is not the case, then continue to guideline 2.
If the index is unique and does not include the partitioning key columns, then use a global index. If this is the case, then you are finished. Otherwise, continue to guideline 3.
If your priority is manageability, then consider a local index. If this is the case, then you are finished. If this is not the case, continue to guideline 4.
If the application is an OLTP type and users need quick response times, then use a global index. If the application is a DSS type and users are more interested in throughput, then use a local index.
For more information about partitioned indexes and how to decide which type to use, refer to Using Partitioning in a Data Warehouse Environment and Using Partitioning in an Online Transaction Processing Environment.
以下的維護(hù)操作,易導(dǎo)致索引分區(qū)UNUSABLE
1. IMPORT PARTITION or conventional path SQL*Loader.
2. Direct-path SQL*Loader沒有成功完成(local index partitions and global indexes)
3. 維護(hù)操作類似ALTER TABLE MOVE PARTITION.
4. 維護(hù)操作類似ALTER TABLE TRUNCATE PARTITION.
5. 維護(hù)操作類似ALTER TABLE SPLIT PARTITION.
6. 維護(hù)操作類似ALTER INDEX SPLIT PARTITION.
7. 對(duì)Hash分區(qū)類型的表增加分區(qū)(分區(qū)中數(shù)據(jù)會(huì)變化)
如何避免索引UNUSABLE
為了防止分區(qū)維護(hù)的操作造成Index不可用,我們可以使用帶'update global indexes'的語(yǔ)句,以下的操作支持UPDATE GLOBAL INDEXES:
1. ADD PARTITION|SUBPARTITION (hash only)
2. COALESCE PARTITION|SUBPARTITION
3. DROP PARTITION
4. EXCHANGE PARTITION|SUBPARTITIO
5. MERGE PARTITION
6. MOVE PARTITION|SUBPARTITION
7. SPLIT PARTITION
8. TRUNCATE PARTITION|SUBPARTITION
Update Global Indexes和Update Indexes的區(qū)別
Update Global Indexes只維護(hù)全局索引,Update Indexes會(huì)同時(shí)維護(hù)全局和本地索引。Update Global Indexes可以理解為是Update Indexes的子集。假定當(dāng)前有一個(gè)表,在其上面創(chuàng)建了local和global partitioned index,我們把其中一個(gè)非空的分區(qū)做spilt/merge,如果只使用Update Global Indexes,那么Local Index會(huì)被標(biāo)記成UNUSABLE。如果使用Update Indexes,則兩者都有效。Oracle 9.2中可以使用'update global indexes',10g之后可以使用'update global indexes'/'update indexes'
測(cè)試可用腳本
create table ohs_part (id number, pdate date) partition by range(pdate) (partition ohs_201701 values less than (to_date('2017-02-01','yyyy-mm-dd')), partition ohs_201702 values less than (to_date('2017-03-01','yyyy-mm-dd')), partition ohs_201703 values less than (to_date('2017-04-01','yyyy-mm-dd')), partition ohs_201704 values less than (to_date('2017-05-01','yyyy-mm-dd')), partition ohs_max values less than (maxvalue)) / insert into ohs_part select 1, sysdate from dual; insert into ohs_part select 2, sysdate from dual; insert into ohs_part select 3, sysdate - 15 from dual; insert into ohs_part select 4, sysdate - 15 from dual; insert into ohs_part select 5, sysdate + 30 from dual; insert into ohs_part select 6, sysdate + 30 from dual; insert into ohs_part select 7, sysdate + 60 from dual; insert into ohs_part select 8, sysdate + 60 from dual; commit; create index idx_local on ohs_part(pdate) local; create index idx_normal on ohs_part(id); create index idx_global on ohs_part(pdate,id) global; SQL> create index idx_local on ohs_part(pdate) local; Index created. SQL> create index idx_normal on ohs_part(id); Index created. SQL> SQL> create index idx_global on ohs_part(pdate,id) global; Index created. SQL> SQL> col index_name for a30 SQL> select index_name,partitioned,status from user_indexes where table_name='OHS_PART'; INDEX_NAME PARTITION STATUS ------------------------------ --------- ------------------------ IDX_GLOBAL NO VALID IDX_NORMAL NO VALID IDX_LOCAL YES N/A SQL> select index_name,status from user_ind_partitions where index_name='IDX_LOCAL'; INDEX_NAME STATUS ------------------------------ ------------------------ IDX_LOCAL USABLE IDX_LOCAL USABLE IDX_LOCAL USABLE IDX_LOCAL USABLE IDX_LOCAL USABLE SQL> SQL> col table_name for a20 SQL> select index_name,table_name,locality,alignment from dba_part_indexes where owner='OHSDBA'; INDEX_NAME TABLE_NAME LOCALITY ALIGNMENT -------------------- -------------------- ------------------ -------------------- IDX_LOCAL OHS_PART LOCAL PREFIXED SQL> SQL> create index idx_local_non_prefixed on ohs_part(id,pdate) local; Index created. SQL> SQL> select index_name,table_name,locality,alignment from dba_part_indexes where owner='OHSDBA'; INDEX_NAME TABLE_NAME LOCALITY ALIGNMENT ------------------------------ -------------------- ------------------ -------------------- IDX_LOCAL OHS_PART LOCAL PREFIXED IDX_LOCAL_NON_PREFIXED OHS_PART LOCAL NON_PREFIXED SQL> drop index idx_local; CREATE INDEX idx_global_prefixed ON ohs_part(pdate) GLOBAL PARTITION BY RANGE(pdate) (partition ohs_ind_201701 values less than (to_date('2017-02-01','yyyy-mm-dd')), partition ohs_ind_201702 values less than (to_date('2017-03-01','yyyy-mm-dd')), partition ohs_ind_201703 values less than (to_date('2017-04-01','yyyy-mm-dd')), partition ohs_ind_201704 values less than (to_date('2017-05-01','yyyy-mm-dd')), partition ohs_ind__max values less than (maxvalue)) / SQL> drop index idx_local; Index dropped. SQL> col index_name for a30 SQL> select index_name,table_name,locality,alignment from dba_part_indexes where owner='OHSDBA'; INDEX_NAME TABLE_NAME LOCALITY ALIGNMENT ------------------------------ -------------------- ------------------ -------------------- IDX_LOCAL_NON_PREFIXED OHS_PART LOCAL NON_PREFIXED SQL> CREATE INDEX idx_global_prefixed ON ohs_part(pdate) 2 GLOBAL PARTITION BY RANGE(pdate) 3 (partition ohs_ind_201701 values less than (to_date('2017-02-01','yyyy-mm-dd')), 4 partition ohs_ind_201702 values less than (to_date('2017-03-01','yyyy-mm-dd')), 5 partition ohs_ind_201703 values less than (to_date('2017-04-01','yyyy-mm-dd')), 6 partition ohs_ind_201704 values less than (to_date('2017-05-01','yyyy-mm-dd')), 7 partition ohs_ind__max values less than (maxvalue)) 8 / Index created. SQL> select index_name,table_name,locality,alignment from dba_part_indexes where owner='OHSDBA'; INDEX_NAME TABLE_NAME LOCALITY ALIGNMENT ------------------------------ -------------------- ------------------ -------------------- IDX_GLOBAL_PREFIXED OHS_PART GLOBAL PREFIXED IDX_LOCAL_NON_PREFIXED OHS_PART LOCAL NON_PREFIXED SQL>
到此,相信大家對(duì)“Oracle Partition怎么使用”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
分享名稱:OraclePartition怎么使用
鏈接分享:http://www.rwnh.cn/article24/pgcdje.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、云服務(wù)器、做網(wǎng)站、品牌網(wǎng)站制作、網(wǎng)站維護(hù)、定制開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)