v7-0001-Fix-fpi_len-issue-introduced-by-0276ae42dd-in-pg_.patch

application/x-patch

Filename: v7-0001-Fix-fpi_len-issue-introduced-by-0276ae42dd-in-pg_.patch
Type: application/x-patch
Part: 0
Message: Re: Add pg_walinspect function with block info columns

Patch

Format: format-patch
Series: patch v7-0001
Subject: Fix fpi_len issue introduced by 0276ae42dd in pg_walinspect
File+
contrib/pg_walinspect/pg_walinspect.c 7 8
From f2fba90775ef2fee6ea6f04dff3a08c2ed7724f1 Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Date: Tue, 28 Mar 2023 01:46:08 +0000
Subject: [PATCH v7] Fix fpi_len issue introduced by 0276ae42dd in
 pg_walinspect

0276ae42dd changed the code to emit block references only if
exists. That change moved the block references calucation code
around which left fpi_len to be emitted as always 0. This commit
fixes that issue.
---
 contrib/pg_walinspect/pg_walinspect.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/contrib/pg_walinspect/pg_walinspect.c b/contrib/pg_walinspect/pg_walinspect.c
index 2933734122..062e90dbce 100644
--- a/contrib/pg_walinspect/pg_walinspect.c
+++ b/contrib/pg_walinspect/pg_walinspect.c
@@ -186,6 +186,7 @@ GetWALRecordInfo(XLogReaderState *record, Datum *values,
 	RmgrData	desc;
 	uint32		fpi_len = 0;
 	StringInfoData rec_desc;
+	StringInfoData rec_blk_ref;
 	int			i = 0;
 
 	desc = GetRmgr(XLogRecGetRmid(record));
@@ -197,6 +198,12 @@ GetWALRecordInfo(XLogReaderState *record, Datum *values,
 	initStringInfo(&rec_desc);
 	desc.rm_desc(&rec_desc, record);
 
+	if (XLogRecHasAnyBlockRefs(record))
+	{
+		initStringInfo(&rec_blk_ref);
+		XLogRecGetBlockRefInfo(record, false, true, &rec_blk_ref, &fpi_len);
+	}
+
 	values[i++] = LSNGetDatum(record->ReadRecPtr);
 	values[i++] = LSNGetDatum(record->EndRecPtr);
 	values[i++] = LSNGetDatum(XLogRecGetPrev(record));
@@ -205,7 +212,6 @@ GetWALRecordInfo(XLogReaderState *record, Datum *values,
 	values[i++] = CStringGetTextDatum(id);
 	values[i++] = UInt32GetDatum(XLogRecGetTotalLen(record));
 	values[i++] = UInt32GetDatum(XLogRecGetDataLen(record));
-
 	values[i++] = UInt32GetDatum(fpi_len);
 
 	if (rec_desc.len > 0)
@@ -213,15 +219,8 @@ GetWALRecordInfo(XLogReaderState *record, Datum *values,
 	else
 		nulls[i++] = true;
 
-	/* Block references. */
 	if (XLogRecHasAnyBlockRefs(record))
-	{
-		StringInfoData rec_blk_ref;
-
-		initStringInfo(&rec_blk_ref);
-		XLogRecGetBlockRefInfo(record, false, true, &rec_blk_ref, &fpi_len);
 		values[i++] = CStringGetTextDatum(rec_blk_ref.data);
-	}
 	else
 		nulls[i++] = true;
 
-- 
2.34.1