Oracle 12C 新特性之非分割槽錶轉分割槽表online clause(不停業務+索引有效)
12c以前非分割槽表需要轉換為分割槽, 如果不停業務的話可以使用線上重定義,只有在表進行切換的時候會有短暫的鎖表。 12c 中alter table online clause 實現了表上現有的索引有效,又不停業務。
測試一:非分割槽錶轉分割槽表,索引轉換為oracle內部規則。
-- 建非分割槽表
create table andy_clause as select * from user_objects where object_id is not null;
--建立非分割槽表索引
create index idx_oid on andy_clause( object_id );
create index idx_ctime_oname on andy_clause( created, object_name );
create bitmap index idx_b_otype on andy_clause(object_type);
--檢視錶索引
SQL>
col column_name for a40
SELECT index_name, column_name, descend,COLUMN_POSITION FROM user_ind_columns WHERE table_name = 'ANDY_CLAUSE';
INDEX_NAME COLUMN_NAME DESC COLUMN_POSITION
------------------------- ---------------------------------------- ---- ---------------
IDX_OID OBJECT_ID ASC 1
IDX_CTIME_ONAME CREATED ASC 1
IDX_CTIME_ONAME OBJECT_NAME ASC 2
IDX_B_OTYPE OBJECT_TYPE ASC 1
-- 檢視索引狀態
SQL>
col index_name for a25
select table_name,index_name,status,blevel,leaf_blocks from user_Indexes where table_name ='ANDY_CLAUSE';
TABLE_NAME INDEX_NAME STATUS BLEVEL LEAF_BLOCKS
------------------------- ------------------------- -------- ---------- -----------
ANDY_CLAUSE IDX_OID VALID 0 1
ANDY_CLAUSE IDX_CTIME_ONAME VALID 0 1
ANDY_CLAUSE IDX_B_OTYPE VALID 0 1
--轉換當前表為分割槽以 object_id 欄位, interval分割槽表,直接 update index,使用ORACLE有自己的索引轉換規則。
SQL>
alter table andy_clause modify
partition by range (object_id) interval (5)
(
partition p1 values less than (73527)
) online
update indexes;
Table altered.
說明:update index ,沒有指定寫local 或global選項, ORACLE有自己的索引轉換規則
--檢視錶索引
SQL>
col column_name for a40
SELECT index_name, column_name, descend,COLUMN_POSITION FROM user_ind_columns WHERE table_name = 'ANDY_CLAUSE';
INDEX_NAME COLUMN_NAME DESC COLUMN_POSITION
------------------------- ---------------------------------------- ---- ---------------
IDX_OID OBJECT_ID ASC 1
IDX_CTIME_ONAME CREATED ASC 1
IDX_CTIME_ONAME OBJECT_NAME ASC 2
IDX_B_OTYPE OBJECT_TYPE ASC 1
-- 檢視索引狀態
SQL>
col TABLE_NAME for a25
col index_name for a25
select table_name,index_name,INDEX_TYPE,status,blevel,leaf_blocks from user_Indexes where table_name ='ANDY_CLAUSE';
TABLE_NAME INDEX_NAME STATUS BLEVEL LEAF_BLOCKS
------------------------- ------------------------- -------- ---------- -----------
ANDY_CLAUSE IDX_OID N/A 0 4
ANDY_CLAUSE IDX_CTIME_ONAME VALID 0 1
ANDY_CLAUSE IDX_B_OTYPE N/A 0 4
SQL> COL INDEX_OWNER FOR A20;
SQL> select INDEX_OWNER,index_name,status,blevel,leaf_blocks from dba_ind_partitions where INDEX_OWNER='C##ANDY'and Index_name='IDX_OID';
INDEX_OWNER INDEX_NAME STATUS BLEVEL LEAF_BLOCKS
-------------------- ------------------------- -------- ---------- -----------
C##ANDY IDX_OID USABLE 0 1
C##ANDY IDX_OID USABLE 0 1
C##ANDY IDX_OID USABLE 0 1
C##ANDY IDX_OID USABLE 0 1
SQL>
COL INDEX_OWNER FOR A20;
col index_name for a25
select INDEX_OWNER,index_name,status,blevel,leaf_blocks from dba_ind_partitions where INDEX_OWNER='C##ANDY'and Index_name='IDX_B_OTYPE';
INDEX_OWNER INDEX_NAME STATUS BLEVEL LEAF_BLOCKS
-------------------- ------------------------- -------- ---------- -----------
C##ANDY IDX_B_OTYPE USABLE 0 1
C##ANDY IDX_B_OTYPE USABLE 0 1
C##ANDY IDX_B_OTYPE USABLE 0 1
C##ANDY IDX_B_OTYPE USABLE 0 1
說明:user_Indexes 是主要計量一個index的相關資訊的,如果分割槽索引為local index 它不能記錄狀態,就為 N/A ,分割槽 local index要用檢視 dba_ind_partitions 查狀態。
-- 檢視分割槽情況
SQL>
select table_name,partition_name,PARTITION_POSITION,tablespace_name,HIGH_VALUE from user_tab_partitions where table_name='ANDY_CLAUSE';
TABLE_NAME PARTITION_NAME PARTITION_POSITION TABLESPACE_NAME HIGH_VALUE
------------------------- ------------------------- ------------------ ------------------------------ -----------
ANDY_CLAUSE P1 1 USERS 73527
ANDY_CLAUSE SYS_P341 2 USERS 73532
ANDY_CLAUSE SYS_P343 3 USERS 73592
ANDY_CLAUSE SYS_P342 4 USERS 73597
測試二:非分割槽錶轉分割槽表,索引轉換為自己設定規則。
-- 建非分割槽表
SQL> create table andy_clause02 as select * from user_objects where object_id is not null;
--建立非分割槽表索引
SQL>
create index idx_oid on andy_clause02( object_id );
create index idx_ctime_oname on andy_clause02( created, object_name );
create bitmap index idx_b_otype on andy_clause02(object_type);
--轉換當前表為分割槽以 object_id 欄位, interval分割槽表,update indexes 時,自己指定local 或global選項
SQL>
alter table andy_clause02 modify
partition by range (object_id) interval (5)
(
partition p1 values less than (73527)
) online
update indexes
( idx_oid local,
idx_ctime_oname global partition by range (created)
(
partition ix2_p1 values less than (date '2017-05-01'),
partition ix2_p2 values less than (maxvalue)
)
);
Table altered.
--檢視錶索引
SQL>
col index_name for a25
col COLUMN_NAME for a25
SELECT index_name, column_name, descend,COLUMN_POSITION FROM user_ind_columns WHERE table_name = 'ANDY_CLAUSE02';
INDEX_NAME COLUMN_NAME DESC COLUMN_POSITION
------------------------- ------------------------- ---- ---------------
IDX_OID OBJECT_ID ASC 1
IDX_CTIME_ONAME CREATED ASC 1
IDX_CTIME_ONAME OBJECT_NAME ASC 2
IDX_B_OTYPE OBJECT_TYPE ASC 1
-- 檢視索引狀態
SQL>
col index_name for a25
col TABLE_NAME for a25
select table_name,index_name,status,blevel,leaf_blocks from user_Indexes where table_name ='ANDY_CLAUSE02';
TABLE_NAME INDEX_NAME STATUS BLEVEL LEAF_BLOCKS
------------------------- ------------------------- -------- ---------- -----------
ANDY_CLAUSE02 IDX_OID N/A 1 113
ANDY_CLAUSE02 IDX_CTIME_ONAME N/A 2 432
ANDY_CLAUSE02 IDX_B_OTYPE N/A 1 3
測試一:非分割槽錶轉分割槽表,索引轉換為oracle內部規則。
-- 建非分割槽表
create table andy_clause as select * from user_objects where object_id is not null;
--建立非分割槽表索引
create index idx_oid on andy_clause( object_id );
create index idx_ctime_oname on andy_clause( created, object_name );
create bitmap index idx_b_otype on andy_clause(object_type);
--檢視錶索引
SQL>
col column_name for a40
SELECT index_name, column_name, descend,COLUMN_POSITION FROM user_ind_columns WHERE table_name = 'ANDY_CLAUSE';
INDEX_NAME COLUMN_NAME DESC COLUMN_POSITION
------------------------- ---------------------------------------- ---- ---------------
IDX_OID OBJECT_ID ASC 1
IDX_CTIME_ONAME CREATED ASC 1
IDX_CTIME_ONAME OBJECT_NAME ASC 2
IDX_B_OTYPE OBJECT_TYPE ASC 1
-- 檢視索引狀態
SQL>
col index_name for a25
select table_name,index_name,status,blevel,leaf_blocks from user_Indexes where table_name ='ANDY_CLAUSE';
TABLE_NAME INDEX_NAME STATUS BLEVEL LEAF_BLOCKS
------------------------- ------------------------- -------- ---------- -----------
ANDY_CLAUSE IDX_OID VALID 0 1
ANDY_CLAUSE IDX_CTIME_ONAME VALID 0 1
ANDY_CLAUSE IDX_B_OTYPE VALID 0 1
--轉換當前表為分割槽以 object_id 欄位, interval分割槽表,直接 update index,使用ORACLE有自己的索引轉換規則。
SQL>
alter table andy_clause modify
partition by range (object_id) interval (5)
(
partition p1 values less than (73527)
) online
update indexes;
Table altered.
說明:update index ,沒有指定寫local 或global選項, ORACLE有自己的索引轉換規則
--檢視錶索引
SQL>
col column_name for a40
SELECT index_name, column_name, descend,COLUMN_POSITION FROM user_ind_columns WHERE table_name = 'ANDY_CLAUSE';
INDEX_NAME COLUMN_NAME DESC COLUMN_POSITION
------------------------- ---------------------------------------- ---- ---------------
IDX_OID OBJECT_ID ASC 1
IDX_CTIME_ONAME CREATED ASC 1
IDX_CTIME_ONAME OBJECT_NAME ASC 2
IDX_B_OTYPE OBJECT_TYPE ASC 1
-- 檢視索引狀態
SQL>
col TABLE_NAME for a25
col index_name for a25
select table_name,index_name,INDEX_TYPE,status,blevel,leaf_blocks from user_Indexes where table_name ='ANDY_CLAUSE';
TABLE_NAME INDEX_NAME STATUS BLEVEL LEAF_BLOCKS
------------------------- ------------------------- -------- ---------- -----------
ANDY_CLAUSE IDX_OID N/A 0 4
ANDY_CLAUSE IDX_CTIME_ONAME VALID 0 1
ANDY_CLAUSE IDX_B_OTYPE N/A 0 4
SQL> COL INDEX_OWNER FOR A20;
SQL> select INDEX_OWNER,index_name,status,blevel,leaf_blocks from dba_ind_partitions where INDEX_OWNER='C##ANDY'and Index_name='IDX_OID';
INDEX_OWNER INDEX_NAME STATUS BLEVEL LEAF_BLOCKS
-------------------- ------------------------- -------- ---------- -----------
C##ANDY IDX_OID USABLE 0 1
C##ANDY IDX_OID USABLE 0 1
C##ANDY IDX_OID USABLE 0 1
C##ANDY IDX_OID USABLE 0 1
SQL>
COL INDEX_OWNER FOR A20;
col index_name for a25
select INDEX_OWNER,index_name,status,blevel,leaf_blocks from dba_ind_partitions where INDEX_OWNER='C##ANDY'and Index_name='IDX_B_OTYPE';
INDEX_OWNER INDEX_NAME STATUS BLEVEL LEAF_BLOCKS
-------------------- ------------------------- -------- ---------- -----------
C##ANDY IDX_B_OTYPE USABLE 0 1
C##ANDY IDX_B_OTYPE USABLE 0 1
C##ANDY IDX_B_OTYPE USABLE 0 1
C##ANDY IDX_B_OTYPE USABLE 0 1
說明:user_Indexes 是主要計量一個index的相關資訊的,如果分割槽索引為local index 它不能記錄狀態,就為 N/A ,分割槽 local index要用檢視 dba_ind_partitions 查狀態。
-- 檢視分割槽情況
SQL>
select table_name,partition_name,PARTITION_POSITION,tablespace_name,HIGH_VALUE from user_tab_partitions where table_name='ANDY_CLAUSE';
TABLE_NAME PARTITION_NAME PARTITION_POSITION TABLESPACE_NAME HIGH_VALUE
------------------------- ------------------------- ------------------ ------------------------------ -----------
ANDY_CLAUSE P1 1 USERS 73527
ANDY_CLAUSE SYS_P341 2 USERS 73532
ANDY_CLAUSE SYS_P343 3 USERS 73592
ANDY_CLAUSE SYS_P342 4 USERS 73597
測試二:非分割槽錶轉分割槽表,索引轉換為自己設定規則。
-- 建非分割槽表
SQL> create table andy_clause02 as select * from user_objects where object_id is not null;
--建立非分割槽表索引
SQL>
create index idx_oid on andy_clause02( object_id );
create index idx_ctime_oname on andy_clause02( created, object_name );
create bitmap index idx_b_otype on andy_clause02(object_type);
--轉換當前表為分割槽以 object_id 欄位, interval分割槽表,update indexes 時,自己指定local 或global選項
SQL>
alter table andy_clause02 modify
partition by range (object_id) interval (5)
(
partition p1 values less than (73527)
) online
update indexes
( idx_oid local,
idx_ctime_oname global partition by range (created)
(
partition ix2_p1 values less than (date '2017-05-01'),
partition ix2_p2 values less than (maxvalue)
)
);
Table altered.
--檢視錶索引
SQL>
col index_name for a25
col COLUMN_NAME for a25
SELECT index_name, column_name, descend,COLUMN_POSITION FROM user_ind_columns WHERE table_name = 'ANDY_CLAUSE02';
INDEX_NAME COLUMN_NAME DESC COLUMN_POSITION
------------------------- ------------------------- ---- ---------------
IDX_OID OBJECT_ID ASC 1
IDX_CTIME_ONAME CREATED ASC 1
IDX_CTIME_ONAME OBJECT_NAME ASC 2
IDX_B_OTYPE OBJECT_TYPE ASC 1
-- 檢視索引狀態
SQL>
col index_name for a25
col TABLE_NAME for a25
select table_name,index_name,status,blevel,leaf_blocks from user_Indexes where table_name ='ANDY_CLAUSE02';
TABLE_NAME INDEX_NAME STATUS BLEVEL LEAF_BLOCKS
------------------------- ------------------------- -------- ---------- -----------
ANDY_CLAUSE02 IDX_OID N/A 1 113
ANDY_CLAUSE02 IDX_CTIME_ONAME N/A 2 432
ANDY_CLAUSE02 IDX_B_OTYPE N/A 1 3
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31383567/viewspace-2139061/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle 12C新特性-線上把非分割槽錶轉為分割槽表Oracle
- Oracle 12C 新特性之表分割槽部分索引(Partial Indexes)Oracle索引Index
- Oracle 12C 新特性之move (非分割槽表)table onlineOracle
- Oracle 12C 新特性之表分割槽或子分割槽的線上遷移Oracle
- Oracle分割槽表及分割槽索引Oracle索引
- [引用分割槽表]Oracle 11g新特性之引用分割槽表Oracle
- 簡單ORACLE分割槽表、分割槽索引Oracle索引
- 非分割槽錶轉換成分割槽表
- Oracle帶區域性分割槽索引的分割槽表刪除舊分割槽新增新分割槽Oracle索引
- 將非分割槽錶轉換為分割槽表
- 深入學習Oracle分割槽表及分割槽索引Oracle索引
- 全面認識oracle分割槽表及分割槽索引Oracle索引
- 將mysql非分割槽錶轉換為分割槽表MySql
- ORACLE 11g 範圍分割槽錶轉換INTERVAL分割槽表Oracle
- Oracle分割槽之五:建立分割槽索引總結Oracle索引
- Oracle分割槽表基礎運維-06分割槽表索引Oracle運維索引
- Oracle線上將普通錶轉分割槽表Oracle
- ORACLE 19c 新特性之混合分割槽表Oracle
- rebuild分割槽表分割槽索引的方法Rebuild索引
- 分割槽表及分割槽索引建立示例索引
- 全面學習分割槽表及分割槽索引(13)--分隔表分割槽索引
- 將一個非分割槽錶轉換為分割槽表
- 非分割槽錶轉換為分割槽表和partition indexIndex
- Oracle11.2表分割槽新特性Oracle
- 【學習筆記】分割槽表和分割槽索引——管理索引分割槽(四)筆記索引
- 全面學習分割槽表及分割槽索引(10)--交換分割槽索引
- 全面學習分割槽表及分割槽索引(9)--刪除表分割槽索引
- 全面學習分割槽表及分割槽索引(11)--合併表分割槽索引
- 全面學習分割槽表及分割槽索引(12)--修改list表分割槽索引
- 學習筆記】分割槽表和分割槽索引——新增表分割槽(二)筆記索引
- 全面學習分割槽表及分割槽索引(17)--其它索引分割槽管理操作索引
- Oracle索引分割槽Oracle索引
- oracle分割槽表和分割槽表exchangeOracle
- 非分割槽錶轉換成分割槽表以及注意事項
- 【分割槽】如何將一個普通錶轉換為分割槽表
- 分割槽表分割槽索引查詢效率探究索引
- Oracle 將普通錶轉換為分割槽表Oracle
- 全面學習分割槽表及分割槽索引(16)--增加和刪除索引分割槽索引