暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

openGauss每日一练第19天,收集统计信息、打印执行计划、垃圾收集和checkpoint

原创 虫爷 2021-12-19
363

openGauss每日一练第19天课后作业


1.创建分区表,并用generate_series(1,N)函数对表插入数据

create table store (

prod_id int not null,

price numeric(10,2),

amount int)

partition by range (prod_id)

(   partition store_p1 values less than (1000),

    partition store_p2 values less than (2000),

    partition store_p3 values less than (3000),

    partition store_p4 values less than (4000),

    partition store_p5 values less than (maxvalue));

insert into store values

(56,1300.99,15),

(1201,98.88,12),

(2340,9.99,34),

(4928,5.36,6),

(3870,6431.99,3);

insert into store values(generate_series(10, 5000));

create table store ( 
prod id int not null, 
price 
amount int) 
partition by range (prod id) 
partition store pl values 
partition store p2 values 
partition store p3 values 
partition store p4 values 
partition store p5 values 
CREATE TABLE 
insert into store values 
(56, 1300.99, 15), 
(1201, 98.88, 12), 
INSERT Ø 5 
less 
less 
less 
less 
less 
than 
than 
than 
than 
than 
(2000), 
(4000), 
(maxvalue) ) ; 
insert into store values( generate series( 10, 
INSERT Ø 4991

2.收集表统计信息

select relname, relpages, reltuples from pg_class where relname = 'store';

analyze VERBOSE store;

select relname, relpages, reltuples from pg_class where relname = 'store';

select relname, 
relname 
relpages 
relpages, reltuples fran pg_class where relname 
reltuples 
store; 
store' • 
store 
01 
analyze VERBOSE 
INFO: analyzing "public . store" (dn 6001 pid 
-20849) 
. "store" : 
INFO: ANALYZE INFO • 
al rcms(dn 6001 pid=2Ø849) 
: "store" : 
INFO: ANALYZE INFO 
total rcms(dn 6001 pid=2Ø849) 
. "store" : 
INFO: ANALYZE INFO • 
total rcms(dn 6001 pid=2Ø849) 
. "store" : 
INFO: ANALYZE INFO • 
total rcms(dn 6001 pid=2Ø849) 
. "store" : 
INFO: ANALYZE INFO • 
total rcms(dn 6001 pid=2Ø849) 
ANALYZE 
sc anned 
sc anned 
sc anned 
sc anned 
sc anned 
5 
5 
5 
5 
5 
of 
of 
of 
of 
of 
5 
5 
5 
5 
5 
pages, 
pages, 
pages, 
pages, 
pages, 
containing 
containing 
containing 
containing 
containing 
991 live rcms and dead rcms; 991 rcms in sample, 991 estimated tot 
1001 live rcms and dead rcms; 
1001 live rcms and dead rcms; 
1001 live rcms and dead rcms; 
1002 live rcms and dead rcms; 
1001 rcms in sample, 
1001 rcms in sample, 
1001 rcms in sample, 
1002 rcms in sample, 
1001 estimated 
1001 estimated 
1001 estimated 
1002 estimated 
select relname, relpages, reltuples fran pg_class where relname 
relname 
relpages 
reltuples 
store' • 
store 
25 | 
4996

3.显示简单查询的执行计划;建立索引并显示有索引条件的执行计划

SET explain_perf_mode=normal;

EXPLAIN SELECT * FROM store;

create index store_idx on store(prod_id);

EXPLAIN SELECT * FROM store WHERE prod_id<1000;

4.更新表数据,并做垃圾收集

update store set prod_id = prod_id +1 where prod_id <2000;

VACUUM (VERBOSE, ANALYZE) store;

5.清理数据

drop table store cascade;

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论