Skip to content

Commit 17abf27

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 158e319 commit 17abf27

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
@@ -10352,6 +10352,7 @@ static void
1035210352
dumpIndex(Archive *fout, IndxInfo *indxinfo)
1035310353
{
1035410354
TableInfo *tbinfo = indxinfo->indextable;
10355+
bool is_constraint = (indxinfo->indexconstraint != 0);
1035510356
PQExpBuffer q;
1035610357
PQExpBuffer delq;
1035710358

@@ -10364,9 +10365,11 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo)
1036410365
/*
1036510366
* If there's an associated constraint, don't dump the index per se, but
1036610367
* do dump any comment for it. (This is safe because dependency ordering
10367-
* will have ensured the constraint is emitted first.)
10368+
* will have ensured the constraint is emitted first.) Note that the
10369+
* emitted comment has to be shown as depending on the constraint, not
10370+
* the index, in such cases.
1036810371
*/
10369-
if (indxinfo->indexconstraint == 0)
10372+
if (!is_constraint)
1037010373
{
1037110374
/* Plain secondary index */
1037210375
appendPQExpBuffer(q, "%s;\n", indxinfo->indexdef);
@@ -10407,7 +10410,9 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo)
1040710410
dumpComment(fout, q->data,
1040810411
tbinfo->dobj.namespace->dobj.name,
1040910412
tbinfo->rolname,
10410-
indxinfo->dobj.catId, 0, indxinfo->dobj.dumpId);
10413+
indxinfo->dobj.catId, 0,
10414+
is_constraint ? indxinfo->indexconstraint :
10415+
indxinfo->dobj.dumpId);
1041110416

1041210417
destroyPQExpBuffer(q);
1041310418
destroyPQExpBuffer(delq);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy