测试分区表local及global index在drop及truncate操作下是否失效
2015-10-23 19:27
225 查看
创建分区表:
create table test10
(
sal_date date not null,
sal_id number not null,
sal_row number(12) not null
)
partition by range(sal_date)
(
partition p_1 values less than(to_date('2010-01-01','yyyy-mm-dd')),
partition p_2 values less than(to_date('2011-01-01','yyyy-mm-dd')),
partition p_3 values less than(to_date('2012-01-01','yyyy-mm-dd')),
partition p_4 values less than(to_date('2013-01-01','yyyy-mm-dd')),
partition p_5 values less than(to_date('2014-01-01','yyyy-mm-dd')),
partition p_6 values less than(to_date('2015-01-01','yyyy-mm-dd')),
partition p_7 values less than(to_date('2016-01-01','yyyy-mm-dd')),
partition p_8 values less than(to_date('2017-01-01','yyyy-mm-dd')),
partition p_9 values less than(to_date('2018-01-01','yyyy-mm-dd')),
partition p_10 values less than(to_date('2019-01-01','yyyy-mm-dd')),
partition p_11 values less than(to_date('2020-01-01','yyyy-mm-dd')),
partition p_12 values less than(to_date('2021-01-01','yyyy-mm-dd')),
partition p_13 values less than(to_date('2022-01-01','yyyy-mm-dd')),
partition p_14 values less than(to_date('2023-01-01','yyyy-mm-dd')),
partition p_15 values less than(maxvalue)
)
插入数据:
insert into test10 SELECT TRUNC(SYSDATE)-ROWNUM, dbms_random.random,ROWNUM FROM dual CONNECT BY LEVEL<=5000;
创建全局索引:
create index test10_sal_id on test10(sal_id) global;
创建本地索引:
create index test10_sal_date on test10(sal_date) local;
查询分区表索引状态,均有效:
SQL> select index_name,status from dba_indexes where table_name='TEST10';
INDEX_NAME STATUS
------------------------------ --------
TEST10_SAL_DATE N/A
TEST10_SAL_ID VALID
删除test10的一个p_2分区:
SQL> alter table test10 truncate partition p_2;
Table truncated.
再次查询索引状态 Golbal索引已经失效了而local索引没有影响:
SQL> select index_name,status from dba_indexes where table_name='TEST10';
INDEX_NAME STATUS
------------------------------ --------
TEST10_SAL_DATE N/A
TEST10_SAL_ID UNUSABLE
分区进行drop的时候:
SQL> alter table test10 drop partition p_3;
Table altered.
全局索引也会失效:
SQL> select index_name,status from dba_indexes where table_name='TEST10';
INDEX_NAME STATUS
------------------------------ --------
TEST10_SAL_DATE N/A
TEST10_SAL_ID UNUSABLE
如下是避免由于分区表进行truncate和drop操作时发生global索引失效:
SQL> alter table test10 truncate partition p_5 update global indexes;
Table truncated.
全局索引没有失效:
SQL> select index_name,status from dba_indexes where table_name='TEST10';
INDEX_NAME STATUS
------------------------------ --------
TEST10_SAL_DATE N/A
TEST10_SAL_ID VALID
drop分区表的时候全局索引也没有失效:
SQL> alter table test10 drop partition p_6 update global indexes;
Table altered.
SQL> select index_name,status from dba_indexes where table_name='TEST10';
INDEX_NAME STATUS
------------------------------ --------
TEST10_SAL_DATE N/A
TEST10_SAL_ID VALID
总结:1:local index在truncate和drop Partition table的时候不会失效
2:global index在truncate和drop Partition table的时候加上update global indexes则global index会自动更新,否则会失效需要rebuild
create table test10
(
sal_date date not null,
sal_id number not null,
sal_row number(12) not null
)
partition by range(sal_date)
(
partition p_1 values less than(to_date('2010-01-01','yyyy-mm-dd')),
partition p_2 values less than(to_date('2011-01-01','yyyy-mm-dd')),
partition p_3 values less than(to_date('2012-01-01','yyyy-mm-dd')),
partition p_4 values less than(to_date('2013-01-01','yyyy-mm-dd')),
partition p_5 values less than(to_date('2014-01-01','yyyy-mm-dd')),
partition p_6 values less than(to_date('2015-01-01','yyyy-mm-dd')),
partition p_7 values less than(to_date('2016-01-01','yyyy-mm-dd')),
partition p_8 values less than(to_date('2017-01-01','yyyy-mm-dd')),
partition p_9 values less than(to_date('2018-01-01','yyyy-mm-dd')),
partition p_10 values less than(to_date('2019-01-01','yyyy-mm-dd')),
partition p_11 values less than(to_date('2020-01-01','yyyy-mm-dd')),
partition p_12 values less than(to_date('2021-01-01','yyyy-mm-dd')),
partition p_13 values less than(to_date('2022-01-01','yyyy-mm-dd')),
partition p_14 values less than(to_date('2023-01-01','yyyy-mm-dd')),
partition p_15 values less than(maxvalue)
)
插入数据:
insert into test10 SELECT TRUNC(SYSDATE)-ROWNUM, dbms_random.random,ROWNUM FROM dual CONNECT BY LEVEL<=5000;
创建全局索引:
create index test10_sal_id on test10(sal_id) global;
创建本地索引:
create index test10_sal_date on test10(sal_date) local;
查询分区表索引状态,均有效:
SQL> select index_name,status from dba_indexes where table_name='TEST10';
INDEX_NAME STATUS
------------------------------ --------
TEST10_SAL_DATE N/A
TEST10_SAL_ID VALID
删除test10的一个p_2分区:
SQL> alter table test10 truncate partition p_2;
Table truncated.
再次查询索引状态 Golbal索引已经失效了而local索引没有影响:
SQL> select index_name,status from dba_indexes where table_name='TEST10';
INDEX_NAME STATUS
------------------------------ --------
TEST10_SAL_DATE N/A
TEST10_SAL_ID UNUSABLE
分区进行drop的时候:
SQL> alter table test10 drop partition p_3;
Table altered.
全局索引也会失效:
SQL> select index_name,status from dba_indexes where table_name='TEST10';
INDEX_NAME STATUS
------------------------------ --------
TEST10_SAL_DATE N/A
TEST10_SAL_ID UNUSABLE
如下是避免由于分区表进行truncate和drop操作时发生global索引失效:
SQL> alter table test10 truncate partition p_5 update global indexes;
Table truncated.
全局索引没有失效:
SQL> select index_name,status from dba_indexes where table_name='TEST10';
INDEX_NAME STATUS
------------------------------ --------
TEST10_SAL_DATE N/A
TEST10_SAL_ID VALID
drop分区表的时候全局索引也没有失效:
SQL> alter table test10 drop partition p_6 update global indexes;
Table altered.
SQL> select index_name,status from dba_indexes where table_name='TEST10';
INDEX_NAME STATUS
------------------------------ --------
TEST10_SAL_DATE N/A
TEST10_SAL_ID VALID
总结:1:local index在truncate和drop Partition table的时候不会失效
2:global index在truncate和drop Partition table的时候加上update global indexes则global index会自动更新,否则会失效需要rebuild
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28473562/viewspace-1815964/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/28473562/viewspace-1815964/
相关文章推荐
- 操作分区表对global和local索引的影响
- 分区表和分区索引(global local)的性能对比测试
- 操作分区表对global和local索引的影响
- Partition Tabel测试drop和truncate 分区对全局和本地索引是否有影响
- Oracle分区表drop和truncate partition索引失效问题
- 操作分区表对global和local索引的影响
- 操作分区表对global和local索引的影响 (三)
- 操作分区表对global和local索引的影响操作分区表对global和local索引的影响
- Oracle分区表drop和truncate partition索引失效问题
- 基于mysqldump备份集来恢复某个误操作的表(drop,truncate)
- 索引分区分为:本地(局部)索引(local index) 全局索引(global index)
- MySQL删除表操作实现(delete、truncate、drop的区别)
- close操作前要测试“文件对象”是否创建成功,如果多个流,需要分别去关闭
- 高级复制-5、测试是否可同步DML操作
- Android 判断一个 View 是否可见 getLocalVisibleRect(rect) 与 getGlobalVisibleRect(rect)
- [Partition][Index]对于Partition表而言,是否Global Index 和 Local Index 可以针对同一个字段建立?
- oracle里如何快速drop column测试(慎用于生产系统,该操作导致表无法访问)
- MAC上安装MySQL,测试是否安装好了,在命令窗中作建表、查询等基本操作。
- local|global index
- 支持阻塞操作和轮询操作的globalfifo设备驱动代码分析以及测试代码