分区索引学习笔记 (77天)

续接上次的分区表学习笔记,对分区索引进行了总结。

--index maintance SQL> select index_name,table_name from user_indexes where table_name='RANGE_PART';

no rows selected

--create one global index SQL> create index glb_range_part on range_part(a,b) 2 global partition by range(a) 3 ( partition part_01 values less than(1000), 4 partition part_02 values less than(maxvalue) 5 );

Index created. SQL> create index ind_range_part on range_part(a,b) local; create index ind_range_part on range_part(a,b) local * ERROR at line 1: ORA-01408: such column list already indexed --如果已经定义了index的列,则不能再创建其他的索引 --再次验证 SQL> create index ind_range_part on range_part(a,b);

Index created.

SQL> create index ind_range_part on range_part(a,b) local; create index ind_range_part on range_part(a,b) local * ERROR at line 1: ORA-00955: name is already used by an existing object

--提示是index名字重复了,似乎可以重新建一个其他名字的index SQL> create index ind1_range_part on range_part(a,b); create index ind1_range_part on range_part(a,b) * ERROR at line 1: ORA-01408: such column list already indexed --这次还是回到上一步,错误重现

--如果不加local,索引在status列会有不同 SQL> select index_name,table_name,status from user_indexes where table_name='RANGE_PART';

INDEX_NAME TABLE_NAME STATUS ------------------------------ ------------------------------ -------- IND_RANGE_PART RANGE_PART VALID

SQL> drop index ind_range_part;

Index dropped.

SQL> create index ind_range_part on range_part(a,b) local;

Index created.

SQL> select index_name,table_name,status from user_indexes where table_name='RANGE_PART';

INDEX_NAME TABLE_NAME STATUS ------------------------------ ------------------------------ -------- IND_RANGE_PART RANGE_PART N/A

关于global index还有一点是global partition Index必须是prefixed的 SQL> create index ind_range_part on range_part(b,a) global partition by range(a) ( partition part_01 values less than(1000), partition part_02 values less than(maxvalue) ) SQL> / global partition by range(a) * ERROR at line 2: ORA-14038: GLOBAL partitioned index must be prefixed

--清除所有的索引,重新测试 SQL> create index ind_range_part on range_part(a,b) global partition by range(a) ( partition glb_part_01 values less than(1000), partition glb_part_02 values less than(maxvalue) ) 2 3 4 5 6 SQL> /

Index created.

SQL> create index ind_range_part2 on range_part(b,a) local;

Index created.

1* select index_name,status from user_indexes where table_name='RANGE_PART' SQL> /

INDEX_NAME STATUS ------------------------------ -------- IND_RANGE_PART N/A IND_RANGE_PART2 N/A

SQL> select index_name,partition_name,high_value,status from user_ind_partitions where index_name in(select index_name from user_indexes where table_name='RANGE_PART');

INDEX_NAME PARTITION_NAME HIGH_VALUE STATUS ------------------------------ ------------------------------ -------------------- -------- IND_RANGE_PART GLB_PART_01 1000 USABLE IND_RANGE_PART2 PART_05 MAXVALUE USABLE IND_RANGE_PART2 PART_02 4000 USABLE IND_RANGE_PART2 PART_01 2000 USABLE IND_RANGE_PART GLB_PART_02 MAXVALUE USABLE

SQL> alter table range_part merge partitions part_01,part_02;

Table altered.

SQL> select index_name,partition_name,high_value,status from user_ind_partitions where index_name in(select index_name from user_indexes where table_name='RANGE_PART');

INDEX_NAME PARTITION_NAME HIGH_VALUE STATUS ------------------------------ ------------------------------ -------------------- -------- IND_RANGE_PART GLB_PART_01 1000 UNUSABLE IND_RANGE_PART2 PART_05 MAXVALUE USABLE IND_RANGE_PART GLB_PART_02 MAXVALUE UNUSABLE IND_RANGE_PART2 SYS_P51 4000 UNUSABLE

--分区编译 SQL> alter index ind_range_part2 rebuild partition SYS_P51;

Index altered. INDEX_NAME PARTITION_NAME HIGH_VALUE STATUS ------------------------------ ------------------------------ -------------------- -------- IND_RANGE_PART GLB_PART_01 1000 UNUSABLE IND_RANGE_PART2 PART_05 MAXVALUE USABLE IND_RANGE_PART GLB_PART_02 MAXVALUE UNUSABLE IND_RANGE_PART2 SYS_P51 4000 USABLE

--对全局索引全表rebuild失败 SQL> ALTER INDEX IND_RANGE_PART REBUILD; ALTER INDEX IND_RANGE_PART REBUILD * ERROR at line 1: ORA-14086: a partitioned index may not be rebuilt as a whole --只能根据分区来相应rebuild

SQL> ALTER INDEX IND_RANGE_PART REBUILD PARTITION GLB_PART_01;

Index altered.

SQL> ALTER INDEX IND_RANGE_PART REBUILD PARTITION GLB_PART_02;

Index altered.

SQL> ALTER TABLE RANGE_PART RENAME PARTITION SYS_P51 TO PART_01;

Table altered.

SQL> ALTER TABLE RANGE_PART SPLIT PARTITION PART_01 AT(2000) INTO (PARTITION PART_01,PARTITION PART_02);

Table altered.

SQL> select index_name,partition_name,high_value,status from user_ind_partitions where index_name in(select index_name from user_indexes where table_name='RANGE_PART');

INDEX_NAME PARTITION_NAME HIGH_VALUE STATUS ------------------------------ ------------------------------ -------------------- -------- IND_RANGE_PART GLB_PART_01 1000 UNUSABLE IND_RANGE_PART2 PART_05 MAXVALUE USABLE IND_RANGE_PART2 PART_02 4000 UNUSABLE IND_RANGE_PART2 SYS_P51 2000 UNUSABLE IND_RANGE_PART GLB_PART_02 MAXVALUE UNUSABLE

--PARTITION_NAME为SYS_P51,这个是Index的partition_name SQL> SELECT PARTITION_NAME FROM USER_TAB_PARTITIONS WHERE TABLE_NAME='RANGE_PART';

PARTITION_NAME ------------------------------ PART_01 PART_02 PART_05

--分区名字没有问题

--rebuild索引有以下的方式 SQL> ALTER TABLE RANGE_PART MODIFY PARTITION PART_01 REBUILD UNUSABLE LOCAL INDEXES;

Table altered.

SQL> ALTER INDEX IND_RANGE_PART2 REBUILD PARTITION PART_02;

Index altered.

最后有几个视图需要注意一下。

SQL> SELECT PARTITION_COUNT,STATUS,TABLE_NAME FROM USER_PART_TABLES WHERE TABLE_NAME='RANGE_PART';

PARTITION_COUNT STATUS TABLE_NAME --------------- -------- ------------------------------ 3 VALID RANGE_PART

--查找partition key SQL> SELECT NAME,OBJECT_TYPE,COLUMN_NAME FROM USER_PART_KEY_COLUMNS WHERE NAME='RANGE_PART';

NAME OBJEC COLUMN_NAME ------------------------------ ----- -------------------- RANGE_PART TABLE A

--USER_TAB_PARTITIONS --USER_IND_PARTITIONS

原文发布于微信公众号 - 杨建荣的学习笔记(jianrong-notes)

原文发表时间:2014-05-19

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏高性能服务器开发

(八)高性能服务器架构设计总结3——以flamigo服务器代码为例

再看filezilla,一款ftp工具的服务器端,它采用的是Windows的WSAAsyncSelect模型(代码下载地址:https://github.com...

1181
来自专栏搞前端的李蚊子

Html5模拟通讯录人员排序(sen.js)

// JavaScript Document  var PY_Json_Str = ""; var PY_Str_1 = ""; var PY_Str_...

5896
来自专栏技术之路

wpf键盘记录器

很简单的一个wpf键盘记录器 ? 这个程序我一样用了全局勾子,之前用的都是winform上运行了,前一段时间 在国外的论坛上逛看到了一个wpf能用的就做了一个小...

2005
来自专栏转载gongluck的CSDN博客

初探WinInet网络api

//必须的头文件,而且要链接wininet.lib #include <WinInet.h> #define UM_SOCKET (WM_USER + 1) ...

3375
来自专栏Hadoop数据仓库

Oracle sqlldr 如何导入一个日期列

1. LOAD DATA INFILE * INTO TABLE test FIELDS TERMINATED BY X'9' TRAILING NULLCO...

1786
来自专栏Pulsar-V

Save Camera Document

#pragma once #include "HCCamera.h" #include <time.h> #include <cstdio> #incl...

2828
来自专栏linux驱动个人学习

高通Audio中ASOC的machine驱动

ASoC被分为Machine、Platform和Codec三大部分,其中的Machine驱动负责Platform和Codec之间的耦合以及部分和设备或板子特定的...

9744
来自专栏潇涧技术专栏

Tips about MacBook's battery health

内容摘自Mac上的一个灰常好的免费软件Battery Health中关于保养MacBook的电池寿命的建议,与大家一起分享

501
来自专栏我和未来有约会

简练的视图模型 ViewModel

patterns & practices Developer Center 发布了 Unity Application Block 1.2 for Silver...

2169
来自专栏祝威廉

Spark Streaming Dynamic Resource Allocation

DRA has already been implemented since Spark 1.2 . However the existing Spark DR...

1403

扫码关注云+社区