【Oracle】表级别分区操作对索引(本地分区索引,全局分区索引,非分区索引)的影响

--参考自《Oracle索引技术》

先贴上结论吧:

【Oracle】表级别分区操作对索引(本地分区索引,全局分区索引,非分区索引)的影响_第1张图片

下面对以上几种操作分别测试:

创建测试表及索引

--创建测试分区表
CREATE TABLE employees_parttest
(
  employee_id    NUMBER(6) not null,
  first_name     VARCHAR2(20),
  last_name      VARCHAR2(25),
  email          VARCHAR2(25),
  phone_number   VARCHAR2(20),
  hire_date      DATE,
  job_id         VARCHAR2(10),
  salary         NUMBER(8,2),
  commission_pct NUMBER(2,2),
  manager_id     NUMBER(6),
  department_id  NUMBER(4)
)
PARTITION BY RANGE (hire_date)
(
PARTITION p2000 VALUES LESS THAN (to_date('2001-01-01','yyyy-mm-dd')),
PARTITION p2001 VALUES LESS THAN (to_date('2002-01-01','yyyy-mm-dd')),
PARTITION p2002 VALUES LESS THAN (to_date('2003-01-01','yyyy-mm-dd')),
PARTITION p2003 VALUES LESS THAN (to_date('2004-01-01','yyyy-mm-dd')),
PARTITION p2004 VALUES LESS THAN (to_date('2005-01-01','yyyy-mm-dd')),
PARTITION p2005 VALUES LESS THAN (to_date('2006-01-01','yyyy-mm-dd')),
PARTITION p2006 VALUES LESS THAN (to_date('2007-01-01','yyyy-mm-dd')),
PARTITION p2007 VALUES LESS THAN (to_date('2008-01-01','yyyy-mm-dd')),
PARTITION p2008 VALUES LESS THAN (to_date('2009-01-01','yyyy-mm-dd'))
);

--插入测试数据
INSERT INTO employees_parttest SELECT * FROM hr.employees;

--创建本分分区索引
CREATE INDEX employees_parttest_li
ON employees_parttest (hire_date)
LOCAL;

--创建全局分区索引
CREATE INDEX employees_gi1
ON employees_parttest (manager_id)
GLOBAL
PARTITION BY RANGE(manager_id)
(
PARTITION manager_100 VALUES LESS THAN (100),
PARTITION manager_200 VALUES LESS THAN (200),
PARTITION manager_300 VALUES LESS THAN (300),
PARTITION manager_400 VALUES LESS THAN (400),
PARTITION manager_500 VALUES LESS THAN (500),
PARTITION manager_600 VALUES LESS THAN (600),
PARTITION manager_700 VALUES LESS THAN (700),
PARTITION manager_800 VALUES LESS THAN (800),
PARTITION manager_900 VALUES LESS THAN (900),
PARTITION manager_max VALUES LESS THAN (MAXVALUE)
);

--创建非分区索引
CREATE INDEX employees_parttest_i1 ON employees_parttest(employee_id);

查询创建完成后三种索引的状态:均为可用状态

--查询索引状态
SQL> SELECT index_name,NULL partition_name,status FROM user_indexes t WHERE t.table_name='EMPLOYEES_PARTTEST'
AND t.partitioned = 'NO'
UNION 
SELECT index_name,partition_name,status FROM User_Ind_Partitions
WHERE index_name IN (SELECT index_name FROM user_indexes WHERE table_name='EMPLOYEES_PARTTEST')
ORDER BY 1,2,3;

INDEX_NAME		       PARTITION_NAME		      STATUS
------------------------------ ------------------------------ --------
EMPLOYEES_GI1		       MANAGER_100		      USABLE
EMPLOYEES_GI1		       MANAGER_200		      USABLE
EMPLOYEES_GI1		       MANAGER_300		      USABLE
EMPLOYEES_GI1		       MANAGER_400		      USABLE
EMPLOYEES_GI1		       MANAGER_500		      USABLE
EMPLOYEES_GI1		       MANAGER_600		      USABLE
EMPLOYEES_GI1		       MANAGER_700		      USABLE
EMPLOYEES_GI1		       MANAGER_800		      USABLE
EMPLOYEES_GI1		       MANAGER_900		      USABLE
EMPLOYEES_GI1		       MANAGER_MAX		      USABLE
EMPLOYEES_PARTTEST_I1					      VALID

INDEX_NAME		       PARTITION_NAME		      STATUS
------------------------------ ------------------------------ --------
EMPLOYEES_PARTTEST_LI	       P2000			      USABLE
EMPLOYEES_PARTTEST_LI	       P2001			      USABLE
EMPLOYEES_PARTTEST_LI	       P2002			      USABLE
EMPLOYEES_PARTTEST_LI	       P2003			      USABLE
EMPLOYEES_PARTTEST_LI	       P2004			      USABLE
EMPLOYEES_PARTTEST_LI	       P2005			      USABLE
EMPLOYEES_PARTTEST_LI	       P2006			      USABLE
EMPLOYEES_PARTTEST_LI	       P2007			      USABLE
EMPLOYEES_PARTTEST_LI	       P2008			      USABLE
EMPLOYEES_PARTTEST_LI	       P2009			      USABLE

21 rows selected.

1. 增加分区

三种索引都不受影响

SQL> ALTER TABLE employees_parttest ADD PARTITION P2010 VALUES LESS THAN (to_date('2011-01-01','yyyy-mm-dd'));

SQL> SELECT t1.index_name,NULL parttion_name, t1.status
  2  FROM dba_indexes t1
  3  WHERE t1.table_name = 'EMPLOYEES_PARTTEST'
  4  AND t1.partitioned = 'NO'
  5  UNION
  6  SELECT
  7  t2.index_name,
  8  t2.partition_name,
  9  t2.status
 10  FROM dba_ind_partitions t2
 11  WHERE t2.index_name IN (SELECT index_name FROM dba_indexes WHERE table_name = 'EMPLOYEES_PARTTEST');
INDEX_NAME                     PARTTION_NAME                  STATUS
------------------------------ ------------------------------ --------
EMPLOYEES_PARTTEST_GI          MANAGER_100                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_200                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_300                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_400                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_500                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_600                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_700                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_800                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_900                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_MAX                    USABLE
EMPLOYEES_PARTTEST_I1                                         VALID
EMPLOYEES_PARTTEST_LI          P2000                          USABLE
EMPLOYEES_PARTTEST_LI          P2001                          USABLE
EMPLOYEES_PARTTEST_LI          P2002                          USABLE
EMPLOYEES_PARTTEST_LI          P2003                          USABLE
EMPLOYEES_PARTTEST_LI          P2004                          USABLE
EMPLOYEES_PARTTEST_LI          P2005                          USABLE
EMPLOYEES_PARTTEST_LI          P2006                          USABLE
EMPLOYEES_PARTTEST_LI          P2007                          USABLE
EMPLOYEES_PARTTEST_LI          P2008                          USABLE
INDEX_NAME                     PARTTION_NAME                  STATUS
------------------------------ ------------------------------ --------
EMPLOYEES_PARTTEST_LI          P2009                          USABLE
EMPLOYEES_PARTTEST_LI          P2010                          USABLE
22 rows selected

2. 截断分区

非分区索引和全局分区索引不可用(unusable),本地分区索引不受影响(usable)。

SQL> ALTER TABLE employees_parttest TRUNCATE PARTITION p2000;
Table truncated

SQL> SELECT t1.index_name,NULL parttion_name, t1.status
  2  FROM dba_indexes t1
  3  WHERE t1.table_name = 'EMPLOYEES_PARTTEST'
  4  AND t1.partitioned = 'NO'
  5  UNION
  6  SELECT
  7  t2.index_name,
  8  t2.partition_name,
  9  t2.status
 10  FROM dba_ind_partitions t2
 11  WHERE t2.index_name IN (SELECT index_name FROM dba_indexes WHERE table_name = 'EMPLOYEES_PARTTEST');
INDEX_NAME                     PARTTION_NAME                  STATUS
------------------------------ ------------------------------ --------
EMPLOYEES_PARTTEST_GI          MANAGER_100                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_200                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_300                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_400                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_500                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_600                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_700                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_800                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_900                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_MAX                    USABLE
EMPLOYEES_PARTTEST_I1                                         VALID
EMPLOYEES_PARTTEST_LI          P2000                          USABLE
EMPLOYEES_PARTTEST_LI          P2001                          USABLE
EMPLOYEES_PARTTEST_LI          P2002                          USABLE
EMPLOYEES_PARTTEST_LI          P2003                          USABLE
EMPLOYEES_PARTTEST_LI          P2004                          USABLE
EMPLOYEES_PARTTEST_LI          P2005                          USABLE
EMPLOYEES_PARTTEST_LI          P2006                          USABLE
EMPLOYEES_PARTTEST_LI          P2007                          USABLE
EMPLOYEES_PARTTEST_LI          P2008                          USABLE
INDEX_NAME                     PARTTION_NAME                  STATUS
------------------------------ ------------------------------ --------
EMPLOYEES_PARTTEST_LI          P2009                          USABLE
EMPLOYEES_PARTTEST_LI          P2010                          USABLE
22 rows selected

3. 移动分区

非分区索引和全局分区索引均为不可用(unusable),本地分区索引中移动的分区为不可用(unusable),其他分区不受影响(usable)。

SQL> ALTER TABLE employees_parttest MOVE PARTITION P2001 TABLESPACE DBS_D_ODS;
Table altered

SQL> SELECT t1.index_name,NULL parttion_name, t1.status
  2  FROM dba_indexes t1
  3  WHERE t1.table_name = 'EMPLOYEES_PARTTEST'
  4  AND t1.partitioned = 'NO'
  5  UNION
  6  SELECT
  7  t2.index_name,
  8  t2.partition_name,
  9  t2.status
 10  FROM dba_ind_partitions t2
 11  WHERE t2.index_name IN (SELECT index_name FROM dba_indexes WHERE table_name = 'EMPLOYEES_PARTTEST');
INDEX_NAME                     PARTTION_NAME                  STATUS
------------------------------ ------------------------------ --------
EMPLOYEES_PARTTEST_GI          MANAGER_100                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_200                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_300                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_400                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_500                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_600                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_700                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_800                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_900                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_MAX                    UNUSABLE
EMPLOYEES_PARTTEST_I1                                         UNUSABLE
EMPLOYEES_PARTTEST_LI          P2000                          USABLE
EMPLOYEES_PARTTEST_LI          P2001                          UNUSABLE
EMPLOYEES_PARTTEST_LI          P2002                          USABLE
EMPLOYEES_PARTTEST_LI          P2003                          USABLE
EMPLOYEES_PARTTEST_LI          P2004                          USABLE
EMPLOYEES_PARTTEST_LI          P2005                          USABLE
EMPLOYEES_PARTTEST_LI          P2006                          USABLE
EMPLOYEES_PARTTEST_LI          P2007                          USABLE
EMPLOYEES_PARTTEST_LI          P2008                          USABLE
INDEX_NAME                     PARTTION_NAME                  STATUS
------------------------------ ------------------------------ --------
EMPLOYEES_PARTTEST_LI          P2009                          USABLE
EMPLOYEES_PARTTEST_LI          P2010                          USABLE
22 rows selected

4. 拆分分区

分两种情况:

(1)空分区被拆分

三种索引均不受影响

SQL> SELECT count(*) FROM employees_parttest PARTITION (P_max);
  COUNT(*)
----------
         0


SQL> ALTER TABLE employees_parttest SPLIT PARTITION P_max AT (to_date('2012-01-01','yyyy-mm-dd'))
  2  INTO (PARTITION P2011,
  3  PARTITION P_max);
Table altered


SQL> SELECT t1.index_name,NULL parttion_name, t1.status
  2  FROM dba_indexes t1
  3  WHERE t1.table_name = 'EMPLOYEES_PARTTEST'
  4  AND t1.partitioned = 'NO'
  5  UNION
  6  SELECT
  7  t2.index_name,
  8  t2.partition_name,
  9  t2.status
 10  FROM dba_ind_partitions t2
 11  WHERE t2.index_name IN (SELECT index_name FROM dba_indexes WHERE table_name = 'EMPLOYEES_PARTTEST');
INDEX_NAME                     PARTTION_NAME                  STATUS
------------------------------ ------------------------------ --------
EMPLOYEES_PARTTEST_GI          MANAGER_100                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_200                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_300                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_400                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_500                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_600                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_700                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_800                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_900                    USABLE
EMPLOYEES_PARTTEST_GI          MANAGER_MAX                    USABLE
EMPLOYEES_PARTTEST_I1                                         VALID
EMPLOYEES_PARTTEST_LI          P2000                          USABLE
EMPLOYEES_PARTTEST_LI          P2001                          USABLE
EMPLOYEES_PARTTEST_LI          P2002                          USABLE
EMPLOYEES_PARTTEST_LI          P2003                          USABLE
EMPLOYEES_PARTTEST_LI          P2004                          USABLE
EMPLOYEES_PARTTEST_LI          P2005                          USABLE
EMPLOYEES_PARTTEST_LI          P2006                          USABLE
EMPLOYEES_PARTTEST_LI          P2007                          USABLE
EMPLOYEES_PARTTEST_LI          P2008                          USABLE
INDEX_NAME                     PARTTION_NAME                  STATUS
------------------------------ ------------------------------ --------
EMPLOYEES_PARTTEST_LI          P2009                          USABLE
EMPLOYEES_PARTTEST_LI          P2010                          USABLE
EMPLOYEES_PARTTEST_LI          P2011                          USABLE
EMPLOYEES_PARTTEST_LI          P_MAX                          USABLE
24 rows selected

(2)非空分区被拆分

全局分区索引和非分区索引都为不可用(unusable),本地分区索引只有拆分出来的分区为不可用。

--新增了一个分区,自行往里面插入几条数据
SQL> alter table employees_parttest add partition p12_15 values less than (to_date('2016-01-01','yyyy-mm-dd'));
Table altered

SQL> ALTER TABLE employees_parttest SPLIT PARTITION p12_15 AT (to_date('2014-01-01','yyyy-mm-dd')) INTO (partition P12_13,partition P14_15);
Table altered

SQL> 
SQL> SELECT t1.index_name,NULL parttion_name, t1.status
  2  FROM dba_indexes t1
  3  WHERE t1.table_name = 'EMPLOYEES_PARTTEST'
  4  AND t1.partitioned = 'NO'
  5  UNION
  6  SELECT
  7  t2.index_name,
  8  t2.partition_name,
  9  t2.status
 10  FROM dba_ind_partitions t2
 11  WHERE t2.index_name IN (SELECT index_name FROM dba_indexes WHERE table_name = 'EMPLOYEES_PARTTEST');
INDEX_NAME                     PARTTION_NAME                  STATUS
------------------------------ ------------------------------ --------
EMPLOYEES_PARTTEST_GI          MANAGER_100                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_200                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_300                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_400                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_500                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_600                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_700                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_800                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_900                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_MAX                    UNUSABLE
EMPLOYEES_PARTTEST_I1                                         UNUSABLE
EMPLOYEES_PARTTEST_LI          P12_13                         UNUSABLE
EMPLOYEES_PARTTEST_LI          P14_15                         UNUSABLE
EMPLOYEES_PARTTEST_LI          P2000                          USABLE
EMPLOYEES_PARTTEST_LI          P2001                          USABLE
EMPLOYEES_PARTTEST_LI          P2002                          USABLE
EMPLOYEES_PARTTEST_LI          P2003                          USABLE
EMPLOYEES_PARTTEST_LI          P2004                          USABLE
EMPLOYEES_PARTTEST_LI          P2005                          USABLE
EMPLOYEES_PARTTEST_LI          P2006                          USABLE
INDEX_NAME                     PARTTION_NAME                  STATUS
------------------------------ ------------------------------ --------
EMPLOYEES_PARTTEST_LI          P2007                          USABLE
EMPLOYEES_PARTTEST_LI          P2008                          USABLE
EMPLOYEES_PARTTEST_LI          P2009                          USABLE
EMPLOYEES_PARTTEST_LI          P2010                          USABLE
EMPLOYEES_PARTTEST_LI          P2011                          USABLE
25 rows selected

 

5. 交换分区

全局分区索引和非分区索引都不可用(unusable),本地分区索引只有交换过的分区为不可用。

SQL> ALTER TABLE employees_parttest EXCHANGE PARTITION p2008 WITH TABLE employees_exch;
Table altered

SQL> SELECT t1.index_name,NULL parttion_name, t1.status
  2  FROM dba_indexes t1
  3  WHERE t1.table_name = 'EMPLOYEES_PARTTEST'
  4  AND t1.partitioned = 'NO'
  5  UNION
  6  SELECT
  7  t2.index_name,
  8  t2.partition_name,
  9  t2.status
 10  FROM dba_ind_partitions t2
 11  WHERE t2.index_name IN (SELECT index_name FROM dba_indexes WHERE table_name = 'EMPLOYEES_PARTTEST');
INDEX_NAME                     PARTTION_NAME                  STATUS
------------------------------ ------------------------------ --------
EMPLOYEES_PARTTEST_GI          MANAGER_100                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_200                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_300                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_400                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_500                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_600                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_700                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_800                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_900                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_MAX                    UNUSABLE
EMPLOYEES_PARTTEST_I1                                         UNUSABLE
EMPLOYEES_PARTTEST_LI          P2000                          USABLE
EMPLOYEES_PARTTEST_LI          P2001                          USABLE
EMPLOYEES_PARTTEST_LI          P2002                          USABLE
EMPLOYEES_PARTTEST_LI          P2003                          USABLE
EMPLOYEES_PARTTEST_LI          P2004                          USABLE
EMPLOYEES_PARTTEST_LI          P2005                          USABLE
EMPLOYEES_PARTTEST_LI          P2006                          USABLE
EMPLOYEES_PARTTEST_LI          P2007                          USABLE
EMPLOYEES_PARTTEST_LI          P2008                          UNUSABLE
INDEX_NAME                     PARTTION_NAME                  STATUS
------------------------------ ------------------------------ --------
EMPLOYEES_PARTTEST_LI          P2009                          USABLE
EMPLOYEES_PARTTEST_LI          P2010                          USABLE
EMPLOYEES_PARTTEST_LI          P2011                          USABLE
EMPLOYEES_PARTTEST_LI          P2012                          USABLE
EMPLOYEES_PARTTEST_LI          P2019                          USABLE
EMPLOYEES_PARTTEST_LI          P_MAX                          USABLE
26 rows selected

SQL>

6. 删除分区

全局分区索引和非分区索引都不可用(unusable),本地分区索引不受影响。

SQL> SELECT t1.index_name,NULL parttion_name, t1.status
  2  FROM dba_indexes t1
  3  WHERE t1.table_name = 'EMPLOYEES_PARTTEST'
  4  AND t1.partitioned = 'NO'
  5  UNION
  6  SELECT
  7  t2.index_name,
  8  t2.partition_name,
  9  t2.status
 10  FROM dba_ind_partitions t2
 11  WHERE t2.index_name IN (SELECT index_name FROM dba_indexes WHERE table_name = 'EMPLOYEES_PARTTEST');
INDEX_NAME                     PARTTION_NAME                  STATUS
------------------------------ ------------------------------ --------
EMPLOYEES_PARTTEST_GI          MANAGER_100                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_200                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_300                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_400                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_500                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_600                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_700                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_800                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_900                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_MAX                    UNUSABLE
EMPLOYEES_PARTTEST_I1                                         UNUSABLE
EMPLOYEES_PARTTEST_LI          P2000                          USABLE
EMPLOYEES_PARTTEST_LI          P2001                          USABLE
EMPLOYEES_PARTTEST_LI          P2002                          USABLE
EMPLOYEES_PARTTEST_LI          P2003                          USABLE
EMPLOYEES_PARTTEST_LI          P2004                          USABLE
EMPLOYEES_PARTTEST_LI          P2005                          USABLE
EMPLOYEES_PARTTEST_LI          P2006                          USABLE
EMPLOYEES_PARTTEST_LI          P2007                          USABLE
EMPLOYEES_PARTTEST_LI          P2008                          USABLE
INDEX_NAME                     PARTTION_NAME                  STATUS
------------------------------ ------------------------------ --------
EMPLOYEES_PARTTEST_LI          P2009                          USABLE
EMPLOYEES_PARTTEST_LI          P2010                          USABLE
EMPLOYEES_PARTTEST_LI          P2011                          USABLE
EMPLOYEES_PARTTEST_LI          P2012                          USABLE
EMPLOYEES_PARTTEST_LI          P_MAX                          USABLE
25 rows selected

7. 合并分区

全局分区索引和非分区索引均为不可用(unusable),本地分区索引只有合并后的分区为不可用(unusable)

SQL> alter table employees_parttest merge partitions p12_13,p14_15 into partition p12_15;
Table altered

SQL> SELECT t1.index_name,NULL parttion_name, t1.status
  2  FROM dba_indexes t1
  3  WHERE t1.table_name = 'EMPLOYEES_PARTTEST'
  4  AND t1.partitioned = 'NO'
  5  UNION
  6  SELECT
  7  t2.index_name,
  8  t2.partition_name,
  9  t2.status
 10  FROM dba_ind_partitions t2
 11  WHERE t2.index_name IN (SELECT index_name FROM dba_indexes WHERE table_name = 'EMPLOYEES_PARTTEST');
INDEX_NAME                     PARTTION_NAME                  STATUS
------------------------------ ------------------------------ --------
EMPLOYEES_PARTTEST_GI          MANAGER_100                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_200                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_300                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_400                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_500                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_600                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_700                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_800                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_900                    UNUSABLE
EMPLOYEES_PARTTEST_GI          MANAGER_MAX                    UNUSABLE
EMPLOYEES_PARTTEST_I1                                         UNUSABLE
EMPLOYEES_PARTTEST_LI          P12_15                         UNUSABLE
EMPLOYEES_PARTTEST_LI          P2000                          USABLE
EMPLOYEES_PARTTEST_LI          P2001                          USABLE
EMPLOYEES_PARTTEST_LI          P2002                          USABLE
EMPLOYEES_PARTTEST_LI          P2003                          USABLE
EMPLOYEES_PARTTEST_LI          P2004                          USABLE
EMPLOYEES_PARTTEST_LI          P2005                          USABLE
EMPLOYEES_PARTTEST_LI          P2006                          USABLE
EMPLOYEES_PARTTEST_LI          P2007                          USABLE
INDEX_NAME                     PARTTION_NAME                  STATUS
------------------------------ ------------------------------ --------
EMPLOYEES_PARTTEST_LI          P2008                          USABLE
EMPLOYEES_PARTTEST_LI          P2009                          USABLE
EMPLOYEES_PARTTEST_LI          P2010                          USABLE
EMPLOYEES_PARTTEST_LI          P2011                          USABLE
24 rows selected

总结:全局分区索引和非分区索引,只有在增加分区时不受影响,其他几种操作都会把它们置为unusable;

           本地分区索引只有被操作的分区索引会受影响,相比较其他两种索引,本地分区索引在所有操作中的受影响程度最小。

 

你可能感兴趣的:(Oracle)