mysql 分区 全局索引_Oracle本地分区索引、全局本地分区索引

官网截图:

global partition index

5d58adeb71487bcf96dfc80b33909bdf.png

local partition index

07b3067774fa2b4d3658825518ef340a.png

《全局分区索引》

drop table JS_SKSKJDK_DZFPMX02 purge;

--创建分区表 jssj

SQL> create table JS_SKSKJDK_DZFPMX02(

fpdm      VARCHAR2(12) not null,

fphm      VARCHAR2(8) not null,

jssj      DATE,

CONSTRAINT PK_JS_SKSKJDK_DZFPMX02 PRIMARY KEY(FPHM,FPDM)

USING INDEX TABLESPACE users

)

PARTITION BY RANGE(JSSJ)

(PARTITION p01 VALUES LESS THAN(to_date('2016/8/31 10:53:40','yyyy-mm-dd hh24:mi:ss')) TABLESPACE users) enable row movement;

Table created.

--创建全局分区索引

drop index ind_jssj02;

SQL> create index ind_jssj02 on JS_SKSKJDK_DZFPMX02(jssj)  global

partition by range (jssj)

(

partition p02 values  less than (to_date('2016/10/30 10:53:40','yyyy-mm-dd hh24:mi:ss')) ,

partition p03 values  less than (to_date('2016/11/30 10:53:40','yyyy-mm-dd hh24:mi:ss')),

partition p04 values  less than (to_date('2016/12/3 10:53:40','yyyy-mm-dd hh24:mi:ss')),

partition p05 values  less than (to_date('2016/12/30 10:53:40','yyyy-mm-dd hh24:mi:ss')),

partition pmax values  less than (maxvalue)

) ;

Index created.

-- 为分区表新增分区

SQL> alter table JS_SKSKJDK_DZFPMX02 add partition p02 values  less than (to_date('2016/10/30 10:53:40','yyyy-mm-dd hh24:mi:ss')) tablespace  users;

Table altered.

SQL> alter table JS_SKSKJDK_DZFPMX02 add partition p03 values  less than (to_date('2016/11/30 10:53:40','yyyy-mm-dd hh24:mi:ss')) tablespace  users;

Table altered.

SQL> alter table JS_SKSKJDK_DZFPMX02 add partition p04 values  less than (to_date('2016/12/3 10:53:40','yyyy-mm-dd hh24:mi:ss')) tablespace  users;

Table altered.

SQL> alter table JS_SKSKJDK_DZFPMX02 add partition p05 values  less than (to_date('2016/12/30 10:53:40','yyyy-mm-dd hh24:mi:ss')) tablespace  users;

Table altered.

-- 将全局分区索引重建于指定的索引分区

alter index ind_jssj02  rebuild partition  p04 tablespace users;

--分区表插入测试数据

SQL> insert into JS_SKSKJDK_DZFPMX02 values('1','1',sysdate);

1 row created.

SQL> insert into JS_SKSKJDK_DZFPMX02 values('2','2',sysdate);

1 row created.

SQL> insert into JS_SKSKJDK_DZFPMX02 values('3','3',sysdate);

1 row created.

--检查索引状态

SQL> select  t2.locality,t1.index_name,t1.partition_name,t1.status,t1.tablespace_name

from user_ind_partitions t1, user_part_indexes t2  where t1.index_name in ('IND_JSSJ02') and t1.index_name=t2.index_name

order by index_name,partition_name;

LOCALI INDEX_NAME                    PARTITION_NAME                STATUS  TABLESPACE_NAME

------ ------------------------------ ------------------------------ -------- ------------------------------

GLOBAL IND_JSSJ02                    P02                            USABLE  USERS

GLOBAL IND_JSSJ02                    P03                            USABLE  USERS

GLOBAL IND_JSSJ02                    P04                            USABLE  USERS

GLOBAL IND_JSSJ02                    P05                            USABLE  USERS

GLOBAL IND_JSSJ02                    PMAX                          USABLE  USERS

--删除某个分区

SQL> alter table JS_SKSKJDK_DZFPMX02  drop partition p02;

Table altered.

--再次检查索引状态

SQL> select  t2.locality,t1.index_name,t1.partition_name,t1.status,t1.tablespace_name

from user_ind_partitions t1, user_part_indexes t2  where t1.index_name in ('IND_JSSJ02') and t1.index_name=t2.index_name

order by index_name,partition_name;

LOCALI INDEX_NAME                    PARTITION_NAME                STATUS  TABLESPACE_NAME

------ ------------------------------ ------------------------------ -------- ------------------------------

GLOBAL IND_JSSJ02                    P02                            UNUSABLE USERS

GLOBAL IND_JSSJ02                    P03                            UNUSABLE USERS

GLOBAL IND_JSSJ02                    P04                            UNUSABLE USERS

GLOBAL IND_JSSJ02                    P05                            UNUSABLE USERS

GLOBAL IND_JSSJ02                    PMAX                          UNUSABLE USERS

--结论: 全局分区索引果然不会自动维护分区索引啊

《本地分区索引》

drop table JS_SKSKJDK_DZFPMX01 purge;

--创建分区表 jssj

SQL> create table JS_SKSKJDK_DZFPMX01(

fpdm      VARCHAR2(12) not null,

fphm      VARCHAR2(8) not null,

jssj      DATE,

CONSTRAINT PK_JS_SKSKJDK_DZFPMX01 PRIMARY KEY(FPHM,FPDM)

USING INDEX TABLESPACE users

)

PARTITION BY RANGE(JSSJ)

(PARTITION p01 VALUES LESS THAN(to_date('2016/8/31 10:53:40','yyyy-mm-dd hh24:mi:ss')) TABLESPACE users) enable row movement;

Table created.

--创建本地分区索引

SQL> create index ind_jssj01 on JS_SKSKJDK_DZFPMX01(jssj)  local tablespace users;

Index created.

-- 为分区表新增分区

SQL> alter table JS_SKSKJDK_DZFPMX01 add partition p02 values  less than (to_date('2016/10/30 10:53:40','yyyy-mm-dd hh24:mi:ss')) tablespace  users;

Table altered.

SQL> alter table JS_SKSKJDK_DZFPMX01 add partition p03 values  less than (to_date('2016/11/30 10:53:40','yyyy-mm-dd hh24:mi:ss')) tablespace  users;

Table altered.

SQL> alter table JS_SKSKJDK_DZFPMX01 add partition p04 values  less than (to_date('2016/12/3 10:53:40','yyyy-mm-dd hh24:mi:ss')) tablespace  users;

Table altered.

SQL> alter table JS_SKSKJDK_DZFPMX01 add partition p05 values  less than (to_date('2016/12/30 10:53:40','yyyy-mm-dd hh24:mi:ss')) tablespace  users;

Table altered.

-- 将局部索引重建于指定的索引分区

alter index ind_jssj  rebuild partition  part04 tablespace users;

--检查索引状态

SQL> select  t2.locality,t1.index_name,t1.partition_name,t1.status,t1.tablespace_name from user_ind_partitions t1, user_part_indexes t2  where t1.index_name in ('IND_JSSJ01') and t1.index_name=t2.index_name

2  order by index_name,partition_name;

LOCALI INDEX_NAME                    PARTITION_NAME                STATUS  TABLESPACE_NAME

------ ------------------------------ ------------------------------ -------- ------------------------------

LOCAL  IND_JSSJ01                    P01                            USABLE  USERS

LOCAL  IND_JSSJ01                    P02                            USABLE  USERS

LOCAL  IND_JSSJ01                    P03                            USABLE  USERS

LOCAL  IND_JSSJ01                    P04                            USABLE  USERS

LOCAL  IND_JSSJ01                    P05                            USABLE  USERS

--删除某个分区

SQL> alter table JS_SKSKJDK_DZFPMX01  drop partition p02;

Table altered.

--再次检查索引状态

SQL> select  t2.locality,t1.index_name,t1.partition_name,t1.status,t1.tablespace_name from user_ind_partitions t1, user_part_indexes t2  where t1.index_name in ('IND_JSSJ01') and t1.index_name=t2.index_name

2  order by index_name,partition_name;

LOCALI INDEX_NAME                    PARTITION_NAME                STATUS  TABLESPACE_NAME

------ ------------------------------ ------------------------------ -------- ------------------------------

LOCAL  IND_JSSJ01                    P01                            USABLE  USERS

LOCAL  IND_JSSJ01                    P03                            USABLE  USERS

LOCAL  IND_JSSJ01                    P04                            USABLE  USERS

LOCAL  IND_JSSJ01                    P05                            USABLE  USERS

--结论 本地分区索引,删除某个分区 对于其他的索引分区没有任何影响

0b1331709591d260c1c78e86d0c51c18.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值