测试说明
测试流程
建立测试表 测试4组分区表分区裁剪功能 测试4组分区表静态数据分区删除功能
测试结论
序号 | 测试大项 | 测试结论 |
1 | 无索引表分区裁剪功能 | 通过,可以正常使用分区裁剪 |
2 | 全局索引表分区裁剪功能 | 通过,可以正常使用分区裁剪 |
3 | 本地普通索引表分区裁剪功能 | 通过,可以正常使用分区裁剪 |
4 | 本地主键索引表分区裁剪功能 | 通过,可以正常使用分区裁剪 |
5 | 删除无索引静态分区是否上锁 | 通过,无论分区表存在DDL还是DML,都可以删除静态分区 |
6 | 删除全局索引静态分区是否上锁 | 通过,无论分区表存在DDL还是DML,都可以删除静态分区 |
7 | 删除本地索引静态分区是否上锁 | 通过,无论分区表存在DDL还是DML,都可以删除静态分区 |
8 | 删除本地主键静态分区是否上锁 | 通过,无论分区表存在DDL还是DML,都可以删除静态分区 |
版本信息
测试步骤
创建全局索引分区表:
CREATE TABLE t_part_noindex (
id int not null,
remark varchar,
ctime date
) PARTITION BY RANGE (ctime)
(
partition p1 values less than('2023-04-01'),
partition p2 values less than('2023-07-01'),
partition p3 values less than('2023-10-01'),
partition p4 values less than(maxvalue)
)
ENABLE ROW MOVEMENT;
复制
插入数据:
insert into t_part_noindex select generate_series(1,364),'global test',generate_series('2023-01-01'::date,'2023-12-30'::date,'1 day');
复制
查看表结构:
\d+ t_part_noindex
复制

创建全局索引分区表:
CREATE TABLE t_part_noindex (
id int not null,
remark varchar,
ctime date
) PARTITION BY RANGE (ctime)
(
partition p1 values less than('2023-04-01'),
partition p2 values less than('2023-07-01'),
partition p3 values less than('2023-10-01'),
partition p4 values less than(maxvalue)
)
ENABLE ROW MOVEMENT;
复制
插入数据:
insert into t_part_global select generate_series(1,364),'global test',generate_series('2023-01-01'::date,'2023-12-30'::date,'1 day');
复制
创建全局索引:
create index ind_global on t_part_global (ctime) GLOBAL;
复制
查看表结构:
\d+ t_part_global
复制

创建本地索引分区表:
CREATE TABLE t_part_local (
id int not null,
remark varchar,
ctime date
) PARTITION BY RANGE (ctime)
(
partition p1 values less than('2023-04-01'),
partition p2 values less than('2023-07-01'),
partition p3 values less than('2023-10-01'),
partition p4 values less than(maxvalue)
)
ENABLE ROW MOVEMENT;
复制
插入数据:
insert into t_part_local select generate_series(1,364),'global test',generate_series('2023-01-01'::date,'2023-12-30'::date,'1 day');
复制
创建本地索引(注意如果建立带有unique属性的本地索引,字段需要引用partition key):
create index ind_local on t_part_local (ctime) LOCAL;
复制
查看表结构:
\d+ t_part_local
复制

CREATE TABLE t_part_primary (
id int not null,
remark varchar,
ctime date
) PARTITION BY RANGE (ctime)
(
partition p1 values less than('2023-04-01'),
partition p2 values less than('2023-07-01'),
partition p3 values less than('2023-10-01'),
partition p4 values less than(maxvalue)
)
ENABLE ROW MOVEMENT;
复制
插入数据:
insert into t_part_primary select generate_series(1,364),'global test',generate_series('2023-01-01'::date,'2023-12-30'::date,'1 day');
复制
创建主键(注意当主键索引列带partition key,会建立本地索引;如果不带partition key,则建立全局索引,本次测试建立带有local属性的主键):
alter table t_part_primary add constraint pk_primary primary key(ctime);
复制
查看表结构:
\d+ t_part_primary
复制

select c.schemaname||'.'||b.parentid::regclass table_name,
a.parentid::regclass index_name,
b.relname table_partition_name,
a.relname index_partition_name,
a.indisusable index_partition_status
from pg_partition a,pg_partition b,pg_stat_user_tables c
where a.indextblid = b.oid(+)
and b.parentid=c.relid
and a.parttype='x'
and a.parentid in (select indexrelid index_name from pg_index where indrelid in ('t_part_local'::regclass,'t_part_global'::regclass,'t_part_primary'::regclass))
order by 1,2,3,4;
复制

analyze t_part_noindex;
analyze t_part_global;
analyze t_part_local;
analyze t_part_primary;
复制
explain (analyze,verbose) select * from t_part_noindex where ctime='2023-01-15'::date;
复制
explain (analyze,verbose) select * from t_part_global where ctime='2023-01-15'::date;
复制
explain (analyze,verbose) select * from t_part_local where ctime='2023-04-15'::date;
复制
explain (analyze,verbose) select * from t_part_primary where ctime='2023-08-15'::date;
复制

begin;
explain (analyze,verbose) select * from t_part_noindx where ctime = '2023-04-01 00:00:00'::timestamp;
explain (analyze,verbose) select /*+ indexscan(t_part_global ind_global) */ * from t_part_global where ctime = '2023-04-01 00:00:00'::timestamp;
explain (analyze,verbose) select /*+ indexscan(t_part_local ind_local) */ * from t_part_local where ctime = '2023-04-01 00:00:00'::timestamp;
explain (analyze,verbose) select /*+ indexscan(t_part_local pk_primary) */ * from t_part_primary where ctime = '2023-04-01 00:00:00'::timestamp;
复制
SELECT pid,database,locktype, relation::regclass,mode,granted FROM pg_locks where granted='t' and database is not null;
复制

alter table t_part_noindex drop partition p1;
alter table t_part_global drop partition p1;
alter table t_part_local drop partition p1;
alter table t_part_primary drop partition p1;
复制

begin;
explain (analyze,verbose) update t_part_noindex set id = 1000 where ctime = '2023-04-01 00:00:00'::timestamp;
explain (analyze,verbose) update t_part_global set id = 1000 where ctime = '2023-04-01 00:00:00'::timestamp;
explain (analyze,verbose) update t_part_local set id = 1000 where ctime = '2023-04-01 00:00:00'::timestamp;
explain (analyze,verbose) update t_part_primary set id = 1000 where ctime = '2023-04-01 00:00:00'::timestamp;
复制
SELECT pid,database,locktype, relation::regclass,mode,granted FROM pg_locks where granted='t' and database is not null;
复制

alter table t_part_noindex drop partition p3;
alter table t_part_global drop partition p3;
alter table t_part_local drop partition p3;
alter table t_part_primary drop partition p3;
复制

\d t_part_noindex
\d t_part_global
\d t_part_local
\d t_part_primary
复制

注意事项
==>global primary key
alter table xx add constraint yy primary(普通列);
==>local primary key
alter table xx add constraint yy primary(普通列,分区列);
复制


关于作者
END
MogDB 是云和恩墨基于 openGauss 开源内核进行增强提升,推出的一款安稳易用的企业级关系型数据库。其具备金融级高可用和全密态计算的极致安全、面向多核处理器的极致性能、AI自诊断调优的极致智能能力,能够满足从核心交易到复杂计算的企业级业务需求。
访问官网了解更多:www.mogdb.io
产品兼容适配申请:partner@enmotech.com
进入交流群:Roger_database
文章转载自MogDB,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
Flink CDC+Hologres高性能数据同步优化实践
阿里云大数据AI技术
85次阅读
2025-03-18 09:46:17
诡异宕机,为何分区表会匹配到错误的表名?
爱可生开源社区
36次阅读
2025-03-25 10:37:40
第 53 期:EXPLAIN 中最直观的 rows
爱可生开源社区
33次阅读
2025-03-21 10:34:08
MySQL索引实现
怀念和想念
30次阅读
2025-03-24 18:14:25
不懂 Oracle 11g、12c、19c 这些主要新功能,你还好意思说自己是高级 DBA?
青年数据库学习互助会
27次阅读
2025-03-27 10:00:37
数据库性能优化一:数据库自身优化(大数据量)
听溪
24次阅读
2025-03-31 19:40:43
数据库索引所采用的数据结构B-/+Tree及其性能分析
luyingjun
24次阅读
2025-03-24 18:12:31
oracle分区表
芃芃
23次阅读
2025-04-05 16:37:38
《突破数据困境:超大分区表的游标优化策略》
程序员阿伟
21次阅读
2025-04-02 16:25:49
PolarDB-PG 多级分区表静态裁剪与并行扫描
PolarDB
20次阅读
2025-03-19 11:20:45