学习目标:学习openGauss收集统计信息、打印执行计划、垃圾收集和checkpoint
课程内容:
–检查点(CHECKPOINT)是一个事务日志中的点,所有数据文件都在该点被更新以反映日志中的信息,所有数据文件都将被刷新到磁盘。
部分学习内容如下所示:
课程作业:
1.创建分区表,并用generate_series(1,N)函数对表插入数据
omm=# create table products(id integer,name char(20)) partition by range(id)
omm-# (partition p1 values less than (100),partition p2 values less than (200),
omm(# partition p3 values less than(maxvalue));
CREATE TABLE
omm=# insert into products values(generate_series(4,1000));
INSERT 0 997
2.收集表统计信息
omm=# select relname,relpages,reltuples from pg_class where relname = 'products';
omm=# relname | relpages | reltuples
----------+----------+-----------
products | 0 | 0
(1 row)
3.显示简单查询的执行计划;建立索引并显示有索引条件的执行计划
omm=# explain select * from products;
QUERY PLAN
------------------------------------------------------------------------------
Partition Iterator (cost=0.00..16.92 rows=692 width=88)
Iterations: 3
-> Partitioned Seq Scan on products (cost=0.00..16.92 rows=692 width=88)
Selected Partitions: 1..3
(4 rows)
omm=# create index product_index on products(id);
CREATE INDEX
omm=# explain select * from products where id >400;
QUERY PLAN
------------------------------------------------------------------------------
Partition Iterator (cost=0.00..11.65 rows=231 width=88)
omm=# Iterations: 1
-> Partitioned Seq Scan on products (cost=0.00..11.65 rows=231 width=88)
Filter: (id > 400)
Selected Partitions: 3
(5 rows)
4.更新表数据,并做垃圾收集
omm=# update products set id = id + 1;
UPDATE 997
omm=# vacuum (verbose,analyze) products;
INFO: vacuuming "public.products"(gaussdb pid=1)
INFO: index "product_index" now contains 191 row versions in 11 pages(gaussdb pid=1)
DETAIL: 0 index row versions were removed.
0 index pages have been deleted, 0 are currently reusable.
CPU 0.00s/0.00u sec elapsed 0.00 sec.
INFO: "products": found 0 removable, 191 nonremovable row versions in 1 out of 1 pages(gaussdb pid=1)
DETAIL: 96 dead row versions cannot be removed yet.
There were 0 unused item pointers.
0 pages are entirely empty.
CPU 0.00s/0.00u sec elapsed 0.00 sec.
INFO: vacuuming "public.products"(gaussdb pid=1)
INFO: index "product_index" now contains 200 row versions in 11 pages(gaussdb pid=1)
DETAIL: 0 index row versions were removed.
0 index pages have been deleted, 0 are currently reusable.
CPU 0.00s/0.00u sec elapsed 0.00 sec.
INFO: "products": found 0 removable, 200 nonremovable row versions in 1 out of 1 pages(gaussdb pid=1)
DETAIL: 100 dead row versions cannot be removed yet.
There were 0 unused item pointers.
0 pages are entirely empty.
CPU 0.00s/0.00u sec elapsed 0.00 sec.
INFO: vacuuming "public.products"(gaussdb pid=1)
INFO: index "product_index" now contains 1603 row versions in 11 pages(gaussdb pid=1)
DETAIL: 0 index row versions were removed.
0 index pages have been deleted, 0 are currently reusable.
CPU 0.00s/0.00u sec elapsed 0.00 sec.
INFO: "products": found 0 removable, 1603 nonremovable row versions in 8 out of 8 pages(gaussdb pid=1)
DETAIL: 801 dead row versions cannot be removed yet.
There were 0 unused item pointers.
0 pages are entirely empty.
CPU 0.00s/0.00u sec elapsed 0.00 sec.
INFO: scanned index "product_index" to remove 0.000000 invisible rows(gaussdb pid=1)
DETAIL: CPU 0.00s/0.00u sec elapsed 0.00 sec.
INFO: analyzing "public.products"(gaussdb pid=1)
INFO: ANALYZE INFO : "products": scanned 1 of 1 pages, containing 95 live rows and 96 dead rows; 95 rows in sample, 95 estimated total rows(gaussdb pid=1)
INFO: ANALYZE INFO : "products": scanned 1 of 1 pages, containing 100 live rows and 100 dead rows; 100 rows in sample, 100 estimated total rows(gaussdb pid=1)
INFO: ANALYZE INFO : "products": scanned 8 of 8 pages, containing 802 live rows and 801 dead rows; 802 rows in sample, 802 estimated total rows(gaussdb pid=1)
VACUUM
5.清理数据
omm=# drop table products;
DROP TABLE