Skip to content

Commit 538ecfa

Browse files
committed
Mark index-constraint comments with correct dependency in pg_dump.
When there's a comment on an index that was created with UNIQUE or PRIMARY KEY constraint syntax, we need to label the comment as depending on the constraint not the index, since only the constraint object actually appears in the dump. This incorrect dependency can lead to parallel pg_restore trying to restore the comment before the index has been created, per bug #8257 from Lloyd Albin. This patch fixes pg_dump to produce the right dependency in dumps made in the future. Usually we also try to hack pg_restore to work around bogus dependencies, so that existing (wrong) dumps can still be restored in parallel mode; but that doesn't seem practical here since there's no easy way to relate the constraint dump entry to the comment after the fact. Andres Freund
1 parent 2beeabc commit 538ecfa

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12942,6 +12942,7 @@ static void
1294212942
dumpIndex(Archive *fout, IndxInfo *indxinfo)
1294312943
{
1294412944
TableInfo *tbinfo = indxinfo->indextable;
12945+
bool is_constraint = (indxinfo->indexconstraint != 0);
1294512946
PQExpBuffer q;
1294612947
PQExpBuffer delq;
1294712948
PQExpBuffer labelq;
@@ -12959,9 +12960,11 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo)
1295912960
/*
1296012961
* If there's an associated constraint, don't dump the index per se, but
1296112962
* do dump any comment for it. (This is safe because dependency ordering
12962-
* will have ensured the constraint is emitted first.)
12963+
* will have ensured the constraint is emitted first.) Note that the
12964+
* emitted comment has to be shown as depending on the constraint, not
12965+
* the index, in such cases.
1296312966
*/
12964-
if (indxinfo->indexconstraint == 0)
12967+
if (!is_constraint)
1296512968
{
1296612969
if (binary_upgrade)
1296712970
binary_upgrade_set_pg_class_oids(fout, q,
@@ -13003,7 +13006,9 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo)
1300313006
dumpComment(fout, labelq->data,
1300413007
tbinfo->dobj.namespace->dobj.name,
1300513008
tbinfo->rolname,
13006-
indxinfo->dobj.catId, 0, indxinfo->dobj.dumpId);
13009+
indxinfo->dobj.catId, 0,
13010+
is_constraint ? indxinfo->indexconstraint :
13011+
indxinfo->dobj.dumpId);
1300713012

1300813013
destroyPQExpBuffer(q);
1300913014
destroyPQExpBuffer(delq);

0 commit comments

Comments
 (0)