原文麇集:https://www.gbase.cn/community/post/4917开云·体育平台(kaiyun)(中国)官网入口登录
更多精彩骨子尽在南大通用GBase技能社区开云·体育平台(kaiyun)(中国)官网入口登录,南大通用用功于成为用户最相信的数据库居品供应商。
分区表的轮廓 分区表通过使用分区技能,将一张大表,拆分红多个表分区(孤苦的segment),从而栽培数据访谒的性能,以及日常的可儿惜性。 分区表中,每个分区的逻辑结构必须相易。如:列名、数据类型。 分区表中,每个分区的物理存储参数不错不同。如:各个分区场合的表空间。 关于利用而言透澈透明,分区前后莫得变化,不需要进行修改。 分区表的谨防事项 现在复旧的分区有 RANGE 分区、LIST 分区、HASH 分区、KEY 分区。 RANGE 分区表和 LIST 分区表复旧子分区,子分区只能以是 HASH 分区或者 KEY分区,每个分区的子分区个数必须相易。 包括子分区在内通盘分区总额个数不大于 8192,坐褥环境中最少保合手单表分区总额在50个以下。 分区列不复旧 update 操作。 分区表的性能测试伸开剩余92%1. 分散创建一个分区的表和非分区的表,进行性能测试。
##创建测试库##
create database testdb;
use testdb;
##创建平方表##
create table no_part_tab ( c1 int default NULL, c2 varchar(30) default null, c3 date default null);
##创建分区表##
create table part_tab ( c1 int default NULL, c2 varchar(30) default null, c3 date default null)
partition by range(year(c3))(
partition p0 values less than (1995),
partition p1 values less than (1996),
partition p2 values less than (1997),
partition p3 values less than (1998),
partition p4 values less than (1999),
partition p5 values less than (2000),
partition p6 values less than (2001),
partition p7 values less than (2002),
partition p8 values less than (2003),
partition p9 values less than MAXVALUE);
示举例下:
2. 生成模拟数据
use testdb;
##创建存储经过生成测试数据##
delimiter //
create procedure load_no_part_tab()
begin
declare v int default 0;
while v < 2000000
do
insert into no_part_tab
values (v,'testing partitions',adddate('1994-01-01',(rand(v)*36520)mod 3652));
set v = v+1;
end while;
commit;
end
//
delimiter ;
示举例下:
关闭事务自动提交参数,使数据插入更快速。use testdb;
set global _t_gcluster_oldtransaction_support_set_autocommit =1;
示举例下:
##从头登陆后使参数收效,实行存储并生成模拟数据##
set autocommit=0;
##多实行几次,使数据均匀散播##
call load_no_part_tab();
call load_no_part_tab();
call load_no_part_tab();
call load_no_part_tab();
call load_no_part_tab();
set autocommit=1;
示举例下:
生成更巨额据,使后续查询效果更显明insert into no_part_tab select * from no_part_tab;
insert into no_part_tab select * from no_part_tab;
insert into no_part_tab select * from no_part_tab;
insert into no_part_tab select * from no_part_tab;
insert into no_part_tab select * from no_part_tab;
insert into no_part_tab select * from no_part_tab;
insert into no_part_tab select * from no_part_tab;
insert into no_part_tab select * from no_part_tab;
示举例下:
将平方表数据同步给分区表insert into part_tab select * from no_part_tab;
示举例下:
3. 实行查询,对比分区表和平方表的查询速率。
select count(*) from part_tab where c3 > to_date('1995-01-01','yyyy-mm-dd') and c3 < to_date('1995-12-31','yyyy-mm-dd') and c1 like '252%';
select count(*) from no_part_tab where c3 > to_date('1995-01-01','yyyy-mm-dd') and c3 < to_date('1995-12-31','yyyy-mm-dd') and c1 like '252%';
示举例下:
跨单个分区表查询只需要16秒,而平方表则需要158秒的时刻。select count(*) from part_tab where c3 > to_date('1995-01-01','yyyy-mm-dd') and c3 < to_date('1996-12-31','yyyy-mm-dd');
select count(*) from no_part_tab where c3 > to_date('1995-01-01','yyyy-mm-dd') and c3 < to_date('1996-12-31','yyyy-mm-dd');
示举例下:
跨两个分区表查询只需要9秒,而平方表则需要43秒的时刻。##调度并行度防患内存超出##
set gbase_parallel_degree=8;
##测试update所需时刻##
update part_tab set c2='test update' where c3 > to_date('1997-01-01','yyyy-mm-dd') and c3 < to_date('1997-12-31','yyyy-mm-dd') and c1=151;
update no_part_tab set c2='test update' where c3 > to_date('1997-01-01','yyyy-mm-dd') and c3 < to_date('1997-12-31','yyyy-mm-dd') and c1=151;
示举例下:
跨单个分区的update所需时刻为8秒,平方表的通盘update更新时刻为78秒。
论断刻下数据库版块为953.27.20_patch 9
查询分区表每个分区数据:
select count(*) from part_tab partition(p0);
select count(*) from part_tab partition(p1);
select count(*) from part_tab partition(p8);
select count(*) from part_tab partition(p9);
示举例下:
为便捷考据,数据生成的时候贪图的即是每个分区数据尽量均匀散播,所有这个词十个分区,是以阐述跨单个分区表查询只需要16秒,而平方表则需要158秒,约莫十倍;跨两个分区表查询只需要9秒,而平方表则需要43秒的时刻,约莫5倍;跨单个分区的update也简略为平方表update 的异常之一,即可考据Gbase 8a 分区表的查询只会检索刻下分区内的数据,而平方表检索整表数据,性能上会大大优化。
原文麇集:https://www.gbase.cn/community/post/4917
更多精彩骨子尽在南大通用GBase技能社区,南大通用用功于成为用户最相信的数据库居品供应商。
发布于:天津市