Skip to content

Commit dd34cbf

Browse files
committed
Need to do CommandCounterIncrement after StoreAttrMissingVal.
Without this, an additional change to the same pg_attribute row within the same command will fail. This is possible at least with ALTER TABLE ADD COLUMN on a multiple-inheritance-pathway structure. (Another potential hazard is that immediately-following operations might not see the missingval.) Introduced by 95f6506, which split the former coding that used a single pg_attribute update to change both atthasdef and atthasmissing/attmissingval into two updates, but missed that this should entail two CommandCounterIncrements as well. Like that fix, back-patch through v13. Reported-by: Alexander Lakhin <exclusion@gmail.com> Author: Tender Wang <tndrwang@gmail.com> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/025a3ffa-5eff-4a88-97fb-8f583b015965@gmail.com Backpatch-through: 13
1 parent ebbdaf1 commit dd34cbf

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/backend/commands/tablecmds.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6715,6 +6715,8 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
67156715
if (!missingIsNull)
67166716
{
67176717
StoreAttrMissingVal(rel, attribute.attnum, missingval);
6718+
/* Make the additional catalog change visible */
6719+
CommandCounterIncrement();
67186720
has_missing = true;
67196721
}
67206722
FreeExecutorState(estate);

src/test/regress/expected/inherit.out

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,17 +1068,30 @@ CREATE TABLE inhta ();
10681068
CREATE TABLE inhtb () INHERITS (inhta);
10691069
CREATE TABLE inhtc () INHERITS (inhtb);
10701070
CREATE TABLE inhtd () INHERITS (inhta, inhtb, inhtc);
1071-
ALTER TABLE inhta ADD COLUMN i int;
1071+
ALTER TABLE inhta ADD COLUMN i int, ADD COLUMN j bigint DEFAULT 1;
10721072
NOTICE: merging definition of column "i" for child "inhtd"
10731073
NOTICE: merging definition of column "i" for child "inhtd"
1074+
NOTICE: merging definition of column "j" for child "inhtd"
1075+
NOTICE: merging definition of column "j" for child "inhtd"
10741076
\d+ inhta
10751077
Table "public.inhta"
10761078
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
10771079
--------+---------+-----------+----------+---------+---------+--------------+-------------
10781080
i | integer | | | | plain | |
1081+
j | bigint | | | 1 | plain | |
10791082
Child tables: inhtb,
10801083
inhtd
10811084

1085+
\d+ inhtd
1086+
Table "public.inhtd"
1087+
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
1088+
--------+---------+-----------+----------+---------+---------+--------------+-------------
1089+
i | integer | | | | plain | |
1090+
j | bigint | | | 1 | plain | |
1091+
Inherits: inhta,
1092+
inhtb,
1093+
inhtc
1094+
10821095
DROP TABLE inhta, inhtb, inhtc, inhtd;
10831096
-- Test for renaming in diamond inheritance
10841097
CREATE TABLE inht2 (x int) INHERITS (inht1);

src/test/regress/sql/inherit.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,9 @@ CREATE TABLE inhta ();
358358
CREATE TABLE inhtb () INHERITS (inhta);
359359
CREATE TABLE inhtc () INHERITS (inhtb);
360360
CREATE TABLE inhtd () INHERITS (inhta, inhtb, inhtc);
361-
ALTER TABLE inhta ADD COLUMN i int;
361+
ALTER TABLE inhta ADD COLUMN i int, ADD COLUMN j bigint DEFAULT 1;
362362
\d+ inhta
363+
\d+ inhtd
363364
DROP TABLE inhta, inhtb, inhtc, inhtd;
364365

365366
-- Test for renaming in diamond inheritance

0 commit comments

Comments
 (0)