v18-0006-Clarify-coding-around-fanout.patch

application/x-patch

Filename: v18-0006-Clarify-coding-around-fanout.patch
Type: application/x-patch
Part: 5
Message: Re: [PoC] Improve dead tuple storage for lazy vacuum

Patch

Format: format-patch
Series: patch v18-0006
Subject: Clarify coding around fanout
File+
src/include/lib/radixtree.h 15 11
From f0bac77d49a88c82f4725bed5688d5f1e01dbe49 Mon Sep 17 00:00:00 2001
From: John Naylor <john.naylor@postgresql.org>
Date: Thu, 12 Jan 2023 20:39:19 +0700
Subject: [PATCH v18 06/10] Clarify coding around fanout

Change assignment of node256's fanout to an
assert and add some comments to the fanout
member of the RT_NODE struct.
---
 src/include/lib/radixtree.h | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/src/include/lib/radixtree.h b/src/include/lib/radixtree.h
index 72735c4643..a02e835cd6 100644
--- a/src/include/lib/radixtree.h
+++ b/src/include/lib/radixtree.h
@@ -284,9 +284,15 @@ typedef struct RT_NODE
 	 */
 	uint16		count;
 
-	/* Max number of children. We can use uint8 because we never need to store 256 */
-	/* WIP: if we don't have a variable sized node4, this should instead be in the base
-	types as needed, since saving every byte is crucial for the smallest node kind */
+	/*
+	 * Max capacity for the current size class. Storing this in the
+	 * node enables multiple size classes per node kind.
+	 * Technically, kinds with a single size class don't need this, so we could
+	 * keep this in the individual base types, but the code is simpler this way.
+	 * Note: node256 is unique in that it cannot possibly have more than a
+	 * single size class, so for that kind we store zero, and uint8 is
+	 * sufficient for other kinds.
+	 */
 	uint8		fanout;
 
 	/*
@@ -923,7 +929,12 @@ RT_INIT_NODE(RT_PTR_LOCAL node, uint8 kind, RT_SIZE_CLASS size_class, bool inner
 		MemSet(node, 0, RT_SIZE_CLASS_INFO[size_class].leaf_size);
 
 	node->kind = kind;
-	node->fanout = RT_SIZE_CLASS_INFO[size_class].fanout;
+
+	if (kind == RT_NODE_KIND_256)
+		/* See comment for the RT_NODE type */
+		Assert(node->fanout == 0);
+	else
+		node->fanout = RT_SIZE_CLASS_INFO[size_class].fanout;
 
 	/* Initialize slot_idxs to invalid values */
 	if (kind == RT_NODE_KIND_125)
@@ -932,13 +943,6 @@ RT_INIT_NODE(RT_PTR_LOCAL node, uint8 kind, RT_SIZE_CLASS size_class, bool inner
 
 		memset(n125->slot_idxs, RT_NODE_125_INVALID_IDX, sizeof(n125->slot_idxs));
 	}
-
-	/*
-	 * Technically it's 256, but we cannot store that in a uint8,
-	 * and this is the max size class to it will never grow.
-	 */
-	if (kind == RT_NODE_KIND_256)
-		node->fanout = 0;
 }
 
 /*
-- 
2.39.0