From 5e75d1ac316c445527ae9f1767a448aad63556b5 Mon Sep 17 00:00:00 2001 From: chenze Date: Fri, 21 Apr 2023 18:01:32 +0800 Subject: [PATCH 1/2] enable vacuum refresh relallvisible flag for partition table --- .../storage/access/heap/visibilitymap.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/gausskernel/storage/access/heap/visibilitymap.cpp b/src/gausskernel/storage/access/heap/visibilitymap.cpp index e50f73d3a3..f5c1a66d44 100644 --- a/src/gausskernel/storage/access/heap/visibilitymap.cpp +++ b/src/gausskernel/storage/access/heap/visibilitymap.cpp @@ -96,6 +96,7 @@ #include "utils/inval.h" #include "commands/tablespace.h" #include "catalog/pg_hashbucket_fn.h" +#include "catalog/pg_partition_fn.h" #include "utils/syscache.h" /* table for fast counting of set bits */ static const uint8 number_of_ones[256] = { @@ -373,6 +374,22 @@ BlockNumber visibilitymap_count(Relation rel, Partition part) result += visibilitymap_count_heap(buckRel); bucketCloseRelation(buckRel); } + } else if (RelationIsPartitioned(rel) && PointerIsValid(part)) { + Relation partRel = partitionGetRelation(rel, part); + if (RelationIsSubPartitioned(rel) && PartitionIsTablePartition(part)) { + List *subPartList = relationGetPartitionList(partRel, NoLock); + ListCell *lc = NULL; + foreach (lc, subPartList) { + Partition subPart = (Partition)lfirst(lc); + Relation subPartRel = partitionGetRelation(rel, subPart); + result += visibilitymap_count_heap(subPartRel); + releaseDummyRelation(&subPartRel); + } + releasePartitionList(partRel, &subPartList, NoLock); + } else { + result = visibilitymap_count_heap(partRel); + } + releaseDummyRelation(&partRel); } else { result = visibilitymap_count_heap(rel); } -- Gitee From 6d08987049dbbaa59bbed489a963d4b4af62b89e Mon Sep 17 00:00:00 2001 From: chenze Date: Sun, 23 Apr 2023 10:48:04 +0800 Subject: [PATCH 2/2] fix regress --- src/test/regress/expected/gpi_cluster_02.out | 48 ++++++++++---------- src/test/regress/sql/gpi_cluster_02.sql | 8 ++-- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/test/regress/expected/gpi_cluster_02.out b/src/test/regress/expected/gpi_cluster_02.out index a20c639a59..f271061028 100644 --- a/src/test/regress/expected/gpi_cluster_02.out +++ b/src/test/regress/expected/gpi_cluster_02.out @@ -100,34 +100,34 @@ select true from (select correlation from pg_stats where tablename='inventory_ta ------ (0 rows) -select part.relname, part.parttype, part.rangenum, part.intervalnum, part.partstrategy, part.relallvisible, part.partkey, part.interval, part.boundaries, part.reltuples +select part.relname, part.parttype, part.rangenum, part.intervalnum, part.partstrategy, part.partkey, part.interval, part.boundaries, part.reltuples from pg_class class, pg_partition part, pg_index ind where class.relname = 'inventory_table_02' and ind.indrelid = class.oid and part.parentid = ind.indexrelid -order by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10; - relname | parttype | rangenum | intervalnum | partstrategy | relallvisible | partkey | interval | boundaries | reltuples ----------+----------+----------+-------------+--------------+---------------+---------+----------+------------+----------- +order by 1, 2, 3, 4, 5, 6, 7, 8, 9; + relname | parttype | rangenum | intervalnum | partstrategy | partkey | interval | boundaries | reltuples +---------+----------+----------+-------------+--------------+---------+----------+------------+----------- (0 rows) -select part.relname, part.parttype, part.rangenum, part.intervalnum, part.partstrategy, part.relallvisible, part.partkey, part.interval, part.boundaries, part.reltuples +select part.relname, part.parttype, part.rangenum, part.intervalnum, part.partstrategy, part.partkey, part.interval, part.boundaries, part.reltuples from pg_class class, pg_partition part, pg_index ind where class.relname = 'inventory_table_02' and ind.indrelid = class.oid and part.parentid = ind.indrelid -order by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10; - relname | parttype | rangenum | intervalnum | partstrategy | relallvisible | partkey | interval | boundaries | reltuples ---------------------+----------+----------+-------------+--------------+---------------+---------+----------+------------+----------- - inventory_table_02 | r | 0 | 0 | r | 0 | 1 | | | 0 - inventory_table_02 | r | 0 | 0 | r | 0 | 1 | | | 0 - p1 | p | 0 | 0 | r | 0 | | | {10000} | 9999 - p1 | p | 0 | 0 | r | 0 | | | {10000} | 9999 - p2 | p | 0 | 0 | r | 0 | | | {20000} | 10000 - p2 | p | 0 | 0 | r | 0 | | | {20000} | 10000 - p3 | p | 0 | 0 | r | 0 | | | {30000} | 10000 - p3 | p | 0 | 0 | r | 0 | | | {30000} | 10000 - p4 | p | 0 | 0 | r | 0 | | | {40000} | 10000 - p4 | p | 0 | 0 | r | 0 | | | {40000} | 10000 - p5 | p | 0 | 0 | r | 0 | | | {50000} | 10000 - p5 | p | 0 | 0 | r | 0 | | | {50000} | 10000 - p6 | p | 0 | 0 | r | 0 | | | {60000} | 10000 - p6 | p | 0 | 0 | r | 0 | | | {60000} | 10000 - p7 | p | 0 | 0 | r | 0 | | | {NULL} | 40001 - p7 | p | 0 | 0 | r | 0 | | | {NULL} | 40001 +order by 1, 2, 3, 4, 5, 6, 7, 8, 9; + relname | parttype | rangenum | intervalnum | partstrategy | partkey | interval | boundaries | reltuples +--------------------+----------+----------+-------------+--------------+---------+----------+------------+----------- + inventory_table_02 | r | 0 | 0 | r | 1 | | | 0 + inventory_table_02 | r | 0 | 0 | r | 1 | | | 0 + p1 | p | 0 | 0 | r | | | {10000} | 9999 + p1 | p | 0 | 0 | r | | | {10000} | 9999 + p2 | p | 0 | 0 | r | | | {20000} | 10000 + p2 | p | 0 | 0 | r | | | {20000} | 10000 + p3 | p | 0 | 0 | r | | | {30000} | 10000 + p3 | p | 0 | 0 | r | | | {30000} | 10000 + p4 | p | 0 | 0 | r | | | {40000} | 10000 + p4 | p | 0 | 0 | r | | | {40000} | 10000 + p5 | p | 0 | 0 | r | | | {50000} | 10000 + p5 | p | 0 | 0 | r | | | {50000} | 10000 + p6 | p | 0 | 0 | r | | | {60000} | 10000 + p6 | p | 0 | 0 | r | | | {60000} | 10000 + p7 | p | 0 | 0 | r | | | {NULL} | 40001 + p7 | p | 0 | 0 | r | | | {NULL} | 40001 (16 rows) cluster inventory_table_02 using global_inventory_table_02_index2; diff --git a/src/test/regress/sql/gpi_cluster_02.sql b/src/test/regress/sql/gpi_cluster_02.sql index 0ea06a9c68..4dccee4b0d 100644 --- a/src/test/regress/sql/gpi_cluster_02.sql +++ b/src/test/regress/sql/gpi_cluster_02.sql @@ -61,13 +61,13 @@ vacuum analyze inventory_table_02; select true from (select correlation from pg_stats where tablename='inventory_table_02' and attname='inv_date_sk') where correlation = 1; select true from (select correlation from pg_stats where tablename='inventory_table_02' and attname='inv_item_sk') where correlation = 1; -select part.relname, part.parttype, part.rangenum, part.intervalnum, part.partstrategy, part.relallvisible, part.partkey, part.interval, part.boundaries, part.reltuples +select part.relname, part.parttype, part.rangenum, part.intervalnum, part.partstrategy, part.partkey, part.interval, part.boundaries, part.reltuples from pg_class class, pg_partition part, pg_index ind where class.relname = 'inventory_table_02' and ind.indrelid = class.oid and part.parentid = ind.indexrelid -order by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10; +order by 1, 2, 3, 4, 5, 6, 7, 8, 9; -select part.relname, part.parttype, part.rangenum, part.intervalnum, part.partstrategy, part.relallvisible, part.partkey, part.interval, part.boundaries, part.reltuples +select part.relname, part.parttype, part.rangenum, part.intervalnum, part.partstrategy, part.partkey, part.interval, part.boundaries, part.reltuples from pg_class class, pg_partition part, pg_index ind where class.relname = 'inventory_table_02' and ind.indrelid = class.oid and part.parentid = ind.indrelid -order by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10; +order by 1, 2, 3, 4, 5, 6, 7, 8, 9; cluster inventory_table_02 using global_inventory_table_02_index2; -- Gitee