[20171211]UNIQUE LOCAL(Partitioned)Index

简介: [20171211]UNIQUE LOCAL (Partitioned) Index.txt --//如何在分区表中建立local unique index呢?自己对分区表这部分内容了解很少,参考链接: --//https://hemantoracledba.

[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.

目录
相关文章
|
SQL Oracle 关系型数据库
Oracle系列十七:Sqluldr2与Sqlldr
Oracle系列十七:Sqluldr2与Sqlldr
|
5月前
|
数据采集 存储 Web App开发
轻量级爬虫框架Feapder入门:快速搭建企业级数据管道
本教程基于Feapder框架,讲解如何构建轻量级爬虫采集豆瓣电影数据。通过配置代理IP、Cookie与User-Agent,实现企业级数据管道能力,包括动态请求与信息提取(如电影名称、导演、演员等)。适合具备Python基础及爬虫原理知识的读者,提供从环境搭建到代码实现的完整流程,并分析常见错误与解决方法,助力高效开发。
240 1
轻量级爬虫框架Feapder入门:快速搭建企业级数据管道
|
8月前
|
安全 大数据 Linux
云上体验最佳的服务器操作系统 - Alibaba Cloud Linux | 飞天技术沙龙-CentOS 迁移替换专场
本次方案的主题是云上体验最佳的服务器操作系统 - Alibaba Cloud Linux ,从 Alibaba Cloud Linux 的产生背景、产品优势以及云上用户使用它享受的技术红利等方面详细进行了介绍。同时,通过国内某社交平台、某快递企业、某手机客户大数据业务 3 大案例,成功助力客户实现弹性扩容能力提升、性能提升、降本增效。 1. 背景介绍 2. 产品介绍 3. 案例分享
185 1
|
Shell
Shell export 定义全局变量(变量的作用范围)
Shell export 定义全局变量(变量的作用范围)
493 0
|
SQL Oracle 关系型数据库
|
SQL Oracle 关系型数据库
ORA-01033: ORACLE initialization or shutdown in progress的两种解决方法
ORA-01033: ORACLE initialization or shutdown in progress通常是由于ORACLE数据库文件损坏引起的,以下是出现的问题及解决方法: 现象一: sysdba可以登录,但是在使用中就出现“数据库未打开,仅允许在固定表/视图中查询”,而normal用户无法登录使用,出现ORA-01033: ORACLE initialization or shutdown in progress 的错误。
2178 0
|
前端开发 Java 中间件
Sentinel Dashboard支持规则配置持久化至Nacos
目录 前言 一、Push模式原理 二、Sentinel控制台改造支持配置持久化至Nacos 1、拉取最新代码 2、开始搬运代码 (1) 调整点之修改NacosConfig类 (2) 调整点之新增NacosConfigProperties类 (3) 调整点之修改NacosConfigUtil类 (4) DynamicRuleProvider和DynamicRulePublisher实现优化 1) AbstractNacosProvider类 2) AbstractNacosPublisher类 3) FlowRuleNacosProvider类 4) FlowRuleNacosPublisher
Sentinel Dashboard支持规则配置持久化至Nacos
|
存储 SQL 缓存
跟面试官侃半小时MySQL事务,说完原子性、一致性、持久性的实现
跟面试官侃半小时MySQL事务,说完原子性、一致性、持久性的实现
332 0
跟面试官侃半小时MySQL事务,说完原子性、一致性、持久性的实现
|
SQL Oracle 关系型数据库
Oracle文本数据导出方法总结
Oracle文本数据导出方法总结
1137 0
|
存储 SQL 安全
如何提高加速数据泵的操作性能
如何提高加速数据泵的操作性能
608 0