https://speakerdeck.com/macdice/improving-the-slru-subsystem?slide=29
contact author, get the C function source code.
CREATE FUNCTION test_clog_fetch(x1 pg_catalog.xid,
x2 pg_catalog.xid,
loops pg_catalog.int4)
RETURNS pg_catalog.void STRICT
AS 'slrubench','test_clog_fetch' LANGUAGE C;
#include "postgres.h"
#include "fmgr.h"
#include "access/clog.h"
#include "access/xlogdefs.h"
#include "miscadmin.h"
PG_MODULE_MAGIC;
PG_FUNCTION_INFO_V1(test_clog_fetch);
Datum
test_clog_fetch(PG_FUNCTION_ARGS)
{
TransactionId x1 = PG_GETARG_TRANSACTIONID(0);
TransactionId x2 = PG_GETARG_TRANSACTIONID(1);
int loops = PG_GETARG_INT32(2);
elog(NOTICE, "xid range %u, %u; loop = %d", x1, x2, loops);
for (int i = 0; i < loops; ++i)
{
for (TransactionId xid = x1; xid < x2; ++xid)
{
XLogRecPtr lsn;
TransactionIdGetStatus(xid, &lsn);
}
CHECK_FOR_INTERRUPTS();
}
PG_RETURN_VOID();
}
sql part:
SELECT pg_current_xact_id();
create table test as select * from public.tenk1;
SELECT pg_current_xact_id();
select test_clog_fetch('807'::xid,'809'::xid,1e4::int);
test_clog_fetch
-----------------
(1 row)
Time: 10.003 ms
regression=# select name,blks_zeroed,blks_hit,blks_read,blks_written,blks_exists,flushes,truncates
from pg_stat_slru;
name | blks_zeroed | blks_hit | blks_read | blks_written | blks_exists | flushes | truncates
-----------------+-------------+----------+-----------+--------------+-------------+---------+-----------
CommitTs | 0 | 0 | 0 | 0 | 0 | 7 | 0
MultiXactMember | 1 | 0 | 0 | 1 | 0 | 7 | 0
MultiXactOffset | 1 | 1 | 3 | 4 | 0 | 7 | 0
Notify | 0 | 0 | 0 | 0 | 0 | 0 | 0
Serial | 0 | 0 | 0 | 0 | 0 | 0 | 0
Subtrans | 6 | 0 | 0 | 4 | 0 | 7 | 7
Xact | 2 | 23971 | 3 | 6 | 0 | 7 | 0
other | 0 | 0 | 0 | 0 | 0 | 0 | 0
(8 rows)
I want to understand what does 23971 mean. overall I can understand input output of function TransactionIdGetStatus. but lsn part I am not famiilar with.
between xid 807, xid 809. I created a table, table relpages is 345, reltuples is 10000.