From 9079a4ec75a29ec9b2e725a4b18b6fb3a0a29d94 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 v1] 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>
---
 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..297472aed08 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 ItemPointer 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 ItemPointer 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 ItemPointer 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 ItemPointer ctid,
 				  XLTW_Oper oper)
 {
 	LOCKTAG		tag;
diff --git a/src/include/storage/lmgr.h b/src/include/storage/lmgr.h
index 58eee4e0d54..ed9a9f32488 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 ItemPointer tid, LOCKMODE lockmode);
+extern bool ConditionalLockTuple(Relation relation, const ItemPointer tid,
 								 LOCKMODE lockmode, bool logLockFailure);
-extern void UnlockTuple(Relation relation, ItemPointer tid, LOCKMODE lockmode);
+extern void UnlockTuple(Relation relation, const ItemPointer 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 ItemPointer ctid, XLTW_Oper oper);
 extern bool ConditionalXactLockTableWait(TransactionId xid,
 										 bool logLockFailure);
 
-- 
2.39.5 (Apple Git-154)

