Skip to content

Commit 76ce043

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 a5380bd commit 76ce043

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
@@ -11180,6 +11180,7 @@ static void
1118011180
dumpIndex(Archive *fout, IndxInfo *indxinfo)
1118111181
{
1118211182
TableInfo *tbinfo = indxinfo->indextable;
11183+
bool is_constraint = (indxinfo->indexconstraint != 0);
1118311184
PQExpBuffer q;
1118411185
PQExpBuffer delq;
1118511186

@@ -11192,9 +11193,11 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo)
1119211193
/*
1119311194
* If there's an associated constraint, don't dump the index per se, but
1119411195
* do dump any comment for it. (This is safe because dependency ordering
11195-
* will have ensured the constraint is emitted first.)
11196+
* will have ensured the constraint is emitted first.) Note that the
11197+
* emitted comment has to be shown as depending on the constraint, not
11198+
* the index, in such cases.
1119611199
*/
11197-
if (indxinfo->indexconstraint == 0)
11200+
if (!is_constraint)
1119811201
{
1119911202
if (binary_upgrade)
1120011203
binary_upgrade_set_relfilenodes(q, indxinfo->dobj.catId.oid, true);
@@ -11238,7 +11241,9 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo)
1123811241
dumpComment(fout, q->data,
1123911242
tbinfo->dobj.namespace->dobj.name,
1124011243
tbinfo->rolname,
11241-
indxinfo->dobj.catId, 0, indxinfo->dobj.dumpId);
11244+
indxinfo->dobj.catId, 0,
11245+
is_constraint ? indxinfo->indexconstraint :
11246+
indxinfo->dobj.dumpId);
1124211247

1124311248
destroyPQExpBuffer(q);
1124411249
destroyPQExpBuffer(delq);

0 commit comments

Comments
 (0)