Skip to content

Commit 50e66d3

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 c204aba commit 50e66d3

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
@@ -12773,6 +12773,7 @@ static void
1277312773
dumpIndex(Archive *fout, IndxInfo *indxinfo)
1277412774
{
1277512775
TableInfo *tbinfo = indxinfo->indextable;
12776+
bool is_constraint = (indxinfo->indexconstraint != 0);
1277612777
PQExpBuffer q;
1277712778
PQExpBuffer delq;
1277812779
PQExpBuffer labelq;
@@ -12790,9 +12791,11 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo)
1279012791
/*
1279112792
* If there's an associated constraint, don't dump the index per se, but
1279212793
* do dump any comment for it. (This is safe because dependency ordering
12793-
* will have ensured the constraint is emitted first.)
12794+
* will have ensured the constraint is emitted first.) Note that the
12795+
* emitted comment has to be shown as depending on the constraint, not
12796+
* the index, in such cases.
1279412797
*/
12795-
if (indxinfo->indexconstraint == 0)
12798+
if (!is_constraint)
1279612799
{
1279712800
if (binary_upgrade)
1279812801
binary_upgrade_set_pg_class_oids(q, indxinfo->dobj.catId.oid, true);
@@ -12833,7 +12836,9 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo)
1283312836
dumpComment(fout, labelq->data,
1283412837
tbinfo->dobj.namespace->dobj.name,
1283512838
tbinfo->rolname,
12836-
indxinfo->dobj.catId, 0, indxinfo->dobj.dumpId);
12839+
indxinfo->dobj.catId, 0,
12840+
is_constraint ? indxinfo->indexconstraint :
12841+
indxinfo->dobj.dumpId);
1283712842

1283812843
destroyPQExpBuffer(q);
1283912844
destroyPQExpBuffer(delq);

0 commit comments

Comments
 (0)