分割槽索引學習筆記
續接上次的分割槽表學習筆記,對分割槽索引進行了總結。
--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
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23718752/viewspace-746696/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- hive學習筆記之四:分割槽表Hive筆記
- MySQL學習筆記:索引失效MySql筆記索引
- 移動分割槽表和分割槽索引的表空間索引
- Spark學習——分割槽Partition數Spark
- MySQL學習筆記:組合索引-索引下推MySql筆記索引
- Oracle分割槽表基礎運維-06分割槽表索引Oracle運維索引
- MySQL優化學習筆記之索引MySql優化筆記索引
- Python學習筆記|Python之索引迭代Python筆記索引
- 機器學習筆記——資料集分割機器學習筆記
- 【MongoDB學習筆記】MongoDB索引那點事MongoDB筆記索引
- SQL優化案例-分割槽索引之無字首索引(六)SQL優化索引
- Oracle優化案例-分割槽索引之無字首索引(六)Oracle優化索引
- 增加表分割槽時,為local分割槽索引指定不同表空間的方法索引
- 【INDEX】Oracle分割槽索引技術詳解IndexOracle索引
- SQL最佳化案例-分割槽索引之無字首索引(六)SQL索引
- 【numpy學習筆記】陣列的切片,索引,迭代筆記陣列索引
- MySQL學習筆記:組合索引-最左原則MySql筆記索引
- 記一次Oracle分割槽表全域性索引重建的過程Oracle索引
- Linux 學習基礎入門之Linux分割槽Linux
- C#學習筆記-欄位、屬性、索引器C#筆記索引
- index_oracle索引梳理系列及分割槽表梳理IndexOracle索引
- mongo 建立使用者 建hash 分割槽 建索引Go索引
- rabbitmq 學習與實踐分享之網路分割槽MQ
- Linux分割槽方案、分割槽建議Linux
- QT學習筆記1(安裝、建立和訊號與槽)QT筆記
- PostgreSQL11preview-索引優化。filter智慧消除、分割槽索引智慧合併SQLView索引優化Filter
- numpy的學習筆記\pandas學習筆記筆記
- MySQL資料表分割槽手記MySql
- oracle分割槽表和分割槽表exchangeOracle
- PostgreSQL/LightDB 分割槽表之分割槽裁剪SQL
- Linux 分割槽擴容(根分割槽擴容,SWAP 分割槽擴容,掛載新分割槽為目錄)Linux
- 事務、全域性索引、透明分散式,再見,分割槽健!索引分散式
- 學習筆記筆記
- 百度影像分割7日打卡訓練營學習筆記筆記
- Oracle分割槽表基礎運維-07增加分割槽(2 HASH分割槽)Oracle運維
- oracle分割槽表和非分割槽表exchangeOracle
- 非分割槽錶轉換成分割槽表
- [oracle] expdp 匯出分割槽表的分割槽Oracle
- 《MySQL實戰45講》學習筆記4——MySQL中InnoDB的索引MySql筆記索引