You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by re...@apache.org on 2025/01/12 06:34:25 UTC

(cloudberry) branch at_set_am updated: Fix an issue where the pg_appendonly entry is not removed during AO->heap

This is an automated email from the ASF dual-hosted git repository.

reshke pushed a commit to branch at_set_am
in repository https://gitbox.apache.org/repos/asf/cloudberry.git


The following commit(s) were added to refs/heads/at_set_am by this push:
     new 532cac752e Fix an issue where the pg_appendonly entry is not removed during AO->heap
532cac752e is described below

commit 532cac752e140869579b274ffdce81fb4fcfda65
Author: Huansong Fu <fu...@gmail.com>
AuthorDate: Fri Jul 15 12:25:38 2022 -0700

    Fix an issue where the pg_appendonly entry is not removed during AO->heap
    
    During changing access method from AO to heap, we need to transfer the
    pg_appendonly entry of the AO table to be associated with the newly
    created temp heap table (TransferAppendonlyEntries). But we mistakenly
    insert a new tuple instead of updating the existing tuple. So even the
    one associated with the temp table is removed, we still end up having
    the old pg_appendonly entry, which has the same oid as the resulting
    heap table.
    
    Fixing that. And add test cases for it too.
---
 src/backend/catalog/pg_appendonly.c              |  2 +-
 src/test/regress/expected/alter_table_set_am.out | 47 +++++++++++++++++++++++-
 src/test/regress/sql/alter_table_set_am.sql      | 27 +++++++++++++-
 3 files changed, 73 insertions(+), 3 deletions(-)

diff --git a/src/backend/catalog/pg_appendonly.c b/src/backend/catalog/pg_appendonly.c
index 92c39ba06c..b4618f68e0 100644
--- a/src/backend/catalog/pg_appendonly.c
+++ b/src/backend/catalog/pg_appendonly.c
@@ -620,7 +620,7 @@ TransferAppendonlyEntries(Oid fromrelid, Oid torelid)
 	pg_appendonly_tuple = heap_modify_tuple(pg_appendonly_tuple, pg_appendonly_dsc,
 								   newValues, newNulls, replace);
 
-	CatalogTupleInsert(pg_appendonly_rel, pg_appendonly_tuple);
+	CatalogTupleUpdate(pg_appendonly_rel, &pg_appendonly_tuple->t_self, pg_appendonly_tuple);
 
 	heap_freetuple(pg_appendonly_tuple);
 
diff --git a/src/test/regress/expected/alter_table_set_am.out b/src/test/regress/expected/alter_table_set_am.out
index 2033e7e8bd..5c7b143225 100644
--- a/src/test/regress/expected/alter_table_set_am.out
+++ b/src/test/regress/expected/alter_table_set_am.out
@@ -136,6 +136,14 @@ SELECT * FROM gp_toolkit.__gp_aovisimap('heap2ao2');
 -----+-------+---------
 (0 rows)
 
+-- pg_appendonly should have entries associated with the new AO tables
+SELECT c.relname FROM pg_class c, pg_appendonly p WHERE c.relname LIKE 'heap2ao%' AND c.oid = p.relid;
+ relname  
+----------
+ heap2ao
+ heap2ao2
+(2 rows)
+
 -- check inherited tables
 CREATE TABLE heapbase (a int, b int);
 NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
@@ -293,6 +301,13 @@ SELECT * FROM gp_toolkit.__gp_aovisimap('heapbase2');
 -----+-------+---------
 (0 rows)
 
+SELECT c.relname FROM pg_class c, pg_appendonly p WHERE c.relname LIKE 'heapbase%' AND c.oid = p.relid;
+  relname  
+-----------
+ heapbase
+ heapbase2
+(2 rows)
+
 -- aux tables are not created for child table
 SELECT * FROM gp_toolkit.__gp_aoseg('heapchild');
 ERROR:  'heapchild' is not an append-only row relation  (seg0 slice1 127.0.0.1:7002 pid=29947)
@@ -302,6 +317,11 @@ SELECT * FROM gp_toolkit.__gp_aoseg('heapchild2');
 ERROR:  'heapchild2' is not an append-only row relation  (seg0 slice1 127.0.0.1:7002 pid=29947)
 SELECT * FROM gp_toolkit.__gp_aovisimap('heapchild2');
 ERROR:  function not supported on relation
+SELECT c.relname FROM pg_class c, pg_appendonly p WHERE c.relname LIKE 'heapchild%' AND c.oid = p.relid;
+ relname 
+---------
+(0 rows)
+
 -- Scenario 3: AO to Heap
 SET gp_default_storage_options = 'blocksize=65536, compresstype=zlib, compresslevel=5, checksum=true';
 CREATE TABLE ao2heap(a int, b int) WITH (appendonly=true);
@@ -380,7 +400,13 @@ SELECT * FROM gp_toolkit.__gp_aoseg('ao2heap2');
 ERROR:  'ao2heap2' is not an append-only row relation  (seg0 slice1 127.0.1.1:7002 pid=6817)
 SELECT * FROM gp_toolkit.__gp_aovisimap('ao2heap2');
 ERROR:  function not supported on relation
--- The altered tabless should have heap AM.
+-- No pg_appendonly entries should be left too
+SELECT c.relname FROM pg_class c, pg_appendonly p WHERE c.relname LIKE 'ao2heap%' AND c.oid = p.relid;
+ relname 
+---------
+(0 rows)
+
+-- The altered tables should have heap AM.
 SELECT c.relname, a.amname FROM pg_class c JOIN pg_am a ON c.relam = a.oid WHERE c.relname LIKE 'ao2heap%';
  relname  | amname 
 ----------+--------
@@ -406,3 +432,22 @@ SELECT relname, relfrozenxid <> '0' FROM pg_class WHERE relname LIKE 'ao2heap%';
 
 DROP TABLE ao2heap;
 DROP TABLE ao2heap2;
+-- Final scenario: run the iterations of AT from "A" to "B" and back to "A", that includes:
+-- 1. Heap->AO->Heap->AO
+-- (TODO) 2. AO->AOCO->AO->AOCO
+-- (TODO) 3. Heap->AOCO->Heap->AOCO
+-- 1. Heap->AO->Heap->AO
+CREATE TABLE heapao(a int, b int) WITH (appendonly=true);
+CREATE INDEX heapaoindex ON heapao(b);
+INSERT INTO heapao SELECT i,i FROM generate_series(1,5) i;
+ALTER TABLE heapao SET ACCESS METHOD ao_row;
+ALTER TABLE heapao SET ACCESS METHOD heap;
+ALTER TABLE heapao SET ACCESS METHOD ao_row;
+-- Just checking data is intact. 
+SELECT count(*) FROM heapao;
+ count 
+-------
+     5
+(1 row)
+
+DROP TABLE heapao;
diff --git a/src/test/regress/sql/alter_table_set_am.sql b/src/test/regress/sql/alter_table_set_am.sql
index d0f41a8e71..d082243347 100644
--- a/src/test/regress/sql/alter_table_set_am.sql
+++ b/src/test/regress/sql/alter_table_set_am.sql
@@ -80,6 +80,8 @@ SELECT * FROM gp_toolkit.__gp_aovisimap('heap2ao');
 SELECT * FROM gp_toolkit.__gp_aoseg('heap2ao2');
 SELECT * FROM gp_toolkit.__gp_aovisimap('heap2ao2');
 
+-- pg_appendonly should have entries associated with the new AO tables
+SELECT c.relname FROM pg_class c, pg_appendonly p WHERE c.relname LIKE 'heap2ao%' AND c.oid = p.relid;
 
 -- check inherited tables
 CREATE TABLE heapbase (a int, b int);
@@ -143,12 +145,14 @@ SELECT * FROM gp_toolkit.__gp_aoseg('heapbase');
 SELECT * FROM gp_toolkit.__gp_aovisimap('heapbase');
 SELECT * FROM gp_toolkit.__gp_aoseg('heapbase2');
 SELECT * FROM gp_toolkit.__gp_aovisimap('heapbase2');
+SELECT c.relname FROM pg_class c, pg_appendonly p WHERE c.relname LIKE 'heapbase%' AND c.oid = p.relid;
 
 -- aux tables are not created for child table
 SELECT * FROM gp_toolkit.__gp_aoseg('heapchild');
 SELECT * FROM gp_toolkit.__gp_aovisimap('heapchild');
 SELECT * FROM gp_toolkit.__gp_aoseg('heapchild2');
 SELECT * FROM gp_toolkit.__gp_aovisimap('heapchild2');
+SELECT c.relname FROM pg_class c, pg_appendonly p WHERE c.relname LIKE 'heapchild%' AND c.oid = p.relid;
 
 -- Scenario 3: AO to Heap
 SET gp_default_storage_options = 'blocksize=65536, compresstype=zlib, compresslevel=5, checksum=true';
@@ -193,7 +197,10 @@ SELECT * FROM gp_toolkit.__gp_aovisimap('ao2heap');
 SELECT * FROM gp_toolkit.__gp_aoseg('ao2heap2');
 SELECT * FROM gp_toolkit.__gp_aovisimap('ao2heap2');
 
--- The altered tabless should have heap AM.
+-- No pg_appendonly entries should be left too
+SELECT c.relname FROM pg_class c, pg_appendonly p WHERE c.relname LIKE 'ao2heap%' AND c.oid = p.relid;
+
+-- The altered tables should have heap AM.
 SELECT c.relname, a.amname FROM pg_class c JOIN pg_am a ON c.relam = a.oid WHERE c.relname LIKE 'ao2heap%';
 
 -- The new heap tables shouldn't have the old AO table's reloptions
@@ -204,3 +211,21 @@ SELECT relname, relfrozenxid <> '0' FROM pg_class WHERE relname LIKE 'ao2heap%';
 
 DROP TABLE ao2heap;
 DROP TABLE ao2heap2;
+
+-- Final scenario: run the iterations of AT from "A" to "B" and back to "A", that includes:
+-- 1. Heap->AO->Heap->AO
+-- (TODO) 2. AO->AOCO->AO->AOCO
+-- (TODO) 3. Heap->AOCO->Heap->AOCO
+
+-- 1. Heap->AO->Heap->AO
+CREATE TABLE heapao(a int, b int) WITH (appendonly=true);
+CREATE INDEX heapaoindex ON heapao(b);
+INSERT INTO heapao SELECT i,i FROM generate_series(1,5) i;
+
+ALTER TABLE heapao SET ACCESS METHOD ao_row;
+ALTER TABLE heapao SET ACCESS METHOD heap;
+ALTER TABLE heapao SET ACCESS METHOD ao_row;
+
+-- Just checking data is intact. 
+SELECT count(*) FROM heapao;
+DROP TABLE heapao;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org