Skip to content

Commit 0941aad

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 b19893b commit 0941aad

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
@@ -7345,6 +7345,8 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
73457345
if (!missingIsNull)
73467346
{
73477347
StoreAttrMissingVal(rel, attribute->attnum, missingval);
7348+
/* Make the additional catalog change visible */
7349+
CommandCounterIncrement();
73487350
has_missing = true;
73497351
}
73507352
FreeExecutorState(estate);

src/test/regress/expected/inherit.out

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,17 +1093,30 @@ CREATE TABLE inhta ();
10931093
CREATE TABLE inhtb () INHERITS (inhta);
10941094
CREATE TABLE inhtc () INHERITS (inhtb);
10951095
CREATE TABLE inhtd () INHERITS (inhta, inhtb, inhtc);
1096-
ALTER TABLE inhta ADD COLUMN i int;
1096+
ALTER TABLE inhta ADD COLUMN i int, ADD COLUMN j bigint DEFAULT 1;
10971097
NOTICE: merging definition of column "i" for child "inhtd"
10981098
NOTICE: merging definition of column "i" for child "inhtd"
1099+
NOTICE: merging definition of column "j" for child "inhtd"
1100+
NOTICE: merging definition of column "j" for child "inhtd"
10991101
\d+ inhta
11001102
Table "public.inhta"
11011103
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
11021104
--------+---------+-----------+----------+---------+---------+--------------+-------------
11031105
i | integer | | | | plain | |
1106+
j | bigint | | | 1 | plain | |
11041107
Child tables: inhtb,
11051108
inhtd
11061109

1110+
\d+ inhtd
1111+
Table "public.inhtd"
1112+
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
1113+
--------+---------+-----------+----------+---------+---------+--------------+-------------
1114+
i | integer | | | | plain | |
1115+
j | bigint | | | 1 | plain | |
1116+
Inherits: inhta,
1117+
inhtb,
1118+
inhtc
1119+
11071120
DROP TABLE inhta, inhtb, inhtc, inhtd;
11081121
-- Test for renaming in diamond inheritance
11091122
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
@@ -377,8 +377,9 @@ CREATE TABLE inhta ();
377377
CREATE TABLE inhtb () INHERITS (inhta);
378378
CREATE TABLE inhtc () INHERITS (inhtb);
379379
CREATE TABLE inhtd () INHERITS (inhta, inhtb, inhtc);
380-
ALTER TABLE inhta ADD COLUMN i int;
380+
ALTER TABLE inhta ADD COLUMN i int, ADD COLUMN j bigint DEFAULT 1;
381381
\d+ inhta
382+
\d+ inhtd
382383
DROP TABLE inhta, inhtb, inhtc, inhtd;
383384

384385
-- Test for renaming in diamond inheritance

0 commit comments

Comments
 (0)