[20171211]UNIQUE LOCAL(Partitioned)Index
[20171211]UNIQUE LOCAL (Partitioned) Index.txt
--//如何在分割槽表中建立local unique index呢?自己對分割槽表這部分內容瞭解很少,參考連結:
--//https://hemantoracledba.blogspot.com/2017/11/unique-local-partitioned-index.html
--//重複測試,一些內容直接轉抄,不自己寫了.
1.環境:
SCOTT@book> @ &r/ver1
PORT_STRING VERSION BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx 11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
2.建立測試環境:
create table users
(region_code varchar2(3),
username varchar2(30),
account_status varchar2(32),
created date,
profile varchar2(128))
partition by range (region_code)
(partition a_m values less than ('N'),
partition n_r values less than ('S'),
partition s_z values less than (MAXVALUE));
insert into users
select substr(username,1,3), username, account_status, created, profile
from dba_users;
exec dbms_stats.gather_table_stats('','USERS');
col partition_name format a30
SCOTT@book> select partition_name, num_rows from user_tab_partitions where table_name = 'USERS' order by partition_position;
PARTITION_NAME NUM_ROWS
-------------- --------
A_M 15
N_R 10
S_Z 13
3.測試1:
--//測試GLOBAL (non-partitioned) Unique Index on USERNAME.
SCOTT@book> create unique index users_username_u1 on users(username) global;
Index created.
SCOTT@book> drop index users_username_u1;
Index dropped.
SCOTT@book> create unique index users_username_u1 on users(username);
Index created.
SCOTT@book> drop index users_username_u1;
Index dropped.
--//OK!!實際上後面的global引數是對於的,預設就是global索引.
4.測試2:
--//I now verify that I can create a Non-Unique LOCAL Index (being equi-partitioned, the index is partitioned by
--//REGION_CODE). (Being equi-partitioned, the default behaviour is the Index Partition Names inherit from the Table
--//Partition Names).
SCOTT@book> create index users_username_l1 on users(username) local;
Index created.
select partition_name, num_rows from user_ind_partitions where index_name = 'USERS_USERNAME_L1' order by partition_position;
SCOTT@book> select partition_name, num_rows from user_ind_partitions where index_name = 'USERS_USERNAME_L1' order by partition_position;
PARTITION_NAME NUM_ROWS
-------------- --------
A_M 15
N_R 10
S_Z 13
SCOTT@book> drop index users_username_l1;
Index dropped.
5.測試3:
--//I've proven (with the GLOBAL Index) that USERNAME is Unique across the whole table. Can I create a Unique LOCAL Index
--//on this column ?
SCOTT@book> create unique index users_username_u_l1 on users(username) local;
create unique index users_username_u_l1 on users(username) local
*
ERROR at line 1:
ORA-14039: partitioning columns must form a subset of key columns of a UNIQUE index
Note the Error Message. The Partition Key must be a subset of the Unique Index columns. Let me try adding the Partition
Key (in my example table, the Partition Key is a single column -- it could be a composite of multiple columns. In that
case all the columns of the Partition Key must for a subset of the Unique Index).
SCOTT@book> create unique index users_rc_un_u_l1 on users(region_code, username) local;
Index created.
SCOTT@book> select partition_name, num_rows from user_ind_partitions where index_name = 'USERS_RC_UN_U_L1' order by partition_position;
PARTITION_NAME NUM_ROWS
-------------- --------
A_M 15
N_R 10
S_Z 13
SCOTT@book> drop index users_rc_un_u_l1;
Index dropped.
SCOTT@book> create unique index users_un_rc_u_l1 on users(username, region_code) local;
Index created.
SCOTT@book> select partition_name, num_rows from user_ind_partitions where index_name = 'USERS_UN_RC_U_L1' order by partition_position;
PARTITION_NAME NUM_ROWS
-------------- --------
A_M 15
N_R 10
S_Z 13
It doesn't matter if I put the Partition Key (REGION_CODE) before or after the target column(s) (USERNAME) when I create
the LOCAL Unique Index. What is necessary is that the Partition Key be a subset of the Unique Index definition.
--//實際上按照以上觀點,就是建立unique local index要包括Partition Key.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2148526/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Local Partitioned IndexesIndex
- Index Unique Scan (213)Index
- pk 、unique index 和 index 區別Index
- local nopartition index:Index
- Partitioned Index-Organized Tables (234)IndexZed
- Sparse Indexes vs unique indexIndex
- LOCAL INDEX和HINT的使用【DO BE USED LOCAL INDEX IN HINT】薦Index
- global index & local index的區別Index
- INDEX UNIQUE SCAN,INDEX FULL SCAN和INDEX FAST FULL SCANIndexAST
- 【Oracle】global index & local index的區別OracleIndex
- 主鍵local索引、unique local索引、分割槽索引順序的理解索引
- Unique Index和Normal Index差異經典對比IndexORM
- 再說Unique Index和Normal Index行為差異IndexORM
- attempt to index local ‘result‘ (a nil value)Index
- ORA-14086: a partitioned index may not be rebuilt as a wholeIndexUI
- unique index與primary key的區別Index
- 建立檢視和淺析LOCAL INDEX和GLOBAL INDEXIndex
- Data Warehouse Guide閱讀筆記(六):unique constraint & unique indexGUIIDE筆記AIIndex
- 高效的SQL(Index unique scan最優化)SQLIndex優化
- 唯一性索引(Unique Index)與普通索引(Normal Index)差異(上)索引IndexORM
- 唯一性索引(Unique Index)與普通索引(Normal Index)差異(中)索引IndexORM
- 唯一性索引(Unique Index)與普通索引(Normal Index)差異(下)索引IndexORM
- 索引唯一性掃描(INDEX UNIQUE SCAN)索引Index
- 在什麼情況下用index unique scansIndex
- 分割槽索引之本地(local index)索引和全域性索引(global index)索引Index
- mysql中key 、primary key 、unique key 與index區別MySqlIndex
- ORA-02429: cannot drop index used for enforcement of unique/primary keyIndex
- oracle index unique scan/index range scan和mysql range/const/ref/eq_ref的區別OracleIndexMySql
- ORA-01452: cannot CREATE UNIQUE INDEX; duplicate keys foundIndex
- OGG How to handle / replicate tables with no (without) primary key (PK) or unique index (UI) (UPI) [IndexUI
- 主鍵(PK)與非空唯一索引(Unique Index)的區別索引Index
- Oracle Partitioned TablesOracle
- Overview of Partitioned IndexesViewIndex
- Convert Range-Partitioned Table To Interval-Range-Partitioned Table
- partitioned by timestamp datatype
- Global Range Partitioned IndexesIndex
- Global Hash Partitioned IndexesIndex
- Maintenance of Global Partitioned IndexesAINaNIndex