diff --git a/src/backend/replication/logical/relation.c b/src/backend/replication/logical/relation.c
index 22b20885b5a..e960278b33b 100644
--- a/src/backend/replication/logical/relation.c
+++ b/src/backend/replication/logical/relation.c
@@ -791,6 +791,14 @@ FindUsableIndexForReplicaIdentityFull(Relation localrel, AttrMap *attrmap)
 		Relation	idxRel;
 
 		idxRel = index_open(idxoid, AccessShareLock);
+
+		/*
+		 * indisvalid is checked here, not in IsIndexUsableForReplicaIdentityFull(),
+		 * since that function's other caller (an assertion) must tolerate
+		 * an index made transiently invalid by a concurrent DROP INDEX
+		 * CONCURRENTLY, whereas a permanently invalid leftover of a failed
+		 * CREATE INDEX CONCURRENTLY must never be chosen here.
+		 */
 		isUsableIdx = idxRel->rd_index->indisvalid &&
 			IsIndexUsableForReplicaIdentityFull(idxRel, attrmap);
 		index_close(idxRel, AccessShareLock);
diff --git a/src/test/subscription/t/032_subscribe_use_index.pl b/src/test/subscription/t/032_subscribe_use_index.pl
index 33a2bdceb5c..1ccd36ac227 100644
--- a/src/test/subscription/t/032_subscribe_use_index.pl
+++ b/src/test/subscription/t/032_subscribe_use_index.pl
@@ -480,10 +480,11 @@ $node_subscriber->safe_psql('postgres', "DROP TABLE test_replica_id_full");
 
 # =============================================================================
 # Testcase start: Subscription does not use an invalid index
-
+#
 # A failed CREATE INDEX CONCURRENTLY leaves behind a live but invalid
 # index, which is not required to contain every row.  The apply worker
 # must not choose it for REPLICA IDENTITY FULL lookups.
+#
 
 # create tables pub and sub
 $node_publisher->safe_psql('postgres',
