I noticed that pgrowlocks will use different names for shared locks
depending on whether the locks are intermediated by a multixact or not.
Particularly, if a single transaction has locked a row, it may return "For
Key Share" or "For Share" in the "modes" array, while if multiple
transactions have locked a row, it may return "Key Share" or "Share". The
documentation of the pgrowlocks function only lists "Key Share" and "Share"
as possible modes. (The four exclusive lock modes use the correct names in
both cases)

The attached patch (against the master branch) fixes this discrepancy, by
using "Key Share" and "Share" in the single transaction case, since that
matches the documentation. I also updated the test's expected output so it
passes again.

Thanks,
--David Cook
From dd7c5dcb0bd8457bd04f5ef762466f2b77209ad4 Mon Sep 17 00:00:00 2001
From: David Cook <divergentd...@gmail.com>
Date: Fri, 30 Jun 2023 09:22:20 -0500
Subject: [PATCH] pgrowlocks: Make mode names consistent with docs

---
 contrib/pgrowlocks/expected/pgrowlocks.out | 28 +++++++++++-----------
 contrib/pgrowlocks/pgrowlocks.c            |  4 ++--
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/contrib/pgrowlocks/expected/pgrowlocks.out b/contrib/pgrowlocks/expected/pgrowlocks.out
index 725467266a..625246711f 100644
--- a/contrib/pgrowlocks/expected/pgrowlocks.out
+++ b/contrib/pgrowlocks/expected/pgrowlocks.out
@@ -10,10 +10,10 @@ a|b
 (2 rows)
 
 step s2_rowlocks: SELECT locked_row, multi, modes FROM pgrowlocks('multixact_conflict');
-locked_row|multi|modes            
-----------+-----+-----------------
-(0,1)     |f    |{"For Key Share"}
-(0,2)     |f    |{"For Key Share"}
+locked_row|multi|modes        
+----------+-----+-------------
+(0,1)     |f    |{"Key Share"}
+(0,2)     |f    |{"Key Share"}
 (2 rows)
 
 step s1_commit: COMMIT;
@@ -28,10 +28,10 @@ a|b
 (2 rows)
 
 step s2_rowlocks: SELECT locked_row, multi, modes FROM pgrowlocks('multixact_conflict');
-locked_row|multi|modes        
-----------+-----+-------------
-(0,1)     |f    |{"For Share"}
-(0,2)     |f    |{"For Share"}
+locked_row|multi|modes  
+----------+-----+-------
+(0,1)     |f    |{Share}
+(0,2)     |f    |{Share}
 (2 rows)
 
 step s1_commit: COMMIT;
@@ -111,10 +111,10 @@ a|b
 (2 rows)
 
 step s2_rowlocks: SELECT locked_row, multi, modes FROM pgrowlocks('multixact_conflict');
-locked_row|multi|modes            
-----------+-----+-----------------
-(0,1)     |f    |{"For Key Share"}
-(0,2)     |f    |{"For Key Share"}
+locked_row|multi|modes        
+----------+-----+-------------
+(0,1)     |f    |{"Key Share"}
+(0,2)     |f    |{"Key Share"}
 (2 rows)
 
 step s1_commit: COMMIT;
@@ -208,7 +208,7 @@ step s2_rowlocks: SELECT locked_row, multi, modes FROM pgrowlocks('multixact_con
 locked_row|multi|modes               
 ----------+-----+--------------------
 (0,1)     |t    |{"Key Share",Update}
-(0,2)     |f    |{"For Key Share"}   
+(0,2)     |f    |{"Key Share"}       
 (2 rows)
 
 step s1_commit: COMMIT;
@@ -226,7 +226,7 @@ step s1_updateb: UPDATE multixact_conflict SET b = 11 WHERE b = 4;
 step s2_rowlocks: SELECT locked_row, multi, modes FROM pgrowlocks('multixact_conflict');
 locked_row|multi|modes                        
 ----------+-----+-----------------------------
-(0,1)     |f    |{"For Key Share"}            
+(0,1)     |f    |{"Key Share"}                
 (0,2)     |t    |{"Key Share","No Key Update"}
 (2 rows)
 
diff --git a/contrib/pgrowlocks/pgrowlocks.c b/contrib/pgrowlocks/pgrowlocks.c
index c543277b7c..c2d66dda35 100644
--- a/contrib/pgrowlocks/pgrowlocks.c
+++ b/contrib/pgrowlocks/pgrowlocks.c
@@ -230,9 +230,9 @@ pgrowlocks(PG_FUNCTION_ARGS)
 				if (infomask & HEAP_XMAX_LOCK_ONLY)
 				{
 					if (HEAP_XMAX_IS_SHR_LOCKED(infomask))
-						snprintf(values[Atnum_modes], NCHARS, "{For Share}");
+						snprintf(values[Atnum_modes], NCHARS, "{Share}");
 					else if (HEAP_XMAX_IS_KEYSHR_LOCKED(infomask))
-						snprintf(values[Atnum_modes], NCHARS, "{For Key Share}");
+						snprintf(values[Atnum_modes], NCHARS, "{Key Share}");
 					else if (HEAP_XMAX_IS_EXCL_LOCKED(infomask))
 					{
 						if (tuple->t_data->t_infomask2 & HEAP_KEYS_UPDATED)
-- 
2.30.2

Reply via email to