本地分區索引、全局本地分區索引


 官網截圖:

global partition index

local partition index

 

                   《全局分區索引》

drop table JS_SKSKJDK_DZFPMX02 purge;


--創建分區表 jssj
SQL> create table JS_SKSKJDK_DZFPMX02(
      fpdm      VARCHAR2(12) not null,
      fphm      VARCHAR2(8) not null,
      jssj      DATE,
      CONSTRAINT PK_JS_SKSKJDK_DZFPMX02 PRIMARY KEY(FPHM,FPDM)
      USING INDEX TABLESPACE users
    )
     PARTITION BY RANGE(JSSJ)
       (PARTITION p01 VALUES LESS THAN(to_date('2016/8/31 10:53:40','yyyy-mm-dd hh24:mi:ss')) TABLESPACE users) enable row movement;

Table created.

--創建全局分區索引
drop index ind_jssj02;

SQL> create index ind_jssj02 on JS_SKSKJDK_DZFPMX02(jssj)  global
    partition by range (jssj)
    (
    partition p02 values  less than (to_date('2016/10/30 10:53:40','yyyy-mm-dd hh24:mi:ss')) ,
    partition p03 values  less than (to_date('2016/11/30 10:53:40','yyyy-mm-dd hh24:mi:ss')),
    partition p04 values  less than (to_date('2016/12/3 10:53:40','yyyy-mm-dd hh24:mi:ss')),
    partition p05 values  less than (to_date('2016/12/30 10:53:40','yyyy-mm-dd hh24:mi:ss')),
    partition pmax values  less than (maxvalue)
    ) ;

Index created.

-- 為分區表新增分區
SQL> alter table JS_SKSKJDK_DZFPMX02 add partition p02 values  less than (to_date('2016/10/30 10:53:40','yyyy-mm-dd hh24:mi:ss')) tablespace  users;

Table altered.

SQL> alter table JS_SKSKJDK_DZFPMX02 add partition p03 values  less than (to_date('2016/11/30 10:53:40','yyyy-mm-dd hh24:mi:ss')) tablespace  users;

Table altered.

SQL> alter table JS_SKSKJDK_DZFPMX02 add partition p04 values  less than (to_date('2016/12/3 10:53:40','yyyy-mm-dd hh24:mi:ss')) tablespace  users;

Table altered.

SQL> alter table JS_SKSKJDK_DZFPMX02 add partition p05 values  less than (to_date('2016/12/30 10:53:40','yyyy-mm-dd hh24:mi:ss')) tablespace  users;

Table altered.

-- 將全局分區索引重建於指定的索引分區
alter index ind_jssj02  rebuild partition  p04 tablespace users;

--分區表插入測試數據
SQL> insert into JS_SKSKJDK_DZFPMX02 values('1','1',sysdate);

1 row created.

SQL> insert into JS_SKSKJDK_DZFPMX02 values('2','2',sysdate);

1 row created.

SQL> insert into JS_SKSKJDK_DZFPMX02 values('3','3',sysdate);

1 row created.


--檢查索引狀態
SQL> select  t2.locality,t1.index_name,t1.partition_name,t1.status,t1.tablespace_name
    from user_ind_partitions t1, user_part_indexes t2  where t1.index_name in ('IND_JSSJ02') and t1.index_name=t2.index_name
    order by index_name,partition_name;

LOCALI INDEX_NAME                     PARTITION_NAME                 STATUS   TABLESPACE_NAME
------ ------------------------------ ------------------------------ -------- ------------------------------
GLOBAL IND_JSSJ02                     P02                            USABLE   USERS
GLOBAL IND_JSSJ02                     P03                            USABLE   USERS
GLOBAL IND_JSSJ02                     P04                            USABLE   USERS
GLOBAL IND_JSSJ02                     P05                            USABLE   USERS
GLOBAL IND_JSSJ02                     PMAX                           USABLE   USERS

--刪除某個分區
SQL> alter table JS_SKSKJDK_DZFPMX02  drop partition p02;

Table altered.

--再次檢查索引狀態
SQL> select  t2.locality,t1.index_name,t1.partition_name,t1.status,t1.tablespace_name
        from user_ind_partitions t1, user_part_indexes t2  where t1.index_name in ('IND_JSSJ02') and t1.index_name=t2.index_name
        order by index_name,partition_name;

LOCALI INDEX_NAME                     PARTITION_NAME                 STATUS   TABLESPACE_NAME
------ ------------------------------ ------------------------------ -------- ------------------------------
GLOBAL IND_JSSJ02                     P02                            UNUSABLE USERS
GLOBAL IND_JSSJ02                     P03                            UNUSABLE USERS
GLOBAL IND_JSSJ02                     P04                            UNUSABLE USERS
GLOBAL IND_JSSJ02                     P05                            UNUSABLE USERS
GLOBAL IND_JSSJ02                     PMAX                           UNUSABLE USERS


--結論: 全局分區索引果然不會自動維護分區索引啊

 

                                               《本地分區索引》

drop table JS_SKSKJDK_DZFPMX01 purge;


--創建分區表 jssj
SQL> create table JS_SKSKJDK_DZFPMX01(
      fpdm      VARCHAR2(12) not null,
      fphm      VARCHAR2(8) not null,
      jssj      DATE,
      CONSTRAINT PK_JS_SKSKJDK_DZFPMX01 PRIMARY KEY(FPHM,FPDM)
      USING INDEX TABLESPACE users
    )
     PARTITION BY RANGE(JSSJ)
       (PARTITION p01 VALUES LESS THAN(to_date('2016/8/31 10:53:40','yyyy-mm-dd hh24:mi:ss')) TABLESPACE users) enable row movement;

Table created.

--創建本地分區索引
SQL> create index ind_jssj01 on JS_SKSKJDK_DZFPMX01(jssj)  local tablespace users;

Index created.


-- 為分區表新增分區
SQL> alter table JS_SKSKJDK_DZFPMX01 add partition p02 values  less than (to_date('2016/10/30 10:53:40','yyyy-mm-dd hh24:mi:ss')) tablespace  users;

Table altered.

SQL> alter table JS_SKSKJDK_DZFPMX01 add partition p03 values  less than (to_date('2016/11/30 10:53:40','yyyy-mm-dd hh24:mi:ss')) tablespace  users;

Table altered.

SQL> alter table JS_SKSKJDK_DZFPMX01 add partition p04 values  less than (to_date('2016/12/3 10:53:40','yyyy-mm-dd hh24:mi:ss')) tablespace  users;

Table altered.

SQL> alter table JS_SKSKJDK_DZFPMX01 add partition p05 values  less than (to_date('2016/12/30 10:53:40','yyyy-mm-dd hh24:mi:ss')) tablespace  users;

Table altered.

-- 將局部索引重建於指定的索引分區
alter index ind_jssj  rebuild partition  part04 tablespace users;

--檢查索引狀態
SQL> select  t2.locality,t1.index_name,t1.partition_name,t1.status,t1.tablespace_name from user_ind_partitions t1, user_part_indexes t2  where t1.index_name in ('IND_JSSJ01') and t1.index_name=t2.index_name
  2  order by index_name,partition_name;

LOCALI INDEX_NAME                     PARTITION_NAME                 STATUS   TABLESPACE_NAME
------ ------------------------------ ------------------------------ -------- ------------------------------
LOCAL  IND_JSSJ01                     P01                            USABLE   USERS
LOCAL  IND_JSSJ01                     P02                            USABLE   USERS
LOCAL  IND_JSSJ01                     P03                            USABLE   USERS
LOCAL  IND_JSSJ01                     P04                            USABLE   USERS
LOCAL  IND_JSSJ01                     P05                            USABLE   USERS


--刪除某個分區
SQL> alter table JS_SKSKJDK_DZFPMX01  drop partition p02;

Table altered.

--再次檢查索引狀態   

SQL> select  t2.locality,t1.index_name,t1.partition_name,t1.status,t1.tablespace_name from user_ind_partitions t1, user_part_indexes t2  where t1.index_name in ('IND_JSSJ01') and t1.index_name=t2.index_name
  2  order by index_name,partition_name;

LOCALI INDEX_NAME                     PARTITION_NAME                 STATUS   TABLESPACE_NAME
------ ------------------------------ ------------------------------ -------- ------------------------------
LOCAL  IND_JSSJ01                     P01                            USABLE   USERS
LOCAL  IND_JSSJ01                     P03                            USABLE   USERS
LOCAL  IND_JSSJ01                     P04                            USABLE   USERS
LOCAL  IND_JSSJ01                     P05                            USABLE   USERS

--結論 本地分區索引,刪除某個分區 對於其他的索引分區沒有任何影響


 
 
 

 

 


 
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM