postgresql/contrib/pgstattuple
Teodor Sigaev 857f9c36cd Skip full index scan during cleanup of B-tree indexes when possible
Vacuum of index consists from two stages: multiple (zero of more) ambulkdelete
calls and one amvacuumcleanup call. When workload on particular table
is append-only, then autovacuum isn't intended to touch this table. However,
user may run vacuum manually in order to fill visibility map and get benefits
of index-only scans. Then ambulkdelete wouldn't be called for indexes
of such table (because no heap tuples were deleted), only amvacuumcleanup would
be called In this case, amvacuumcleanup would perform full index scan for
two objectives: put recyclable pages into free space map and update index
statistics.

This patch allows btvacuumclanup to skip full index scan when two conditions
are satisfied: no pages are going to be put into free space map and index
statistics isn't stalled. In order to check first condition, we store
oldest btpo_xact in the meta-page. When it's precedes RecentGlobalXmin, then
there are some recyclable pages. In order to check second condition we store
number of heap tuples observed during previous full index scan by cleanup.
If fraction of newly inserted tuples is less than
vacuum_cleanup_index_scale_factor, then statistics isn't considered to be
stalled. vacuum_cleanup_index_scale_factor can be defined as both reloption and GUC (default).

This patch bumps B-tree meta-page version. Upgrade of meta-page is performed
"on the fly": during VACUUM meta-page is rewritten with new version. No special
handling in pg_upgrade is required.

Author: Masahiko Sawada, Alexander Korotkov
Review by: Peter Geoghegan, Kyotaro Horiguchi, Alexander Korotkov, Yura Sokolov
Discussion: https://www.postgresql.org/message-id/flat/CAD21AoAX+d2oD_nrd9O2YkpzHaFr=uQeGr9s1rKC3O4ENc568g@mail.gmail.com
2018-04-04 19:29:00 +03:00
..
expected Skip full index scan during cleanup of B-tree indexes when possible 2018-04-04 19:29:00 +03:00
sql pgstattuple: Fix typo partitiond -> partitioned 2017-03-09 20:06:11 -05:00
.gitignore Add a regression test for pgstattuple. 2011-08-25 00:06:16 -04:00
Makefile Remove superuser checks in pgstattuple 2016-09-29 22:13:38 -04:00
pgstatapprox.c Sync up our various ways of estimating pg_class.reltuples. 2018-03-22 15:47:41 -04:00
pgstatindex.c Remove unnecessary parentheses in return statements 2017-09-05 14:52:55 -04:00
pgstattuple--1.0--1.1.sql Add pgstatginindex() function to get the size of the GIN pending list. 2012-12-05 09:58:03 +02:00
pgstattuple--1.1--1.2.sql Fix pgstattuple functions to use regclass-type as the argument. 2013-07-19 03:50:20 +09:00
pgstattuple--1.2--1.3.sql Add pgstattuple_approx() to the pgstattuple extension. 2015-05-13 07:35:06 +02:00
pgstattuple--1.3--1.4.sql Update pgstattuple extension for parallel query. 2016-06-10 10:42:03 -04:00
pgstattuple--1.4--1.5.sql Fix pgstattuple's handling of unused hash pages. 2017-04-12 11:53:00 -04:00
pgstattuple--1.4.sql Minor fixes in contrib installation scripts. 2016-06-14 10:47:06 -04:00
pgstattuple--unpackaged--1.0.sql Fix typos in some error messages thrown by extension scripts when fed to psql. 2014-08-25 18:30:37 +02:00
pgstattuple.c Fix more format truncation issues 2018-03-15 11:41:42 -04:00
pgstattuple.control Remove superuser checks in pgstattuple 2016-09-29 22:13:38 -04:00