From fcb74fd20cd5549f2f69770140f194e0e25c4362 Mon Sep 17 00:00:00 2001
From: "houzj.fnst" <houzj.fnst@fujitsu.com>
Date: Wed, 22 Dec 2021 14:57:32 +0800
Subject: [PATCH] Delay the variable initialization in get_rel_sync_entry

Delay the variable initialization in get_rel_sync_entry which will cause
unnecessary cache access in a hot function.
---
 src/backend/replication/pgoutput/pgoutput.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c
index 6f6a203..a08da85 100644
--- a/src/backend/replication/pgoutput/pgoutput.c
+++ b/src/backend/replication/pgoutput/pgoutput.c
@@ -1119,8 +1119,6 @@ static RelationSyncEntry *
 get_rel_sync_entry(PGOutputData *data, Oid relid)
 {
 	RelationSyncEntry *entry;
-	bool		am_partition = get_rel_relispartition(relid);
-	char		relkind = get_rel_relkind(relid);
 	bool		found;
 	MemoryContext oldctx;
 
@@ -1160,6 +1158,8 @@ get_rel_sync_entry(PGOutputData *data, Oid relid)
 		List	   *schemaPubids = GetSchemaPublications(schemaId);
 		ListCell   *lc;
 		Oid			publish_as_relid = relid;
+		bool		am_partition = get_rel_relispartition(relid);
+		char		relkind = get_rel_relkind(relid);
 
 		/* Reload publications if needed before use. */
 		if (!publications_valid)
-- 
2.7.2.windows.1

