From 0582d92ba4df517f3e67717751cddb8916c8ab9f Mon Sep 17 00:00:00 2001
From: Japin Li <japinli@hotmail.com>
Date: Tue, 22 Jun 2021 09:59:38 +0800
Subject: [PATCH v1] Minor code beautification for RelationGetIdentityKeyBitmap

---
 src/backend/utils/cache/relcache.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index d55ae016d0..94fbf1aa19 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -5244,9 +5244,9 @@ Bitmapset *
 RelationGetIdentityKeyBitmap(Relation relation)
 {
 	Bitmapset  *idindexattrs = NULL;	/* columns in the replica identity */
-	List	   *indexoidlist;
 	Relation	indexDesc;
 	int			i;
+	Oid			replidindex;
 	MemoryContext oldcxt;
 
 	/* Quick exit if we already computed the result */
@@ -5260,18 +5260,14 @@ RelationGetIdentityKeyBitmap(Relation relation)
 	/* Historic snapshot must be set. */
 	Assert(HistoricSnapshotActive());
 
-	indexoidlist = RelationGetIndexList(relation);
-
-	/* Fall out if no indexes (but relhasindex was set) */
-	if (indexoidlist == NIL)
-		return NULL;
+	replidindex = RelationGetReplicaIndex(relation);
 
 	/* Fall out if there is no replica identity index */
-	if (!OidIsValid(relation->rd_replidindex))
+	if (!OidIsValid(replidindex))
 		return NULL;
 
 	/* Look up the description for the replica identity index */
-	indexDesc = RelationIdGetRelation(relation->rd_replidindex);
+	indexDesc = RelationIdGetRelation(replidindex);
 
 	if (!RelationIsValid(indexDesc))
 		elog(ERROR, "could not open relation with OID %u",
@@ -5295,7 +5291,6 @@ RelationGetIdentityKeyBitmap(Relation relation)
 	}
 
 	RelationClose(indexDesc);
-	list_free(indexoidlist);
 
 	/* Don't leak the old values of these bitmaps, if any */
 	bms_free(relation->rd_idattr);
-- 
2.30.2

