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

Commitbb812ab

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 parentbcd5b4b commitbb812ab

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
@@ -7077,6 +7077,10 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
70777077
colDef->colname, RelationGetRelationName(rel))));
70787078

70797079
table_close(attrdesc, RowExclusiveLock);
7080+
7081+
/* Make the child column change visible */
7082+
CommandCounterIncrement();
7083+
70807084
return InvalidObjectAddress;
70817085
}
70827086
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,23 @@ Inherits: inht1,
10881088
inhs1
10891089

10901090
DROP TABLE inhts;
1091+
-- Test for adding a column to a parent table with complex inheritance
1092+
CREATE TABLE inhta ();
1093+
CREATE TABLE inhtb () INHERITS (inhta);
1094+
CREATE TABLE inhtc () INHERITS (inhtb);
1095+
CREATE TABLE inhtd () INHERITS (inhta, inhtb, inhtc);
1096+
ALTER TABLE inhta ADD COLUMN i int;
1097+
NOTICE: merging definition of column "i" for child "inhtd"
1098+
NOTICE: merging definition of column "i" for child "inhtd"
1099+
\d+ inhta
1100+
Table "public.inhta"
1101+
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
1102+
--------+---------+-----------+----------+---------+---------+--------------+-------------
1103+
i | integer | | | | plain | |
1104+
Child tables: inhtb,
1105+
inhtd
1106+
1107+
DROP TABLE inhta, inhtb, inhtc, inhtd;
10911108
-- Test for renaming in diamond inheritance
10921109
CREATE TABLE inht2 (x int) INHERITS (inht1);
10931110
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
@@ -372,6 +372,15 @@ ALTER TABLE inhts RENAME d TO dd;
372372

373373
DROPTABLE inhts;
374374

375+
-- Test for adding a column to a parent table with complex inheritance
376+
CREATETABLEinhta ();
377+
CREATETABLEinhtb () INHERITS (inhta);
378+
CREATETABLEinhtc () INHERITS (inhtb);
379+
CREATETABLEinhtd () INHERITS (inhta, inhtb, inhtc);
380+
ALTERTABLE inhta ADD COLUMN iint;
381+
\d+ inhta
382+
DROPTABLE inhta, inhtb, inhtc, inhtd;
383+
375384
-- Test for renaming in diamond inheritance
376385
CREATETABLEinht2 (xint) INHERITS (inht1);
377386
CREATETABLEinht3 (yint) INHERITS (inht1);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp