From 1dd7a8f3da3cf018a692ca1b9e770012ee3a8967 Mon Sep 17 00:00:00 2001 From: "tender.wang" Date: Wed, 17 Jan 2024 23:00:11 +0800 Subject: [PATCH v2] Fix self updated tuple invisible for catalog tuple. We may update tuple more times in complex inheritance case. Previously, we forgot to update the Command Counter, so we couldn't update the tuple which we updated it before. --- src/backend/commands/tablecmds.c | 6 +++++- src/test/regress/expected/inherit.out | 17 +++++++++++++++++ src/test/regress/sql/inherit.sql | 11 +++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 2a56a4357c..1c0f4bfc78 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -7077,7 +7077,11 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel, colDef->colname, RelationGetRelationName(rel)))); table_close(attrdesc, RowExclusiveLock); - return InvalidObjectAddress; + + /* Make sure the child column change is visible */ + CommandCounterIncrement(); + + return InvalidObjectAddress; } } diff --git a/src/test/regress/expected/inherit.out b/src/test/regress/expected/inherit.out index 0f1aa831f6..8626ce4a05 100644 --- a/src/test/regress/expected/inherit.out +++ b/src/test/regress/expected/inherit.out @@ -1088,6 +1088,23 @@ Inherits: inht1, inhs1 DROP TABLE inhts; +-- Test for adding a column to a parent table with complex inheritance +CREATE TABLE inhta (); +CREATE TABLE inhtb () INHERITS (inhta); +CREATE TABLE inhtc () INHERITS (inhtb); +CREATE TABLE inhtd () INHERITS (inhta,inhtb,inhtc); +ALTER TABLE inhta ADD COLUMN i int; +NOTICE: merging definition of column "i" for child "inhtd" +NOTICE: merging definition of column "i" for child "inhtd" +\d+ inhta + Table "public.inhta" + Column | Type | Collation | Nullable | Default | Storage | Stats target | Description +--------+---------+-----------+----------+---------+---------+--------------+------------- + i | integer | | | | plain | | +Child tables: inhtb, + inhtd + +DROP TABLE inhta, inhtb, inhtc, inhtd; -- Test for renaming in diamond inheritance CREATE TABLE inht2 (x int) INHERITS (inht1); CREATE TABLE inht3 (y int) INHERITS (inht1); diff --git a/src/test/regress/sql/inherit.sql b/src/test/regress/sql/inherit.sql index f7b4062ce5..8e537f7da3 100644 --- a/src/test/regress/sql/inherit.sql +++ b/src/test/regress/sql/inherit.sql @@ -372,6 +372,17 @@ ALTER TABLE inhts RENAME d TO dd; DROP TABLE inhts; +-- Test for adding a column to a parent table with complex inheritance +CREATE TABLE inhta (); +CREATE TABLE inhtb () INHERITS (inhta); +CREATE TABLE inhtc () INHERITS (inhtb); +CREATE TABLE inhtd () INHERITS (inhta,inhtb,inhtc); + +ALTER TABLE inhta ADD COLUMN i int; +\d+ inhta + +DROP TABLE inhta, inhtb, inhtc, inhtd; + -- Test for renaming in diamond inheritance CREATE TABLE inht2 (x int) INHERITS (inht1); CREATE TABLE inht3 (y int) INHERITS (inht1); -- 2.25.1