fix_bench_radix_tree.patch

application/x-patch

Filename: fix_bench_radix_tree.patch
Type: application/x-patch
Part: 0
Message: Re: [PoC] Improve dead tuple storage for lazy vacuum

Patch

Format: unified
File+
contrib/bench_radix_tree/bench_radix_tree.c 23 14
diff --git a/contrib/bench_radix_tree/bench_radix_tree.c b/contrib/bench_radix_tree/bench_radix_tree.c
index 0778da2d7b..d4c8040357 100644
--- a/contrib/bench_radix_tree/bench_radix_tree.c
+++ b/contrib/bench_radix_tree/bench_radix_tree.c
@@ -27,20 +27,17 @@ PG_FUNCTION_INFO_V1(bench_shuffle_search);
 PG_FUNCTION_INFO_V1(bench_load_random_int);
 PG_FUNCTION_INFO_V1(bench_fixed_height_search);
 
-static radix_tree *rt = NULL;
-static ItemPointer itemptrs = NULL;
-
 static uint64
 tid_to_key_off(ItemPointer tid, uint32 *off)
 {
-	uint32 upper;
+	uint64 upper;
 	uint32 shift = pg_ceil_log2_32(MaxHeapTuplesPerPage);
 	int64 tid_i;
 
 	Assert(ItemPointerGetOffsetNumber(tid) < MaxHeapTuplesPerPage);
 
 	tid_i = ItemPointerGetOffsetNumber(tid);
-	tid_i |= ItemPointerGetBlockNumber(tid) << shift;
+	tid_i |= (uint64) ItemPointerGetBlockNumber(tid) << shift;
 
 	/* log(sizeof(uint64) * BITS_PER_BYTE, 2) = log(64, 2) = 6 */
 	*off = tid_i & ((1 << 6) - 1);
@@ -70,10 +67,10 @@ shuffle_itemptrs(ItemPointer itemptr, uint64 nitems)
 	for (int i = 0; i < nitems - 1; i++)
 	{
 		int j = shuffle_randrange(&state, i, nitems - 1);
-		ItemPointerData t = itemptrs[j];
+		ItemPointerData t = itemptr[j];
 
-		itemptrs[j] = itemptrs[i];
-		itemptrs[i] = t;
+		itemptr[j] = itemptr[i];
+		itemptr[i] = t;
 	}
 }
 
@@ -138,6 +135,8 @@ bench_search(FunctionCallInfo fcinfo, bool shuffle)
 {
 	BlockNumber minblk = PG_GETARG_INT32(0);
 	BlockNumber maxblk = PG_GETARG_INT32(1);
+	ItemPointer itemptrs = NULL;
+	radix_tree *rt = NULL;
 	uint64	ntids;
 	uint64	key;
 	uint64	last_key = PG_UINT64_MAX;;
@@ -185,6 +184,8 @@ bench_search(FunctionCallInfo fcinfo, bool shuffle)
 	TimestampDifference(start_time, end_time, &secs, &usecs);
 	rt_load_ms = secs * 1000 + usecs / 1000;
 
+	rt_stats(rt);
+
 	/* measure the load time of the array */
 	itemptrs = MemoryContextAllocHuge(CurrentMemoryContext,
 									  sizeof(ItemPointerData) * ntids);
@@ -210,12 +211,14 @@ bench_search(FunctionCallInfo fcinfo, bool shuffle)
 		ItemPointer tid = &(tids[i]);
 		uint64	key, val;
 		uint32	off;
+		volatile bool ret; /* prevent calling rt_search from being optimized out */
 
 		CHECK_FOR_INTERRUPTS();
 
 		key = tid_to_key_off(tid, &off);
 
-		rt_search(rt, key, &val);
+		ret = rt_search(rt, key, &val);
+		(void) ret;
 	}
 	end_time = GetCurrentTimestamp();
 	TimestampDifference(start_time, end_time, &secs, &usecs);
@@ -226,12 +229,16 @@ bench_search(FunctionCallInfo fcinfo, bool shuffle)
 	for (int i = 0; i < ntids; i++)
 	{
 		ItemPointer tid = &(tids[i]);
+		volatile bool ret; /* prevent calling bsearch from being optimized out */
 
-		bsearch((void *) tid,
-				(void *) itemptrs,
-				ntids,
-				sizeof(ItemPointerData),
-				vac_cmp_itemptr);
+		CHECK_FOR_INTERRUPTS();
+
+		ret = bsearch((void *) tid,
+					  (void *) itemptrs,
+					  ntids,
+					  sizeof(ItemPointerData),
+					  vac_cmp_itemptr);
+		(void) ret;
 	}
 	end_time = GetCurrentTimestamp();
 	TimestampDifference(start_time, end_time, &secs, &usecs);
@@ -294,6 +301,8 @@ bench_load_random_int(PG_FUNCTION_ARGS)
 	TimestampDifference(start_time, end_time, &secs, &usecs);
 	load_time_ms = secs * 1000 + usecs / 1000;
 
+	rt_stats(rt);
+
 	MemSet(nulls, false, sizeof(nulls));
 	values[0] = Int64GetDatum(rt_memory_usage(rt));
 	values[1] = Int64GetDatum(load_time_ms);