pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Teodor Sigaev <teodor@sigaev.ru>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Skip full index scan during cleanup of B-tree indexes when possi
Date: Wed, 04 Apr 2018 16:29:53 +0000
Message-ID: <E1f3lIH-0005Cn-GV@gemulon.postgresql.org> (raw)

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....

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/857f9c36cda520030381bd8c2af20adf0ce0e1d4

Modified Files
--------------
contrib/amcheck/verify_nbtree.c               |   8 +-
contrib/pageinspect/Makefile                  |   3 +-
contrib/pageinspect/btreefuncs.c              |   4 +-
contrib/pageinspect/expected/btree.out        |  16 +--
contrib/pageinspect/pageinspect--1.6--1.7.sql |  26 +++++
contrib/pageinspect/pageinspect.control       |   2 +-
contrib/pgstattuple/expected/pgstattuple.out  |  10 +-
doc/src/sgml/config.sgml                      |  25 +++++
doc/src/sgml/pageinspect.sgml                 |  16 +--
doc/src/sgml/ref/create_index.sgml            |  15 +++
src/backend/access/common/reloptions.c        |  13 ++-
src/backend/access/nbtree/nbtinsert.c         |  12 +++
src/backend/access/nbtree/nbtpage.c           | 150 ++++++++++++++++++++++++--
src/backend/access/nbtree/nbtree.c            | 118 ++++++++++++++++++--
src/backend/access/nbtree/nbtxlog.c           |   6 +-
src/backend/utils/init/globals.c              |   2 +
src/backend/utils/misc/guc.c                  |  10 ++
src/include/access/nbtree.h                   |  11 +-
src/include/access/nbtxlog.h                  |   4 +
src/include/miscadmin.h                       |   2 +
src/include/utils/rel.h                       |   2 +
src/test/regress/expected/btree_index.out     |  29 +++++
src/test/regress/sql/btree_index.sql          |  19 ++++
23 files changed, 458 insertions(+), 45 deletions(-)



view thread (18+ messages)  latest in thread

Message-ID: <E1f3lIH-0005Cn-GV@gemulon.postgresql.org>
Permalink:  ../E1f3lIH-0005Cn-GV@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1f3lIH-0005Cn-GV@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: teodor@sigaev.ru
  Subject: Re: pgsql: Skip full index scan during cleanup of B-tree indexes when possi
  In-Reply-To: <E1f3lIH-0005Cn-GV@gemulon.postgresql.org>
  References: <E1f3lIH-0005Cn-GV@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox