v2699-0002-Do-less-work-when-encoding-key-value.patch.txt
text/plain
Filename: v2699-0002-Do-less-work-when-encoding-key-value.patch.txt
Type: text/plain
Part: 0
From 6bdd33fa4f55757b54d16ce00dc60a21b929606e Mon Sep 17 00:00:00 2001
From: John Naylor <john.naylor@postgresql.org>
Date: Sat, 11 Feb 2023 10:45:21 +0700
Subject: [PATCH v2699 2/3] Do less work when encoding key/value
---
src/backend/access/common/tidstore.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/src/backend/access/common/tidstore.c b/src/backend/access/common/tidstore.c
index 5d24680737..3d384cf645 100644
--- a/src/backend/access/common/tidstore.c
+++ b/src/backend/access/common/tidstore.c
@@ -159,6 +159,7 @@ typedef struct TidStoreIter
static void tidstore_iter_extract_tids(TidStoreIter *iter, uint64 key, uint64 val);
static inline BlockNumber key_get_blkno(TidStore *ts, uint64 key);
+static inline uint64 encode_key_off(TidStore *ts, BlockNumber block, uint32 offset, uint32 *off);
static inline uint64 tid_to_key_off(TidStore *ts, ItemPointer tid, uint32 *off);
/*
@@ -367,7 +368,6 @@ void
tidstore_add_tids(TidStore *ts, BlockNumber blkno, OffsetNumber *offsets,
int num_offsets)
{
- ItemPointerData tid;
uint64 *values;
uint64 key;
uint64 prev_key;
@@ -381,16 +381,12 @@ tidstore_add_tids(TidStore *ts, BlockNumber blkno, OffsetNumber *offsets,
values = palloc(sizeof(uint64) * nkeys);
key = prev_key = key_base;
- ItemPointerSetBlockNumber(&tid, blkno);
-
for (int i = 0; i < num_offsets; i++)
{
uint32 off;
- ItemPointerSetOffsetNumber(&tid, offsets[i]);
-
/* encode the tid to key and val */
- key = tid_to_key_off(ts, &tid, &off);
+ key = encode_key_off(ts, blkno, offsets[i], &off);
/* make sure we scanned the line pointer array in order */
Assert(key >= prev_key);
@@ -681,20 +677,29 @@ key_get_blkno(TidStore *ts, uint64 key)
/* Encode a tid to key and offset */
static inline uint64
tid_to_key_off(TidStore *ts, ItemPointer tid, uint32 *off)
+{
+ uint32 offset = ItemPointerGetOffsetNumber(tid);
+ BlockNumber block = ItemPointerGetBlockNumber(tid);
+
+ return encode_key_off(ts, block, offset, off);
+}
+
+/* encode a block and offset to a key and partial offset */
+static inline uint64
+encode_key_off(TidStore *ts, BlockNumber block, uint32 offset, uint32 *off)
{
uint64 key;
uint64 tid_i;
if (!ts->control->encode_tids)
{
- *off = ItemPointerGetOffsetNumber(tid);
+ *off = offset;
/* Use the block number as the key */
- return (int64) ItemPointerGetBlockNumber(tid);
+ return (int64) block;
}
- tid_i = ItemPointerGetOffsetNumber(tid);
- tid_i |= (uint64) ItemPointerGetBlockNumber(tid) << ts->control->offset_nbits;
+ tid_i = offset | ((uint64) block << ts->control->offset_nbits);
*off = tid_i & ((UINT64CONST(1) << TIDSTORE_VALUE_NBITS) - 1);
key = tid_i >> TIDSTORE_VALUE_NBITS;
--
2.39.1