From 6cd17b504ca51178dcb5a7e03d65b5071b9483e6 Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Fri, 13 Dec 2024 16:55:52 -0800 Subject: [PATCH v6 7/8] Add TidStoreNumBlocks API to get the number of blocks in TidStore. Author: Reviewed-by: Discussion: https://postgr.es/m/ Backpatch-through: --- src/backend/access/common/tidstore.c | 12 ++++++++++++ src/include/access/tidstore.h | 1 + 2 files changed, 13 insertions(+) diff --git a/src/backend/access/common/tidstore.c b/src/backend/access/common/tidstore.c index 399adf4af31..c43b3d8ac69 100644 --- a/src/backend/access/common/tidstore.c +++ b/src/backend/access/common/tidstore.c @@ -596,6 +596,18 @@ TidStoreMemoryUsage(TidStore *ts) return local_ts_memory_usage(ts->tree.local); } +/* + * Return the number of entries in TidStore. + */ +BlockNumber +TidStoreNumBlocks(TidStore *ts) +{ + if (TidStoreIsShared(ts)) + return shared_ts_num_keys(ts->tree.shared); + else + return local_ts_num_keys(ts->tree.local); +} + /* * Return the DSA area where the TidStore lives. */ diff --git a/src/include/access/tidstore.h b/src/include/access/tidstore.h index c886cef0f7d..fd739d20da1 100644 --- a/src/include/access/tidstore.h +++ b/src/include/access/tidstore.h @@ -51,6 +51,7 @@ extern int TidStoreGetBlockOffsets(TidStoreIterResult *result, int max_offsets); extern void TidStoreEndIterate(TidStoreIter *iter); extern size_t TidStoreMemoryUsage(TidStore *ts); +extern BlockNumber TidStoreNumBlocks(TidStore *ts); extern dsa_pointer TidStoreGetHandle(TidStore *ts); extern dsa_area *TidStoreGetDSA(TidStore *ts); -- 2.43.5