Partition Tabel测试drop和truncate 分区对全局和本地索引是否有影响
2015-07-02 11:00
776 查看
创建分区表:
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
相关文章推荐
- linux下安装Maven
- 为PopupWindow设置动画效果
- Nginx 配置虚拟机
- div嵌套margin-top失效的解决方法
- linux系统硬件配置查看方法
- Ubuntu下Nginx配置ThinkPHP的Pathinfo和URl Rewrite模式
- LinuxShell中删除文件中某一行的方法
- Apache Kafka —一个不同的消息系统
- 使用Glog帮助编写Linux C程序
- linux中fork()函数详解(转载)
- linux下部署项目后可能出现的问题 ;(是无效,Web server process 写入资料的目录)
- nginx 反向代理 504 错误
- Bash学习手册
- Nginx配置支持ThinkPHP的PATH_INFO
- 使用nginx的proxy_cache做网站缓存
- Linux kernel浮点计算支持
- SeLinux语法规则
- 制作Cubie版OpenWRT(功能齐全,大小仅有11M)
- 关于蓝牙通讯报 The operation is not allowed on non-connected sockets. 错误
- Nginx下支持Thinkphp URL Rewrite的配置示例