Skip to content

Commit bd17896

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 b057512 commit bd17896

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
@@ -7533,6 +7533,8 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
75337533
if (!missingIsNull)
75347534
{
75357535
StoreAttrMissingVal(rel, attribute->attnum, missingval);
7536+
/* Make the additional catalog change visible */
7537+
CommandCounterIncrement();
75367538
has_missing = true;
75377539
}
75387540
FreeExecutorState(estate);

src/test/regress/expected/inherit.out

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,17 +1096,30 @@ CREATE TABLE inhta ();
10961096
CREATE TABLE inhtb () INHERITS (inhta);
10971097
CREATE TABLE inhtc () INHERITS (inhtb);
10981098
CREATE TABLE inhtd () INHERITS (inhta, inhtb, inhtc);
1099-
ALTER TABLE inhta ADD COLUMN i int;
1099+
ALTER TABLE inhta ADD COLUMN i int, ADD COLUMN j bigint DEFAULT 1;
11001100
NOTICE: merging definition of column "i" for child "inhtd"
11011101
NOTICE: merging definition of column "i" for child "inhtd"
1102+
NOTICE: merging definition of column "j" for child "inhtd"
1103+
NOTICE: merging definition of column "j" for child "inhtd"
11021104
\d+ inhta
11031105
Table "public.inhta"
11041106
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
11051107
--------+---------+-----------+----------+---------+---------+--------------+-------------
11061108
i | integer | | | | plain | |
1109+
j | bigint | | | 1 | plain | |
11071110
Child tables: inhtb,
11081111
inhtd
11091112

1113+
\d+ inhtd
1114+
Table "public.inhtd"
1115+
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
1116+
--------+---------+-----------+----------+---------+---------+--------------+-------------
1117+
i | integer | | | | plain | |
1118+
j | bigint | | | 1 | plain | |
1119+
Inherits: inhta,
1120+
inhtb,
1121+
inhtc
1122+
11101123
DROP TABLE inhta, inhtb, inhtc, inhtd;
11111124
-- Test for renaming in diamond inheritance
11121125
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
@@ -380,8 +380,9 @@ CREATE TABLE inhta ();
380380
CREATE TABLE inhtb () INHERITS (inhta);
381381
CREATE TABLE inhtc () INHERITS (inhtb);
382382
CREATE TABLE inhtd () INHERITS (inhta, inhtb, inhtc);
383-
ALTER TABLE inhta ADD COLUMN i int;
383+
ALTER TABLE inhta ADD COLUMN i int, ADD COLUMN j bigint DEFAULT 1;
384384
\d+ inhta
385+
\d+ inhtd
385386
DROP TABLE inhta, inhtb, inhtc, inhtd;
386387

387388
-- Test for renaming in diamond inheritance

0 commit comments

Comments
 (0)