• 分区表 主键全局索引和分区索引区别


    SQL> create table pdba (agmt_id number,corp_org char(10),agmt_mod_cd char(10),a1 number,a2 number,a3 number,a4 number, start_date date) partition by range (start_date )
    (
    partition p1 values less than (to_date('2010-10-1', 'yyyy-mm-dd')),
    partition p2 values less than (to_date('2010-11-1', 'yyyy-mm-dd')),
    partition p3 values less than (to_date('2010-12-1', 'yyyy-mm-dd')),
    partition p4 values less than (maxvalue)
    )
      2    3    4    5    6    7    8  ;
    
    表已创建。
    
    SQL> desc pdba;
     名称                                    是否为空? 类型
     ----------------------------------------- -------- ----------------------------
     AGMT_ID					    NUMBER
     CORP_ORG					    CHAR(10)
     AGMT_MOD_CD					    CHAR(10)
     A1						    NUMBER
     A2						    NUMBER
     A3						    NUMBER
     A4						    NUMBER
     START_DATE					    DATE
    
    
    
    主键为分区索引:
    
    alter table pdba add primary key (AGMT_ID, CORP_ORG, AGMT_MOD_CD) USING INDEX LOCAL;
    
    
    SQL> alter table pdba add primary key (AGMT_ID, CORP_ORG, AGMT_MOD_CD) USING INDEX LOCAL;
    alter table pdba add primary key (AGMT_ID, CORP_ORG, AGMT_MOD_CD) USING INDEX LOCAL
    *
    第 1 行出现错误:
    ORA-14039: 分区列必须构成 UNIQUE 索引的关键字列子集
    
    alter table pdba add primary key (AGMT_ID, CORP_ORG, AGMT_MOD_CD, start_date ) USING INDEX LOCAL;
    
    必须把分区列 加入到主键
    
    SQL> alter table pdba add primary key (AGMT_ID, CORP_ORG, AGMT_MOD_CD, start_date ) USING INDEX LOCAL;
    
    表已更改。
    SQL>  select index_name,table_name,PARTITIONED,GLOBAL_STATS from dba_indexes where table_name='PDBA';
    
    INDEX_NAME		       TABLE_NAME		      PAR GLO
    ------------------------------ ------------------------------ --- ---
    SYS_C0023490		       PDBA			      YES NO
    
    
    如果主键是全局索引呢?
    alter table pdba add primary key (AGMT_ID, CORP_ORG, AGMT_MOD_CD);
    
    SQL> alter table pdba add primary key (AGMT_ID, CORP_ORG, AGMT_MOD_CD);
    
    表已更改。
    
    全局的可以
    
    GLOBAL_STATS	VARCHAR2(3)	 	For partitioned indexes, indicates whether statistics were collected by analyzing the index as a whole (YES) or were estimated from 
    
    statistics on underlying index partitions and subpartitions (NO)
    
    
    对于分区索引,表明是否统计信息是通过分析index 作为整个搜集的 或者 是从依赖的分区或者子分区评估的
    
    PARTITIONED	VARCHAR2(3)	 	Indicates whether the index is partitioned (YES) or not (NO)
    
    SQL> select index_name,table_name,PARTITIONED,GLOBAL_STATS from dba_indexes where table_name='PDBA';
    
    INDEX_NAME		       TABLE_NAME		      PAR GLO
    ------------------------------ ------------------------------ --- ---
    SYS_C0023489		       PDBA			      NO  YES
    

  • 相关阅读:
    Java JDK和IntelliJ IDEA 配置及安装
    来吧学学.Net Core之登录认证与跨域资源使用
    来吧学学.Net Core之项目文件简介及配置文件与IOC的使用
    【转载】任正非:我的父亲母亲
    HTTP协议中的短轮询、长轮询、长连接和短连接
    跨域资源共享CORS详解
    C#各个版本中的新增特性详解
    仓央嘉措不负如来不负卿
    Redis Sentinel实现的机制与原理详解
    Redis的发布订阅及.NET客户端实现
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349941.html
Copyright © 2020-2023  润新知