Use heap scan routines directly in vac_update_datfrozenxid()

Soumyadeep Chakraborty <soumyadeep2007@gmail.com>

From: Soumyadeep Chakraborty <soumyadeep2007@gmail.com>
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2024-10-06T20:39:42Z
Lists: pgsql-hackers

Attachments

Hi hackers,

Attached is a simple patch to directly use heap scan routines in
vac_update_datfrozenxid(), avoiding the multilayer overhead from the
sysscan infrastructure. The speedup can be noticeable in databases
containing a large number of relations (perhaps due to heavy partition
table usage). This was proposed in [1].

Experiment setup:

* Use -O3 optimized build without asserts, with fsync and autovacuum off,
on my laptop. Other gucs are all at defaults.

* Create tables using pgbench to inflate pg_class's to a decent size.

$ cat << EOF > bench.sql
> select txid_current() AS txid \gset
> CREATE TABLE t:txid(a int);
> EOF

$ pgbench -f ./bench.sql -t 200000 -c 100 -n bench

select pg_size_pretty(pg_relation_size('pg_class'));
 pg_size_pretty
----------------
 3508 MB
(1 row)

* Use instr_time to record the scan time. See attached instr_vac.diff.

* Run vacuum on any of the created empty tables in the database bench:

Results:

* main as of 68dfecbef2:

bench=# vacuum t1624;
NOTICE:  scan took 796.862142 ms
bench=# vacuum t1624;
NOTICE:  scan took 793.730688 ms
bench=# vacuum t1624;
NOTICE:  scan took 793.963655 ms

* patch:

bench=# vacuum t1624;
NOTICE:  scan took 682.283366 ms
bench=# vacuum t1624;
NOTICE:  scan took 670.816975 ms
bench=# vacuum t1624;
NOTICE:  scan took 683.821717 ms

Regards,
Soumyadeep (Broadcom)


[1] https://www.postgresql.org/message-id/20221229030329.fbpiitatmowzza6c%40awork3.anarazel.de