第十九天学习openGauss收集统计信息、打印执行计划、垃圾收集和checkpoint。
连接openGauss
su - omm gsql -r
1.创建分区表,并用generate_series(1,N)函数对表插入数据
create table tab(id int not null,name varchar(20))
partition by range(id)
(
partition store_p0 values less than (50),
partition store_p1 values less than (100),
partition store_p2 values less than (150),
partition store_p3 values less than (200)
);
insert into tab values(1,'a'),(51,'b'),(101,'c'),(151,'d');
insert into tab select generate_series(1,199),'test';
2.收集表统计信息
--查看系统表中表的统计信息
select relname, relpages, reltuples from pg_class where relname = 'tab';
--使用ANALYZE VERBOSE语句更新统计信息,并输出表的相关信息
analyze verbose tab;
--查看系统表中表的统计信息
select relname, relpages, reltuples from pg_class where relname = 'tab';
3.显示简单查询的执行计划;建立索引并显示有索引条件的执行计划
--使用默认的打印格式
SET explain_perf_mode=normal;
--显示表简单查询的执行计划
explain select * from tab;
--有索引条件的执行计划
create index store_index1 on tab(id) local;
explain select * from tab where id<100;
4.更新表数据,并做垃圾收集
update tab set id = id + 1 where id < 100;
VACUUM (VERBOSE, ANALYZE) tab;
5.清理数据
drop table tab;
上面实际操作截图如下:




通过以上实操,学习到openGauss的收集统计信息、打印执行计划、垃圾收集和checkpoint。了解到VACUUM回收表或B-Tree索引中已经删除的行所占据的存储空间。检查点(CHECKPOINT)是一个事务日志中的点,所有数据文件都在该点被更新以反映日志中的信息,所有数据文件都将被刷新到磁盘。
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




