点击上方"蓝字"
关注我们,享更多干货!
01
概述
openGauss分区表支持两种索引:全局(global)索引和本地(local)索引。
分区表创建索引不支持concurrently语法,默认索引是全局索引,创建本地索引需要指定local。
创建主键约束和唯一约束必须要包含分区字段,创建本地唯一索引也必须要包含分区字段,但是创建全局唯一索引没有这个限制。
postgres=# create index concurrently on part_index_test(col2,col1,col3);
ERROR: cannot create concurrent partitioned indexes
本文主要阐述添加或删除分区对索引的影响。
数据库版本:openGauss 1.1.0
02
测试
一.建表语句
范围分区中的间隔语法可以自动追加分区表,这里以间隔分区表为例:
create table part_index_test(
partid varchar(32) not null,
col1 varchar(2) not null,
col2 date not null,
col3 varchar(8) not null
)partition by range(col2)
interval('1 day')
(
partition part1 values less than ('20210331'),
partition part2 values less than ('20210401')
);
全局索引:
create index on part_index_test(col2,col1,col3);
本地索引:
create index on part_index_test(col2,col1,col3) local;
二.测试数据
间隔分区是以1天为单位,所以新增一天的数据,会自动增加一个以sys_p开头的自增分区:
i