Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbfec14d

Browse files
committed
Fix ALTER TABLE .. ADD COLUMN with complex inheritance trees
This command, when used to add a column on a parent table with a complexinheritance tree, tried to update multiple times the same tuple inpg_attribute for a child table when incrementing attinhcount, causingfailures with "tuple already updated by self" because of a missingCommandCounterIncrement() between two updates.This exists for a rather long time, so backpatch all the way down.Reported-by: Alexander LakhinAuthor: Tender WangReviewed-by: Richard GuoDiscussion:https://postgr.es/m/18297-b04cd83a55b51e35@postgresql.orgBackpatch-through: 12
1 parentdc9d424 commitbfec14d

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6291,6 +6291,10 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
62916291
colDef->colname, RelationGetRelationName(rel))));
62926292

62936293
table_close(attrdesc, RowExclusiveLock);
6294+
6295+
/* Make the child column change visible */
6296+
CommandCounterIncrement();
6297+
62946298
return InvalidObjectAddress;
62956299
}
62966300
}

‎src/test/regress/expected/inherit.out

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,23 @@ Inherits: inht1,
10631063
inhs1
10641064

10651065
DROP TABLE inhts;
1066+
-- Test for adding a column to a parent table with complex inheritance
1067+
CREATE TABLE inhta ();
1068+
CREATE TABLE inhtb () INHERITS (inhta);
1069+
CREATE TABLE inhtc () INHERITS (inhtb);
1070+
CREATE TABLE inhtd () INHERITS (inhta, inhtb, inhtc);
1071+
ALTER TABLE inhta ADD COLUMN i int;
1072+
NOTICE: merging definition of column "i" for child "inhtd"
1073+
NOTICE: merging definition of column "i" for child "inhtd"
1074+
\d+ inhta
1075+
Table "public.inhta"
1076+
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
1077+
--------+---------+-----------+----------+---------+---------+--------------+-------------
1078+
i | integer | | | | plain | |
1079+
Child tables: inhtb,
1080+
inhtd
1081+
1082+
DROP TABLE inhta, inhtb, inhtc, inhtd;
10661083
-- Test for renaming in diamond inheritance
10671084
CREATE TABLE inht2 (x int) INHERITS (inht1);
10681085
CREATE TABLE inht3 (y int) INHERITS (inht1);

‎src/test/regress/sql/inherit.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,15 @@ ALTER TABLE inhts RENAME d TO dd;
353353

354354
DROPTABLE inhts;
355355

356+
-- Test for adding a column to a parent table with complex inheritance
357+
CREATETABLEinhta ();
358+
CREATETABLEinhtb () INHERITS (inhta);
359+
CREATETABLEinhtc () INHERITS (inhtb);
360+
CREATETABLEinhtd () INHERITS (inhta, inhtb, inhtc);
361+
ALTERTABLE inhta ADD COLUMN iint;
362+
\d+ inhta
363+
DROPTABLE inhta, inhtb, inhtc, inhtd;
364+
356365
-- Test for renaming in diamond inheritance
357366
CREATETABLEinht2 (xint) INHERITS (inht1);
358367
CREATETABLEinht3 (yint) INHERITS (inht1);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp