From 7b24fd5139507a80d0edba994abe0a80ae1ac243 Mon Sep 17 00:00:00 2001
From: John Naylor <john.naylor@postgresql.org>
Date: Sun, 5 Oct 2025 14:17:44 +0700
Subject: [PATCH v1 3/4] Get rid of XLOG_HEAP_OPMASK

---
 src/backend/access/heap/heapam_xlog.c    |  8 ++++----
 src/backend/access/rmgrdesc/heapdesc.c   |  6 ++----
 src/backend/replication/logical/decode.c |  4 ++--
 src/include/access/heapam_xlog.h         | 11 +++++------
 4 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/src/backend/access/heap/heapam_xlog.c b/src/backend/access/heap/heapam_xlog.c
index cf843277938..e6cd0955818 100644
--- a/src/backend/access/heap/heapam_xlog.c
+++ b/src/backend/access/heap/heapam_xlog.c
@@ -1179,14 +1179,14 @@ heap_xlog_inplace(XLogReaderState *record)
 void
 heap_redo(XLogReaderState *record)
 {
-	uint8		info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
+	uint8		info = XLogRecGetRecType(record);
 
 	/*
 	 * These operations don't overwrite MVCC data so no conflict processing is
 	 * required. The ones in heap2 rmgr do.
 	 */
 
-	switch (info & XLOG_HEAP_OPMASK)
+	switch (info)
 	{
 		case XLOG_HEAP_INSERT:
 			heap_xlog_insert(record);
@@ -1225,9 +1225,9 @@ heap_redo(XLogReaderState *record)
 void
 heap2_redo(XLogReaderState *record)
 {
-	uint8		info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
+	uint8		info = XLogRecGetRecType(record);
 
-	switch (info & XLOG_HEAP_OPMASK)
+	switch (info)
 	{
 		case XLOG_HEAP2_PRUNE_ON_ACCESS:
 		case XLOG_HEAP2_PRUNE_VACUUM_SCAN:
diff --git a/src/backend/access/rmgrdesc/heapdesc.c b/src/backend/access/rmgrdesc/heapdesc.c
index 82b62c95de5..dd5ae6b295b 100644
--- a/src/backend/access/rmgrdesc/heapdesc.c
+++ b/src/backend/access/rmgrdesc/heapdesc.c
@@ -184,9 +184,8 @@ void
 heap_desc(StringInfo buf, XLogReaderState *record)
 {
 	char	   *rec = XLogRecGetData(record);
-	uint8		info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
+	uint8		info = XLogRecGetRecType(record);
 
-	info &= XLOG_HEAP_OPMASK;
 	if (info == XLOG_HEAP_INSERT)
 	{
 		xl_heap_insert *xlrec = (xl_heap_insert *) rec;
@@ -264,9 +263,8 @@ void
 heap2_desc(StringInfo buf, XLogReaderState *record)
 {
 	char	   *rec = XLogRecGetData(record);
-	uint8		info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
+	uint8		info = XLogRecGetRecType(record);
 
-	info &= XLOG_HEAP_OPMASK;
 	if (info == XLOG_HEAP2_PRUNE_ON_ACCESS ||
 		info == XLOG_HEAP2_PRUNE_VACUUM_SCAN ||
 		info == XLOG_HEAP2_PRUNE_VACUUM_CLEANUP)
diff --git a/src/backend/replication/logical/decode.c b/src/backend/replication/logical/decode.c
index af7465e1bbf..cf298a215ee 100644
--- a/src/backend/replication/logical/decode.c
+++ b/src/backend/replication/logical/decode.c
@@ -404,7 +404,7 @@ standby_decode(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
 void
 heap2_decode(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
 {
-	uint8		info = XLogRecGetInfo(buf->record) & XLOG_HEAP_OPMASK;
+	uint8		info = XLogRecGetRecType(buf->record);
 	TransactionId xid = XLogRecGetXid(buf->record);
 	SnapBuild  *builder = ctx->snapshot_builder;
 
@@ -468,7 +468,7 @@ heap2_decode(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
 void
 heap_decode(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
 {
-	uint8		info = XLogRecGetInfo(buf->record) & XLOG_HEAP_OPMASK;
+	uint8		info = XLogRecGetRecType(buf->record);
 	TransactionId xid = XLogRecGetXid(buf->record);
 	SnapBuild  *builder = ctx->snapshot_builder;
 
diff --git a/src/include/access/heapam_xlog.h b/src/include/access/heapam_xlog.h
index d4c0625b632..6ebfdb32369 100644
--- a/src/include/access/heapam_xlog.h
+++ b/src/include/access/heapam_xlog.h
@@ -27,8 +27,9 @@
 /*
  * WAL record definitions for heapam.c's WAL operations
  *
- * XLOG allows to store some information in high 4 bits of log
- * record xl_info field.  We use 3 for opcode and one for init bit.
+ * XLOG allows to store record type in high 4 bits of log record xl_info
+ * field and the lower 4 bits for optional flags. We use the high bits
+ * for the opcode and the lower for the init bit.
  */
 #define XLOG_HEAP_INSERT		0x00
 #define XLOG_HEAP_DELETE		0x10
@@ -39,17 +40,15 @@
 #define XLOG_HEAP_LOCK			0x60
 #define XLOG_HEAP_INPLACE		0x70
 
-#define XLOG_HEAP_OPMASK		0x70
 /*
  * When we insert 1st item on new page in INSERT, UPDATE, HOT_UPDATE,
  * or MULTI_INSERT, we can (and we do) restore entire page in redo
  */
-#define XLOG_HEAP_INIT_PAGE		0x80
+#define XLOG_HEAP_INIT_PAGE		0x01
 /*
  * We ran out of opcodes, so heapam.c now has a second RmgrId.  These opcodes
  * are associated with RM_HEAP2_ID, but are not logically different from
- * the ones above associated with RM_HEAP_ID.  XLOG_HEAP_OPMASK applies to
- * these, too.
+ * the ones above associated with RM_HEAP_ID.
  *
  * There's no difference between XLOG_HEAP2_PRUNE_ON_ACCESS,
  * XLOG_HEAP2_PRUNE_VACUUM_SCAN and XLOG_HEAP2_PRUNE_VACUUM_CLEANUP records.
-- 
2.51.0

