From e056133360436e115a434a8a21685a99602a5b5d Mon Sep 17 00:00:00 2001 From: Masahiko Sawada Date: Wed, 8 Feb 2023 15:53:14 +0900 Subject: [PATCH] Add bench_tidstore_load() --- .../bench_radix_tree--1.0.sql | 10 ++++ contrib/bench_radix_tree/bench_radix_tree.c | 46 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/contrib/bench_radix_tree/bench_radix_tree--1.0.sql b/contrib/bench_radix_tree/bench_radix_tree--1.0.sql index 95eedbbe10..fbf51c1086 100644 --- a/contrib/bench_radix_tree/bench_radix_tree--1.0.sql +++ b/contrib/bench_radix_tree/bench_radix_tree--1.0.sql @@ -75,3 +75,13 @@ OUT rt_sparseload_ms int8 returns record as 'MODULE_PATHNAME' LANGUAGE C STRICT VOLATILE PARALLEL UNSAFE; + +create function bench_tidstore_load( +minblk int4, +maxblk int4, +OUT mem_allocated int8, +OUT load_ms int8 +) +returns record +as 'MODULE_PATHNAME' +LANGUAGE C STRICT VOLATILE PARALLEL UNSAFE; diff --git a/contrib/bench_radix_tree/bench_radix_tree.c b/contrib/bench_radix_tree/bench_radix_tree.c index 7d1e2eee57..3c2caa3b90 100644 --- a/contrib/bench_radix_tree/bench_radix_tree.c +++ b/contrib/bench_radix_tree/bench_radix_tree.c @@ -9,6 +9,7 @@ */ #include "postgres.h" +#include "access/tidstore.h" #include "common/pg_prng.h" #include "fmgr.h" #include "funcapi.h" @@ -54,6 +55,7 @@ PG_FUNCTION_INFO_V1(bench_load_random_int); PG_FUNCTION_INFO_V1(bench_fixed_height_search); PG_FUNCTION_INFO_V1(bench_search_random_nodes); PG_FUNCTION_INFO_V1(bench_node128_load); +PG_FUNCTION_INFO_V1(bench_tidstore_load); static uint64 tid_to_key_off(ItemPointer tid, uint32 *off) @@ -168,6 +170,50 @@ vac_cmp_itemptr(const void *left, const void *right) } #endif +Datum +bench_tidstore_load(PG_FUNCTION_ARGS) +{ + BlockNumber minblk = PG_GETARG_INT32(0); + BlockNumber maxblk = PG_GETARG_INT32(1); + TidStore *ts; + OffsetNumber *offs; + TimestampTz start_time, + end_time; + long secs; + int usecs; + int64 load_ms; + TupleDesc tupdesc; + Datum values[2]; + bool nulls[2] = {false}; + + /* Build a tuple descriptor for our result type */ + if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) + elog(ERROR, "return type must be a row type"); + + offs = palloc(sizeof(OffsetNumber) * TIDS_PER_BLOCK_FOR_LOAD); + for (int i = 0; i < TIDS_PER_BLOCK_FOR_LOAD; i++) + offs[i] = i + 1; /* FirstOffsetNumber is 1 */ + + ts = tidstore_create(1 * 1024L * 1024L * 1024L, MaxHeapTuplesPerPage, NULL); + + elog(NOTICE, "sleeping for 2 seconds..."); + pg_usleep(2 * 1000000L); + + /* load tids */ + start_time = GetCurrentTimestamp(); + for (BlockNumber blkno = minblk; blkno < maxblk; blkno++) + tidstore_add_tids(ts, blkno, offs, TIDS_PER_BLOCK_FOR_LOAD); + end_time = GetCurrentTimestamp(); + TimestampDifference(start_time, end_time, &secs, &usecs); + load_ms = secs * 1000 + usecs / 1000; + + values[0] = Int64GetDatum(tidstore_memory_usage(ts)); + values[1] = Int64GetDatum(load_ms); + + tidstore_destroy(ts); + PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls))); +} + static Datum bench_search(FunctionCallInfo fcinfo, bool shuffle) { -- 2.31.1