Hi hackers,

While working on a rebase for [1] due to 0cecc908e97, I noticed that
CheckRelationLockedByMe() and CheckRelationOidLockedByMe() are used only in
assertions.

I think it would make sense to declare / define those functions only for
assert enabled build: please find attached a tiny patch doing so.

Thoughts?

[1]: 
https://www.postgresql.org/message-id/flat/ZiYjn0eVc7pxVY45%40ip-10-97-1-34.eu-west-3.compute.internal

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
>From bee765581b6b356a6c9c2e4407243f1622b8e84a Mon Sep 17 00:00:00 2001
From: Bertrand Drouvot <bertranddrouvot...@gmail.com>
Date: Mon, 1 Jul 2024 05:38:30 +0000
Subject: [PATCH v1] Surround CheckRelation[Oid]LockedByMe() with
 USE_ASSERT_CHECKING

As CheckRelationLockedByMe() and CheckRelationOidLockedByMe() are used only in
assertions, declare / define those functions only for assert enabled build.
---
 src/backend/storage/lmgr/lmgr.c | 2 ++
 src/include/storage/lmgr.h      | 2 ++
 2 files changed, 4 insertions(+)
  50.0% src/backend/storage/lmgr/
  50.0% src/include/storage/

diff --git a/src/backend/storage/lmgr/lmgr.c b/src/backend/storage/lmgr/lmgr.c
index 094522acb41..234cab4f7af 100644
--- a/src/backend/storage/lmgr/lmgr.c
+++ b/src/backend/storage/lmgr/lmgr.c
@@ -318,6 +318,7 @@ UnlockRelation(Relation relation, LOCKMODE lockmode)
 	LockRelease(&tag, lockmode, false);
 }
 
+#ifdef USE_ASSERT_CHECKING
 /*
  *		CheckRelationLockedByMe
  *
@@ -352,6 +353,7 @@ CheckRelationOidLockedByMe(Oid relid, LOCKMODE lockmode, bool orstronger)
 
 	return LockHeldByMe(&tag, lockmode, orstronger);
 }
+#endif
 
 /*
  *		LockHasWaitersRelation
diff --git a/src/include/storage/lmgr.h b/src/include/storage/lmgr.h
index ce15125ac3b..3d5f989ae80 100644
--- a/src/include/storage/lmgr.h
+++ b/src/include/storage/lmgr.h
@@ -46,10 +46,12 @@ extern void UnlockRelationOid(Oid relid, LOCKMODE lockmode);
 extern void LockRelation(Relation relation, LOCKMODE lockmode);
 extern bool ConditionalLockRelation(Relation relation, LOCKMODE lockmode);
 extern void UnlockRelation(Relation relation, LOCKMODE lockmode);
+#ifdef USE_ASSERT_CHECKING
 extern bool CheckRelationLockedByMe(Relation relation, LOCKMODE lockmode,
 									bool orstronger);
 extern bool CheckRelationOidLockedByMe(Oid relid, LOCKMODE lockmode,
 									   bool orstronger);
+#endif
 extern bool LockHasWaitersRelation(Relation relation, LOCKMODE lockmode);
 
 extern void LockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode);
-- 
2.34.1

Reply via email to