v18-0008-Turn-branch-into-Assert-in-RT_NODE_UPDATE_INNER.patch

application/x-patch

Filename: v18-0008-Turn-branch-into-Assert-in-RT_NODE_UPDATE_INNER.patch
Type: application/x-patch
Part: 7
Message: Re: [PoC] Improve dead tuple storage for lazy vacuum

Patch

Format: format-patch
Series: patch v18-0008
Subject: Turn branch into Assert in RT_NODE_UPDATE_INNER
File+
src/include/lib/radixtree.h 2 7
src/include/lib/radixtree_search_impl.h 23 18
From 009c01a67817389fc5972d848334c1da00e8864c Mon Sep 17 00:00:00 2001
From: John Naylor <john.naylor@postgresql.org>
Date: Sun, 15 Jan 2023 14:31:42 +0700
Subject: [PATCH v18 08/10] Turn branch into Assert in RT_NODE_UPDATE_INNER

---
 src/include/lib/radixtree.h             |  9 ++----
 src/include/lib/radixtree_search_impl.h | 41 ++++++++++++++-----------
 2 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/src/include/lib/radixtree.h b/src/include/lib/radixtree.h
index e053a2e56e..9f8bed09f7 100644
--- a/src/include/lib/radixtree.h
+++ b/src/include/lib/radixtree.h
@@ -1129,7 +1129,7 @@ RT_FREE_NODE(RT_RADIX_TREE *tree, RT_PTR_ALLOC allocnode)
 #endif
 }
 
-static inline bool
+static inline void
 RT_NODE_UPDATE_INNER(RT_PTR_LOCAL node, uint64 key, RT_PTR_ALLOC new_child)
 {
 #define RT_ACTION_UPDATE
@@ -1160,12 +1160,7 @@ RT_REPLACE_NODE(RT_RADIX_TREE *tree, RT_PTR_LOCAL parent, RT_PTR_ALLOC old_child
 		tree->ctl->root = new_child;
 	}
 	else
-	{
-		bool replaced PG_USED_FOR_ASSERTS_ONLY;
-
-		replaced = RT_NODE_UPDATE_INNER(parent, key, new_child);
-		Assert(replaced);
-	}
+		RT_NODE_UPDATE_INNER(parent, key, new_child);
 
 	RT_FREE_NODE(tree, old_child);
 }
diff --git a/src/include/lib/radixtree_search_impl.h b/src/include/lib/radixtree_search_impl.h
index 3e97c31c2c..31e4978e4f 100644
--- a/src/include/lib/radixtree_search_impl.h
+++ b/src/include/lib/radixtree_search_impl.h
@@ -32,18 +32,19 @@
 				RT_NODE4_TYPE *n4 = (RT_NODE4_TYPE *) node;
 				int			idx = RT_NODE_4_SEARCH_EQ((RT_NODE_BASE_4 *) n4, chunk);
 
+#ifdef RT_ACTION_UPDATE
+				Assert(idx >= 0);
+				n4->children[idx] = new_child;
+#else
 				if (idx < 0)
 					return false;
 
 #ifdef RT_NODE_LEVEL_LEAF
 				value = n4->values[idx];
-#else
-#ifdef RT_ACTION_UPDATE
-				n4->children[idx] = new_child;
 #else
 				child = n4->children[idx];
 #endif
-#endif
+#endif							/* RT_ACTION_UPDATE */
 				break;
 			}
 		case RT_NODE_KIND_32:
@@ -51,18 +52,19 @@
 				RT_NODE32_TYPE *n32 = (RT_NODE32_TYPE *) node;
 				int			idx = RT_NODE_32_SEARCH_EQ((RT_NODE_BASE_32 *) n32, chunk);
 
+#ifdef RT_ACTION_UPDATE
+				Assert(idx >= 0);
+				n32->children[idx] = new_child;
+#else
 				if (idx < 0)
 					return false;
 
 #ifdef RT_NODE_LEVEL_LEAF
 				value = n32->values[idx];
-#else
-#ifdef RT_ACTION_UPDATE
-				n32->children[idx] = new_child;
 #else
 				child = n32->children[idx];
 #endif
-#endif
+#endif							/* RT_ACTION_UPDATE */
 				break;
 			}
 		case RT_NODE_KIND_125:
@@ -70,24 +72,28 @@
 				RT_NODE125_TYPE *n125 = (RT_NODE125_TYPE *) node;
 				int			slotpos = n125->base.slot_idxs[chunk];
 
+#ifdef RT_ACTION_UPDATE
+				Assert(slotpos != RT_NODE_125_INVALID_IDX);
+				n125->children[slotpos] = new_child;
+#else
 				if (slotpos == RT_NODE_125_INVALID_IDX)
 					return false;
 
 #ifdef RT_NODE_LEVEL_LEAF
 				value = RT_NODE_LEAF_125_GET_VALUE(n125, chunk);
-#else
-#ifdef RT_ACTION_UPDATE
-				n125->children[slotpos] = new_child;
 #else
 				child = RT_NODE_INNER_125_GET_CHILD(n125, chunk);
 #endif
-#endif
+#endif							/* RT_ACTION_UPDATE */
 				break;
 			}
 		case RT_NODE_KIND_256:
 			{
 				RT_NODE256_TYPE *n256 = (RT_NODE256_TYPE *) node;
 
+#ifdef RT_ACTION_UPDATE
+				RT_NODE_INNER_256_SET(n256, chunk, new_child);
+#else
 #ifdef RT_NODE_LEVEL_LEAF
 				if (!RT_NODE_LEAF_256_IS_CHUNK_USED(n256, chunk))
 #else
@@ -97,28 +103,27 @@
 
 #ifdef RT_NODE_LEVEL_LEAF
 				value = RT_NODE_LEAF_256_GET_VALUE(n256, chunk);
-#else
-#ifdef RT_ACTION_UPDATE
-				RT_NODE_INNER_256_SET(n256, chunk, new_child);
 #else
 				child = RT_NODE_INNER_256_GET_CHILD(n256, chunk);
 #endif
-#endif
+#endif							/* RT_ACTION_UPDATE */
 				break;
 			}
 	}
 
-#ifndef RT_ACTION_UPDATE
+#ifdef RT_ACTION_UPDATE
+	return;
+#else
 #ifdef RT_NODE_LEVEL_LEAF
 	Assert(value_p != NULL);
 	*value_p = value;
 #else
 	Assert(child_p != NULL);
 	*child_p = child;
-#endif
 #endif
 
 	return true;
+#endif							/* RT_ACTION_UPDATE */
 
 #undef RT_NODE4_TYPE
 #undef RT_NODE32_TYPE
-- 
2.39.0