diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 2ce0cd8..107cabb 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -13493,6 +13493,7 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo)
 	PQExpBuffer q;
 	PQExpBuffer delq;
 	PQExpBuffer labelq;
+	bool is_constraint = indxinfo->indexconstraint != 0;
 
 	if (dataOnly)
 		return;
@@ -13509,7 +13510,7 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo)
 	 * do dump any comment for it.	(This is safe because dependency ordering
 	 * will have ensured the constraint is emitted first.)
 	 */
-	if (indxinfo->indexconstraint == 0)
+	if (!is_constraint)
 	{
 		if (binary_upgrade)
 			binary_upgrade_set_pg_class_oids(fout, q,
@@ -13547,11 +13548,15 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo)
 					 NULL, NULL);
 	}
 
-	/* Dump Index Comments */
+	/*
+	 * Dump Index Comments - depend on the constraint instead of the index if
+	 * present to ensure sensible ordering.
+	 */
 	dumpComment(fout, labelq->data,
 				tbinfo->dobj.namespace->dobj.name,
 				tbinfo->rolname,
-				indxinfo->dobj.catId, 0, indxinfo->dobj.dumpId);
+				indxinfo->dobj.catId, 0,
+		    is_constraint ? indxinfo->indexconstraint : indxinfo->dobj.dumpId);
 
 	destroyPQExpBuffer(q);
 	destroyPQExpBuffer(delq);
