v2699-0003-Force-all-callers-to-encode-no-matter-how-smal.patch.txt
text/plain
Filename: v2699-0003-Force-all-callers-to-encode-no-matter-how-smal.patch.txt
Type: text/plain
Part: 2
From 82c1f639aaa64cc943af3b53294a63d5d8f7a9b9 Mon Sep 17 00:00:00 2001
From: John Naylor <john.naylor@postgresql.org>
Date: Sat, 11 Feb 2023 11:51:32 +0700
Subject: [PATCH v2699 3/3] Force all callers to encode, no matter how small
the expected offset
---
src/backend/access/common/tidstore.c | 36 +++++-----------------------
1 file changed, 6 insertions(+), 30 deletions(-)
diff --git a/src/backend/access/common/tidstore.c b/src/backend/access/common/tidstore.c
index 3d384cf645..ff8e66936e 100644
--- a/src/backend/access/common/tidstore.c
+++ b/src/backend/access/common/tidstore.c
@@ -99,7 +99,6 @@ typedef struct TidStoreControl
size_t max_bytes; /* the maximum bytes a TidStore can use */
int max_offset; /* the maximum offset number */
int offset_nbits; /* the number of bits required for max_offset */
- bool encode_tids; /* do we use tid encoding? */
int offset_key_nbits; /* the number of bits of a offset number
* used for the key */
@@ -224,21 +223,15 @@ tidstore_create(size_t max_bytes, int max_offset, dsa_area *area)
ts->control->max_offset = max_offset;
ts->control->offset_nbits = pg_ceil_log2_32(max_offset);
+ if (ts->control->offset_nbits < TIDSTORE_VALUE_NBITS)
+ ts->control->offset_nbits = TIDSTORE_VALUE_NBITS;
+
/*
* We use tid encoding if the number of bits for the offset number doesn't
* fix in a value, uint64.
*/
- if (ts->control->offset_nbits > TIDSTORE_VALUE_NBITS)
- {
- ts->control->encode_tids = true;
- ts->control->offset_key_nbits =
- ts->control->offset_nbits - TIDSTORE_VALUE_NBITS;
- }
- else
- {
- ts->control->encode_tids = false;
- ts->control->offset_key_nbits = 0;
- }
+ ts->control->offset_key_nbits =
+ ts->control->offset_nbits - TIDSTORE_VALUE_NBITS;
return ts;
}
@@ -643,12 +636,6 @@ tidstore_iter_extract_tids(TidStoreIter *iter, uint64 key, uint64 val)
uint64 tid_i;
OffsetNumber off;
- if (i > iter->ts->control->max_offset)
- {
- Assert(!iter->ts->control->encode_tids);
- break;
- }
-
if ((val & (UINT64CONST(1) << i)) == 0)
continue;
@@ -668,10 +655,7 @@ tidstore_iter_extract_tids(TidStoreIter *iter, uint64 key, uint64 val)
static inline BlockNumber
key_get_blkno(TidStore *ts, uint64 key)
{
- if (ts->control->encode_tids)
- return (BlockNumber) (key >> ts->control->offset_key_nbits);
-
- return (BlockNumber) key;
+ return (BlockNumber) (key >> ts->control->offset_key_nbits);
}
/* Encode a tid to key and offset */
@@ -691,14 +675,6 @@ encode_key_off(TidStore *ts, BlockNumber block, uint32 offset, uint32 *off)
uint64 key;
uint64 tid_i;
- if (!ts->control->encode_tids)
- {
- *off = offset;
-
- /* Use the block number as the key */
- return (int64) block;
- }
-
tid_i = offset | ((uint64) block << ts->control->offset_nbits);
*off = tid_i & ((UINT64CONST(1) << TIDSTORE_VALUE_NBITS) - 1);
--
2.39.1