From a26481cb0bcd0dbe223e0fc8ec1ea0c4d7a77619 Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <lic@highgo.com>
Date: Wed, 27 Aug 2025 16:48:54 +0800
Subject: [PATCH v2] Mark ItemPointer parameters as const in tuple/table lock
 functions

The functions LockTuple, ConditionalLockTuple, UnlockTuple, and
XactLockTableWait take an ItemPointer parameter named 'tid'. Since
these functions do not modify the tuple identifier, the parameter
should be declared as const to better convey intent and allow the
compiler to enforce immutability.

Changes:
- Add 'const' qualifier to ItemPointer tid parameter in the above functions.
- Update function declarations and definitions accordingly.

This improves code correctness and readability without affecting behavior.

Author: Chao Li <lic@highgo.com>
Discussion: https://postgr.es/m/CAEoWx2m9e4rECHBwpRE4%2BGCH%2BpbYZXLh2f4rB1Du5hDfKug%2BOg%40mail.gmail.com
---
 src/backend/storage/lmgr/lmgr.c | 8 ++++----
 src/include/storage/lmgr.h      | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/backend/storage/lmgr/lmgr.c b/src/backend/storage/lmgr/lmgr.c
index 3f6bf70bd3c..81f9cdb0fc0 100644
--- a/src/backend/storage/lmgr/lmgr.c
+++ b/src/backend/storage/lmgr/lmgr.c
@@ -559,7 +559,7 @@ UnlockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode)
  * tuple.  See heap_lock_tuple before using this!
  */
 void
-LockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode)
+LockTuple(Relation relation, const ItemPointerData *tid, LOCKMODE lockmode)
 {
 	LOCKTAG		tag;
 
@@ -579,7 +579,7 @@ LockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode)
  * Returns true iff the lock was acquired.
  */
 bool
-ConditionalLockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode,
+ConditionalLockTuple(Relation relation, const ItemPointerData *tid, LOCKMODE lockmode,
 					 bool logLockFailure)
 {
 	LOCKTAG		tag;
@@ -598,7 +598,7 @@ ConditionalLockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode,
  *		UnlockTuple
  */
 void
-UnlockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode)
+UnlockTuple(Relation relation, const ItemPointerData *tid, LOCKMODE lockmode)
 {
 	LOCKTAG		tag;
 
@@ -660,7 +660,7 @@ XactLockTableDelete(TransactionId xid)
  * and if so wait for its parent.
  */
 void
-XactLockTableWait(TransactionId xid, Relation rel, ItemPointer ctid,
+XactLockTableWait(TransactionId xid, Relation rel, const ItemPointerData *ctid,
 				  XLTW_Oper oper)
 {
 	LOCKTAG		tag;
diff --git a/src/include/storage/lmgr.h b/src/include/storage/lmgr.h
index 58eee4e0d54..b7abd18397d 100644
--- a/src/include/storage/lmgr.h
+++ b/src/include/storage/lmgr.h
@@ -71,16 +71,16 @@ extern bool ConditionalLockPage(Relation relation, BlockNumber blkno, LOCKMODE l
 extern void UnlockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode);
 
 /* Lock a tuple (see heap_lock_tuple before assuming you understand this) */
-extern void LockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode);
-extern bool ConditionalLockTuple(Relation relation, ItemPointer tid,
+extern void LockTuple(Relation relation, const ItemPointerData *tid, LOCKMODE lockmode);
+extern bool ConditionalLockTuple(Relation relation, const ItemPointerData *tid,
 								 LOCKMODE lockmode, bool logLockFailure);
-extern void UnlockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode);
+extern void UnlockTuple(Relation relation, const ItemPointerData *tid, LOCKMODE lockmode);
 
 /* Lock an XID (used to wait for a transaction to finish) */
 extern void XactLockTableInsert(TransactionId xid);
 extern void XactLockTableDelete(TransactionId xid);
 extern void XactLockTableWait(TransactionId xid, Relation rel,
-							  ItemPointer ctid, XLTW_Oper oper);
+							  const ItemPointerData *ctid, XLTW_Oper oper);
 extern bool ConditionalXactLockTableWait(TransactionId xid,
 										 bool logLockFailure);
 
-- 
2.39.5 (Apple Git-154)

